Wednesday 11 October 2023

Can we just autofill city and state? Please!

Coming from a country that is not the US where zip/postal codes are hyper specific, it always drives me nuts when you are filling in a form in the US that is like:

City

State

Zip

It's patently obvious and massively infuriating that anyone from a country such as the UK that this could be trivially autopopulated if you asked for the zip first. In the UK you usually are asked to enter the postcode and then the first line is the only one you have to complete.

As with many things in the US, why is this so hard?

Like literally, mash in the 10011 -> New York City, New York. Done. It would also improve the quality of the data that the forms collect.

So in an idle 10 minutes I decided to have a go at fixing the problem with ChatGpt.



Looks pretty sensible to me. Does it work? Sure does.

One small snag is that there are zip codes that cross state lines. That's a minor annoyance and one of the justifications used to excuse this lack of functionality in form filling websites. OK so I tested it with a zip that is ambiguous:

[nix-shell:~]$ node ~/state/state.js
State: Arizona
City: Teec Nos Pos

This seems reasonable. If you are one of the poor suckers who lives in an ambiguous zip then I am sorry, that is the price you have to pay. At the moment everyone is paying the price to fill in City and State!



Ok so let's ship it.


// Define a function to resolve ZIP code to state and city
function resolveZipCode(zipCode, callback) {
  // Define the API endpoint for Zippopotam
  const apiUrl = `https://api.zippopotam.us/us/${zipCode}`;

  // Make an HTTP request to the API
  fetch(apiUrl)
    .then(response => {
      if (response.status === 200) {
        return response.json();
      } else {
        throw new Error('ZIP code not found');
      }
    })
    .then(data => {
      const state = data.places[0].state;
      const city = data.places[0]['place name'];
      callback(null, { state, city });
    })
    .catch(error => {
      callback(error, null);
    });
}

// Example usage
const zipCode = '86514'; // Replace with the ZIP code you want to resolve
resolveZipCode(zipCode, (error, result) => {
  if (error) {
    console.error('Error:', error);
  } else {
    console.log('State:', result.state);
    console.log('City:', result.city);
  }
});



Wednesday 13 September 2023

deauthenticated due to inactivity (timer DEAUTH/REMOVE)

I have an r6260 running dd-wrt which my pixel 7 was having trouble connecting to. It would connect-ish and then say there was no internet and disconnect.
It would do this more aggressively on the 5g channel than the 2.4g channel, both didn't really work well though.

Reading the syslogs in dd-wrt in the status tab logs it would show:


deauthenticated due to inactivity (timer DEAUTH/REMOVE)
 
A miniscule bit of a Googling led me to this post which recommended a dissoc setting that allegedly was aggressively disconnecting the client after inactivity. Switching that didn't do anything seemingly.
Another post that I saw for IOT devices recommended simplify the wireless security settings. So I went into the wireless settings tab and changed my 5g network to only support WPA2-Personal (removing WPA3-Personal) and only supporting CCMP-128 algorithms.

Save settings, reboot and voila the connection is stable. Seems like a bug in android not being very stable in mixed WPA2/WPA3 networks? Other devices like my macbook work just fine.

Friday 12 July 2019

Reading For Team Leads

Radical Candor: awesome way of thinking about what you do with your day and how you work with your people.
What Got You Here Won't Get You There: gives you a good perspective on the role
One Minute Manager: classic but not very useful.

Sunday 9 June 2019

Strava GPX Format for Watts and Power

Strava documentation here is vague. The tags you need to set to extend the Garmin GPX format to allow Cadence and Power look like this:

      <Cadence>0</Cadence>
      <Extensions>
       <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
        <Speed>2.5</Speed>
        <Watts>0</Watts>
       </TPX>

      ...

So to add the Watts to a Trackpoint you need to use the TPX tag and set the namespace to an extension and put the Watts in there.
 

Monday 11 September 2017

Playing with Google Cloud Services

Late last night I wanted to build a simple but humorous website (the details of which shall remain veiled from you). The website simply needed to serve up a random image, i, (from a collection of N) and then serve a title that I had associated with said i. That is, show an image and a caption.

Being an engineer, I knew I simply must over-engineer this simple challenge. I also wanted to use it as an opportunity to learn a little about the Google Cloud Services products (Google's answer to Amazon Web Services).

I spent some time perusing the vast litany of products that Google Cloud Services provides; from storage, to compute, to SQL to container hosting to VM hosting; it's all there. I didn't see anything missing (yet).

My initial design looked something like the following (artwork courtesy of yours truly).
My Website 1.0
The general idea was that I would have some sort of Google Cloud Function that would house the business logic of my project. It would simply get a random number in a given range and then request an image with that number from Google Cloud Storage and return its url. I would house the captions in a database (in this initial design I chose Spanner since that seemed hip and cool and in the news but then I realised it was expensive so opted for postgres later). This initial design was missing where the html would actually be served from as we will find out later.

Google Cloud Storage was the most impressive thing so far. It was really easy to setup and get used to; it was easy to understand and striaghtforward to use.

I realised fairly quickly that Google Cloud Function was not appropriate for what I was doing. What I should be using was Google App Engine (known as GAE). This thing was built literally for hosting websites (mine was not static). I followed the initial hello world tutorial and realised it only needed a tiny bit of tweaking for me to use it for my website.
After about 2 hours I was serving some simple HTML from GAE (using a Go application) that would simply generate a random number in a given range and then serve the image with that name from my GCS. Simple.

Now I wanted to serve the captions for these images. Initially you could see that I wanted to put them in a database (Postgres because I don't like MySql). Postgres is still in beta on Google Cloud Services. Getting Postgres in a usable state was tremendously hard. I was able to create the tables through an interactive prompt launched from the GAE website but it was very difficult to get my GAE connected to the same instance - I spent 1 hour jerking around with certificates and keys to only get hangs. I could at some point connect interactively with psql from my GAE prompt but not reliably - not sure what was going on. There are tutorials on GAE for connecting to postgres from Java and Python (which seems to need a proxy!?) but nothing for Go (yet). So I was kinda stuck up a creek without a paddle.

So I just mashed the captions into the code and put out version 0.1.

The end design looking something like this:

The diagram is actually pretty inaccurate since the go code doesn't actually talk to GCS but it just generates the URL and the browser downloads it.

The whole process was pretty cool all in all. I was able to get up and running without spending a penny (1 year of $300 for free when you sign up woo) and jump around the different products easily. The integration between the Postgres/GAE stuff was terrible. It was really hard to work out how to get the auth setup. I also didn't take enough time to setup the interactive tools locally - my internet was spotty - and using the web based tmux console was very painful and slow. But it was fun to bash something out from my browser that hit GCS and used Go without having to download a megalith of tools that I would never look at again.

ICV?

Can we just autofill city and state? Please!

Coming from a country that is not the US where zip/postal codes are hyper specific, it always drives me nuts when you are filling in a form ...