Golang in one word? Productivity

I’ve been batting around this idea over the past few days. Golang is a great language and it has many superb features, but if I had to distill what I like so much about Golang into one word, that word would be “productive.” I feel so incredibly productive writing Golang code.

Start with the documentation. I love Golang’s documentation. I don’t know how much of it was a conscious decision by the developers, but the “culture of documentation” that I loved in Python is very much alive in the Golang community. Reading the documentation of standard library packages on godoc.org made a language I didn’t know just a few weeks ago much more understandable. I’ve been able to easily integrate third-party packages into my code because they were all well documented.

Coming from older languages, the tooling around Golang feels so modern. go get and you’ve got the package on your system, ready to use. go fmt and you don’t have to waste cycles on getting the format just right. go install and you’ve got a binary or a library in a few seconds. And the Github support! We developers love our Github, so why not make use of it to host code? It’s brilliant.

Then there’s the parts of the language spec itself. At first, I didn’t care for struct tags, but now I’ve seen the light. So much of programming is slinging bits around in XML or JSON — why not include that info front and center? The way pointers are automatically dereferenced when needed lets me focus on what my code is trying to solve, not the nuts and bolts of memory management.

I’m still getting my feet wet with Golang but I haven’t felt this productive in a new language in a long time.

How to track traffic in Google Analytics without JS

I’ve long wanted to hook up the RSS feeds on hnrss.org to Google Analytics so I could get a better sense of what kind of traffic the site got. But because the feeds are delivered as XML, I had to figure out a way to do it without JavaScript.

After some poking around yesterday, I finally figured out a way.

Google Analytics has a Measurement Protocol API built for this sort of thing. You send a HTTP request (POST and GET both work) with the necessary parameters, and it’ll register the hit in your Analytics property.

After testing it out locally using curl and seeing it all work, it was time to integrate with the app.

After searching around for awhile, the eureka moment came when I discovered the post_action feature of NGINX. This enabled me to hit the Measurement Protocol API after serving the feed.

Here’s the necessary bits that I had to add to my NGINX config to get it all working:

# replace UA-XXXXXXXX-Y with your Analytics property ID
location @GA {
  internal;
  resolver 8.8.8.8 ipv6=off;
  proxy_pass https://www.google-analytics.com/collect?v=1&tid=UA-XXXXXXXX-Y&cid=$remote_addr&t=pageview&dp=$request_uri&uip=$remote_addr;
}

server {
  # the standard stuff (server_name, listen, etc.)
  location / {
    # no changes needed other than adding post_action
    post_action @GA;
  }
}

Also, directly passing the User-Agent (e.g., ua=$http_user_agent) gave me all sorts of problems (I think it wasn’t being properly URL encoded) so I sanitized them with a map:

# N.B. maps have to exist in the http context
map $http_user_agent $user_agent {
  ""                    empty;
  "~Android"            android;
  "~^Slackbot"          slackbot;
  "~^curl"              curl;
  "~^Feedbin"           feedbin;
  "~^Tiny Tiny"         ttrss;
  "~^NewsBlur"          newsblur;
  "~^Feedly"            feedly;
  "~^Go-http"           golang;
  "~^UniversalFeed"     feedparser;
  "~^Zapier"            zapier;
  "~^PHP"               php;
  "~^python-requests"   python-requests;
  "~^Mozilla"           mozilla;
  default               other;
}

Then I added ua=$user_agent to the URL. Not ideal, but good enough for me.

Introducing my college basketball ratings system

With conference play starting up, I’ve finally put the finishing touches on my college basketball ratings system: EJD CBB Ratings. I wrote a bit about the technical details and how it came about here.

Its goal is to predict the outcome of game featuring any two college basketball teams. It also serves as a way to teach myself more about sports ratings systems in general and matrices/systems of equations in particular.

Good luck, UNLV

When you’re a UNLV basketball fan, you’re used to knots in your stomach. No lead feels safe until the final buzzer rings. Opposing players put up career days with alarming regularity. Bottom feeder teams come out swinging against the former World Champs and steal one on your home floor. But those knots usually subside once the season wraps up.

When Mick Cronin flew back to Cincinnati without being announced as the new head coach, I knew the knots would be here to stay during the offseason, too.

Spurned by Cronin, Chris Beard and Marvin Menzies interview for the job and Beard is hired within 48 hours. The ponderous Board of Regents begins its approval process while players — current and future — get as far away from the program as possible. After a jaw-droppingly awkward meeting where the contact is finally approved, Beard gets to work stabilizing the program. Nearly every remaining recruit in the country with a pulse is offered. It’s going to be tough and the first year will be ugly, but if anybody can do it, it’ll be Beard. The Rebel mustache now has a matching Beard. The dumpster fire appears extinguished when Tubby Smith gets a call from Memphis.

Smith to Memphis happens quickly and the hypotheticals begin appearing immediately. “What if Beard jumps ship to Texas Tech? Wouldn’t that be wild?” Hours without any official word from Beard or UNLV turn into days. The odds-on outcome is no longer Beard staying, but Beard leaving. A jet from Texas arrives. This is really happening. The Chris Beard era at UNLV is coming to an end. An official announcement is made and the coaching search hopes the third time is the charm.

Menzies gets on a flight to Las Vegas so quick there is a trail of dust following him. This is his dream job and he doesn’t care how bad of shape the program is in. Menzies should have doubled his salary request. Could UNLV have said no? I doubt it. The program starts from scratch, again. Menzies gets an early win by convincing Morgan to stay. Every little bit helps. Recruits and transfers start becoming official. Slowly, the program begins to turn around.

But as UNLV begins conference play tonight, I feel more disconnected from the program than I can ever remember. Nervousness about games has taken a back seat to apathy. Outside of a handful of players, it’s all new faces. It’s going to take a few years for Menzies to get the players he wants, I understand that. And Las Vegas is an easier sell than Las Cruces so I have no doubt he’ll get the players eventually. One day, we’ll have a team with the Marvin Menzies stamp of approval. But until then, this season feels like going through the motions. It’ll be a slog through a bad, one-bid Mountain West Conference. At best, we’ll pin some losses on the bad teams and stay close with the good ones. Most painful of all is watching UNR become the new powerhouse with a chance of winning the league championship inside the Thomas & Mack. Them having the cannon and a championship is the darkest timeline.

I will always love UNLV and be a fan of UNLV athletics. Hopefully a new athletic director can begin fixing Kunzer-Murphy’s many missteps made during her helm. Hopefully Menzies proves me wrong and makes UNLV into a contender this year and going forward. I didn’t get into football, but hopefully Tony Sanchez can finally break through with a bowl next year along with winning back the cannon.

But that’s a lot of hope for a year that wasn’t very hopeful.