Friday, June 10, 2022

Laravel / Google Maps -- Get Locations in Bounds

Problem: 

While working on a project using Laravel back-end and JavaScript front-end. I had a situation where I needed to get all the locations for the map with given bounds. First, I tried just doing a bounding box check, which worked but only sometimes. 


Solution:

In this problem, I was not alone. After reading and trying some various approaches, this one by FatMonk on SO did the trick (https://stackoverflow.com/a/35944747). 

// Google Maps API map.getBounds()

$north = $lat1_ne || 90;
$east = $lng1_ne;
$south = $lat2_sw || -90;
$west = $lng2_sw;

$locations = Location::whereBetween('lat', [$south, $north])
    ->where(function($query) use ($west, $east){
        if ($west < $east){
            $query->whereBetween('lon', [$west, $east]);
        }else{
            $query->whereBetween('lon', [$west, 180])
                ->orWhereBetween('lon', [-180, $east]);
        }
})
->get();

Thursday, June 9, 2022

BlackMagic Ursa Mini G2 - Iso to gain DBs translation

Recently I have needed to get this information and couldn't quickly find it, so I'm shamelessly placing it here for next time :). 

db ISO
-12=100
-6=200
0=400
+6=800
+12=1600
+18=3200
+24=6400
+30=12800
+36=25600
Natives are 0db and +18db

ISO 100 = -12db. ISO doubles every 6db and the highest ISO is 25600 @ 36db.



Source: https://forum.blackmagicdesign.com/viewtopic.php?t=154758&p=822669

Friday, May 27, 2022

Python: valueerror too many values to unpack (expected 2) stackoverflow - dict to tuples

Admittedly, I haven't spent a lot of time in Python lately and find myself hitting my head on the wall trying to figure out some fairly simple things again. This is one of those such things.

Problem: 

I am using the requests library to interact with a server. This library has some great methods to prepare requests and then be able to send them at a later time. In one of these instances, I was building and preparing the Request with some data (also wrapping with the session to preserve cookie info):

request = session.prepare_request(Request('GET', "https://example.com/search", params=rdata))

The rdata object looks like a simple dict with key/value pairs. However, when running the code I got the error: 

ValueError: too many values to unpack (expected 2)


Solution:

After printing out the object and comparing it with a clean object, I found the issue:

rdata = {'key': 1, 'value': 2},

The comma at the end implied to Python that my structure was a tuple (pseudo: type(rdata) == <class 'tuple'>). Also, keep in mind my variable has a lot more data in it running it off the screen and I am not using word-wrap... so out of site, out of mind I guess. 

After removing the comma, rdata was seen as a dict again and could be converted to a list of tuples by requests prepare function.