Jacks Repository

The other day I attempted to browse a J script described in an old blog post only to find that my employer’s network monkeys had blocked the file sharing service. I’ve railed about IT control freaks in the past. They will not rest until it’s impossible to do useful work. I fumed and grumbled until I perceived a bigger problem. I have so many references to program code in this blog that it’s getting tedious tracking them down. Wouldn’t it be nice if my hacks were neatly organized in one coherent repository?

Let me introduce jacks. jacks, or “J-hacks”, organizes the J related code referenced in this blog into a single GitHub repository. Most of the scripts in jacks are one-offs but some have proven so useful that it makes sense to store them in a repository and track changes. From now on jacks will be the first place to look for code from this blog. You pull the contents of jacks into a new Git repository with the commands:

git init
git remote add jacks https://github.com/bakerjd99/jacks.git
git pull jacks master

It took me a few moments to settle on the name “jacks.” I considered “jokes” because programmers often take their code too seriously and “jocks” because J programmers are wild out of control convention eschewing code jocks but jacks won out when I remembered the refrain “jack be nimble, jack be quick, jack jump over” whatever coding problem is pissing you off.

Australia It Is

I’m putting up with a little feces storm; it’s flying off the fan in all directions.

Let’s start with work. Lately it’s been grueling. I’m coding like a mad twenty something, wasting my weekends for the man and being very much the good little corporate drone. I do my best to avoid crazy hours but I’ve foolishly allowed myself to care about the problem. I’m kind of surprised that in my boomer dotage I am still capable of going into deep code: that weird state where you have dreams about iterators and interfaces. In my feverish coding dreams I’m always one step from nailing a problem, all that remains is a stupid little tweak, but for the life of me I cannot see it.

Moving on: my wife and elderly demented mother-in-law have fled the US. They’re both back in Canada where my wife is attempting to get her mother placed in a facility that can handle her Alzheimer’s. My poor wife has looked after her demented mother for almost two years and it’s completely worn her down. Caring for the Alzheimer stricken elderly is far more draining than looking after newborns. I’ve done both and believe me babies are a breeze. And, if one demented mother-in-law wasn’t bad enough, this week I learned my mother has a “growth” near the speech center of her brain. We’re awaiting biopsy results so we don’t know what the “growth” is, but brain growths are never good news. 

We need a vacation which brings me the results of the first ever ADND poll.  I asked a simple question: which country should we visit, Argentina or Australia? I didn’t expect any answers but a few readers chimed in and, the last time I looked, Australia was the winner! Until two months ago Argentina was still in the running but it looks like Kirchner is a bigger economic imbecile than Obama. You go girl!  Until the economic dust settles Argentina looks like work so it’s off to Australia in the fourth quarter.

I’ve started marking places to visit. If anyone has suggestions please drop a note.

GPX from Google Maps KML J Script

In preparation for my Arizona jaunt to watch the May 20th annular eclipse I spent a few hours on Google Maps selecting locations to visit.  Here are my prime targets.

After selecting targets the next step is to load them onto my “GPS device.” Currently my GPS device is the MotionX GPS iPhone app.  MotionX can read GPX files in many ways but you need GPX files not Google Maps KML files. Converting KML to GPX is a recurring nuisance. I’ve used online converters for this chore but today, after being annoyed by this problem for the zillionth time, I dashed off a J script that transforms Google Maps KML to GPX.  The main verb gpxfrmapkml is shown below. The entire script is available here and in the files sidebar. Browse to the J Scripts directory. Happy KML to GPX’ing my friends.

gpxfrmapkml=:3 : 0

NB.*gpxfrmapkml v-- gpx from Google maps kml.
NB.
NB. monad:  clGpx =. gpxfrmapkml clKml
NB.
NB.   NB. download Google map waypoints as kml
NB.   kml=. read 'c:/temp/arizona annular eclipse.kml'
NB.
NB.   NB. convert to gpx and save
NB.   gpx=. gpxfrmapkml kml
NB.   gpx write 'c:/temp/arizona annular eclipse.gpx'  

NB. parse kml form waypoint table
dname=. ;'name' geteletext '<Placemark>' beforestr y
wpt=.   ;'Placemark' geteletext y
wpt=.   ('name' geteletext wpt) ,. <;._1&> ','&,&.> 'coordinates' geteletext wpt
hdr=.   ;:'phototitle longitude latitude'

NB. format gpx header 
gpxstamp=. 'Waypoints: ',(":#wpt),' GPX generated: ',timestamp''
gpxheader=. ('/{{headername}}/',dname,'/{{headerdescription}}/',gpxstamp) changestr GPXFRKMLHEADER
gpxtrailer=. GPXTRAILER

'idx pkml'=. HTMLVARBPATTERN patpartstr GPXSMUGPLACEMARK
rvarbs=. idx htmlvarbs pkml

NB. all row varibles must exist in data header
assert. *./ rvarbs e. hdr
rows=. (#wpt) # ,: pkml
rows=. ((hdr i. <'phototitle'){"1 wpt) (<a:;(rvarbs i. <'phototitle'){idx)} rows
rows=. ((hdr i. <'latitude'){"1 wpt) (<a:;(rvarbs i. <'latitude'){idx)} rows
rows=. ((hdr i. <'longitude'){"1 wpt) (<a:;(rvarbs i. <'longitude'){idx)} rows

gpxheader,(;rows),gpxtrailer
)