Day: December 11, 2024

Show Only ...
Maps - Photos - Videos

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.