Personal

Code, Code, Code

If you want to be good at something, you have to constantly do it, practice.

One of the reasons I’ve not been as much blogging lately is because I’ve been spending so much time studying C/C++ coding, along with some Rust programming, along with other supporting languages like DuckDB and SQL. A lot of it is just watching videos and reading, though I know the thing I have to do more is sit down and write actual code. The problem is that C/C++ doesn’t provide a natural path for developing content for the blog, and that many of the projects I can up with in C aren’t obvious what to turn them into actual products. Part of it is finding libraries that are useful, and using them to generate good interesting content.

R is my usual standby, but I know while R is handy for coding, and I like many things about that language, it’s no C/C++ when it comes to writing professional software, building things made to last. R is great for quick one-offs, the kind of throwaway content for the blog, but it’s not as great for things you are building to last for decade, or run quickly in a production environment. But between my personal use of R and at work, it’s such powerful tool.

A Bash Script for Geocoding Addresses in New York State

If you are on your typical Linux or Unix server you probably have everything you need to run this script such as cURL and sed, except for possibly for jq which was on my home computer but has no dependencies and can be easily installed on most Unix servers by just compiling the source code.

#!/bin/bash
url="https://gisservices.its.ny.gov/arcgis/rest/services/Locators/Street_and_Address_Composite/GeocodeServer/geocodeAddresses"

query=''
i=1
while read -r LINE; do
	LINE=$(echo $LINE | sed -e 's/"//g')

	if [ $i -ne 1 ]; then query+=","; fi

	query+=$(printf "{ \"attributes\": { \"OBJECTID\": %s, " $i)
	query+=$(printf "\"SINGLELINE\": \"%s\" } }\n" "$LINE")

	if [ $i -eq 1000 ]; then 
		query="{\"records\": [ ${query} ] }"

		curl -s -F f=pjson -F outSR=32768 -F addresses="$query" $url |
			jq --raw-output '.locations |= sort_by(.attributes.ResultID) | .locations[] | [.address, .score, .attributes.Match_addr, .attributes.ResultID, .location.x, .location.y ] | @csv'
		i=1
		query=''
	fi 
	
	((i++))
done < /dev/stdin

# handle remaining records
query="{\"records\": [ ${query} ] }"
curl -s -F f=pjson -F outSR=32768 -F addresses="$query" $url |
	jq --raw-output '.locations |= sort_by(.attributes.ResultID) | .locations[] | [.address, .score, .attributes.Match_addr, .attributes.ResultID, .location.x, .location.y ] | @csv'

Inspection Dun… Passed

I told myself I was going to catch a bus down to the shop. But I didn’t want to pay a $1.35 to ride the bus. So I walked there. It wasn’t raining too hard until it was. Still it’s raining down pretty hard now that I’m at the library. Shrug. I’ll be driving home this evening, in the rain once I get some work and some code I’m working on done that I need files from the interwebs from.

The People of New York State as represented by the local repair shop say Big Red is safe & clean enough to drive 4 another year.

Good morning, Happy Inspection Day πŸ›»πŸ”οΈ

And tire rotation day. Not raining so hard, though I expect to get fairly wet after dropping off my truck. I guess it best to walk home rather then ride, I’m a bit on the fence. I think by the time I unload the bike from truck, ride back, I’d get wetter then just walking home. If necessary, I’ll I can catch a bus. I won’t melt in the rain.

Fingers crossed that things will go well with the inspection. 🀞 I know the lights, tires, and windshield wipers are good, so that’s two thirds of the inspection. I worry too much but if there is a deficiency in the suspension that needs to get fixed, it will get fixed. But it seems okay, things haven’t really gotten worse this year, and the truck is old at this point. Who knows, this might be the last inspection or maybe not. Just got to get through it.

Cornmeal pancakes this morning, πŸ₯ž along with shredded oatmeal and a banana. 🍌 I also kneaded up some apple-cinnamon bread which is rising in the oven, and I will bake later this morning. Thinking about also making some red-lentil soup on this cold rainy December morning. 🍲 This should be a good day taking off, not having to worry about getting dressed up for work. Besides cooking, I want to do some reading πŸ“š and working on code. Albany County published their official results — in an Excel file — yeah! so I may want to make some maps up. πŸ—Ί I might go down to the library when I pick up my truck this afternoon, as there is some data I would like to pull off the internet and don’t want to use too much mobile bandwidth.

Weekend still looks like rain, 🌧 at least come Sunday. Not going to camping this weekend, just because I want to do more then one night, and not in the rain. I might take off the second half of next work week, depending on the status of the database update at work. πŸ’Ύ I was looking at a photo I took of my bike 🚡🀳 and realized that the lock wasn’t on the hanger fairly on, so that narrows down the places I could have lost the lock. It’s possible — maybe even likely — I took it off when I started riding due to the rough terrain and it falling off, and it’s somewhere in my apartment. I’ll go back looking on the bike trail on Saturday morning. πŸ” Once the snow and ice melt today, along with the much smaller area for search, πŸ”’ I think that will increase my chances of finding it. Without the key it’s not likely particularly valuable to most people to be stolen..

jq

jq

jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.

jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you'd expect.

This library is really handy and I was able to build it with ease on the server at work with ease and it was pre installed on my laptop.