Tuesday, September 30, 2014

Running IntelliJ IDEA on Mac OS with Java 8

IntelliJ IDEA doesn't support Java 8 right now, but I want to use it anyway. :)

Here's my solution:

$ JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
$ sudo mkdir -p $JAVA_HOME/bundle/Libraries
$ sudo ln -s $JAVA_HOME/jre/lib/server/libjvm.dylib $JAVA_HOME/bundle/Libraries/libserver.dylib
$ cd /Applications/IntelliJ\ IDEA\ 13\ CE.app
$ vi Contents/Info.plist
And change the JVMVersion entry:
Then launch IDEA.

Source material:

  1. Info about running from the command line and updating Info.plist
  2. Info about symlinking

Thursday, August 14, 2014

MySQL on Mac for TechEmpower benchmarks

I always forget how to do this, so this is a note to myself.

  1. I've already installed MySQL on my Mac with Homebrew.
  2. Start MySQL.
    mysql.server start
  3. Create the user accounts, schema and data.
    sudo mysql  < config/create.sql
  4. Since I've never worked out how to increase MySQL's max number of connections, I manually decrease the size of the connection pool in every Play app's application.conf

Wednesday, August 6, 2014

Publishing play-slick [draft]

Here are my raw notes from my latest publish. They need to be verified for another release and then they can be turned into proper documentation.

  1. Create release branch.
    git checkout -b release-0.8.0
  2. Bump version in code/build.sbt.
    version := "0.8.0"
  3. Commit changes
  4. Go into plugin source directory.
    cd code
  5. Publish local.
    sbt +publish-local-signed
  6. Smoke test with Activator template.

    Source: https://github.com/loicdescotte/activator-play-slick

    Template: https://typesafe.com/activator/template/play-slick-quickstart

  7. Publish to OSS Sonatype staging repo (see guide).
    sbt +publish-signed
  8. Log in to repo admin interface.
  9. Close repository.
  10. If closing fails, fix problems and try publishing again.
  11. Smoke test again by adding repo to Activator template's build.sbt.
    resolvers += "Test repo" at "https://oss.sonatype.org/content/repositories/comtypesafe-1188"

    Remember to clear ivy cache first so you're not picking up the artifacts from your publish. Check that you see lines like the following for each Scala version you test.

    [info] downloading https://oss.sonatype.org/content/repositories/comtypesafe-1188/com/typesafe/play/play-slick_2.11/0.8.0/play-slick_2.11-0.8.0.jar ...
    [info]  [SUCCESSFUL ] com.typesafe.play#play-slick_2.11;0.8.0!play-slick_2.11.jar (3012ms)
    [info] downloading https://oss.sonatype.org/content/repositories/comtypesafe-1188/com/typesafe/play/play-slick_2.10/0.8.0/play-slick_2.10-0.8.0.jar ...
    [info]  [SUCCESSFUL ] com.typesafe.play#play-slick_2.10;0.8.0!play-slick_2.10.jar (3162ms)
  12. Fix up any changes and commit to release branch. Squash commits.
  13. Tag release. We're not pushing the release branch, just the tag.
    git tag -a -s -m 'Releasing 0.8.0' v0.8.0
    git push origin v0.8.0
  14. Create branch off master and update README.md with update version information. Create a PR for the update.
  15. Optionally create a PR for the Activator template with updated versions.
  16. Release the OSS Sonatype staging repository.
  17. Wait for Maven Central to sync. Can take a few hours.
  18. Once artifacts are available in Central, optionally smoke test again.
    [info] downloading http://repo1.maven.org/maven2/com/typesafe/play/play-slick_2.11/0.8.0/play-slick_2.11-0.8.0.jar ...
    [info]  [SUCCESSFUL ] com.typesafe.play#play-slick_2.11;0.8.0!play-slick_2.11.jar (3215ms)
    [info] downloading http://repo1.maven.org/maven2/com/typesafe/play/play-slick_2.10/0.8.0/play-slick_2.10-0.8.0.jar ...
    [info]  [SUCCESSFUL ] com.typesafe.play#play-slick_2.10;0.8.0!play-slick_2.10.jar (3524ms)
  19. Merge PR with updated README.md.
  20. Announce with a cross-post to scalaquery and play-framework lists.

Wednesday, June 4, 2014

Google Analytics download events using callbacks

Debugging analytics locally

Google Analytics won't send events when testing on localhost. To enable debugging on localhost, run this command in the browser console:

_gaq.push(['_setDomainName', 'none']);

Via Stack Overflow.

Tracking downloads

A download will cancel other HTTP requests, so analytics requests won't work. You need to delay the download until the analytics event has happened.

The trick is to run a callback after the event has been sent. Using ga.js-style analytics, here is how you do it:

if (window._gaq) {
        ["_set", "hitCallback", triggerTrackedClick],
        ["_trackEvent", "download", "click", label],
        ["_set", "hitCallback", null]
} else {
    // Trigger tracked click immediately if analytics not loaded

Update 3 July 2015: An easier way to do this for downloads, is to target the download at either _blank or an internal iframe. Targeting the download means that the download doesn't unload the current page, so Google Analytics events aren't interrupted by the download. See this PR for an example of how the code can be simplified.

Sunday, May 25, 2014

WiFi problems on Mavericks

I had very unstable WiFi when I upgraded my late-2012 Retina MacBook Pro to Mavericks (model: MacBookPro10,1). Upon waking from sleep, my MacBook usually wouldn't connect to WiFi. I had to try manually reconnecting several times to get a connection.

The solution for me turned out to be trashing my Bluetooth preferences file (/Library/Preferences/com.apple.Bluetooth.plist) and restarting.

Instructions courtesy of Peter Cohen!

Friday, March 7, 2014

JavaScript language libs in JavaScript

Various tools for working with JavaScript/EcmaScript code.


See also: Mozilla Parser API.

Code printers


Virtual machines

Sunday, February 2, 2014

Gettings stats for Play’s “Get involved” page

Here is how I get stats for the upcoming Play framework Get involved page.

Getting the number of committers

$ git shortlog -sn | head
   695 James Roper
   517 Guillaume Bort
   336 Peter Hausel
   330 Christopher Hunt
   237 peter hausel
   234 Sadek Drobi
   140 Erwan Loisant
    95 Rich Dougherty
    95 Nilanjan Raychaudhuri
    83 Julien Richard-Foy
$ git shortlog -sn | wc
     312     878    6391

The first column returned by wc shows that Play has had 312 committers over the repository's lifetime.

Credit: Pedro Nascimento's answer on Stack Overflow.

Getting the number of issue reporters

I'm counting creators of both open and closed issues. Even better would be to include people who comment on issues as well.

#!/usr/bin/env python

import requests
import json

def getIssues(page, state):
  return requests.get('https://api.github.com/repos/playframework/playframework/issues?state={}&page={}'.format(state, page))

def getReporters(page, state):
  resp = getIssues(page, state)
  if resp.ok:
    reporters = set()
    issues = json.loads(resp.content)
    for issue in issues:
      reporter = issue['user']['login']
    return reporters
    return None

def getAllReportersForState(state):
  reporters = set()
  page = 1
  while True:
    reportersForPage = getReporters(page, state)
    if reportersForPage:
      reporters |= reportersForPage
      return reporters
    page += 1

openReporters = getAllReportersForState('open')
print '=== open ==='
print openReporters
print len(openReporters)

closedReporters = getAllReportersForState('closed')
print '=== closed ==='
print closedReporters
print len(closedReporters)

allReporters = openReporters | closedReporters
print '=== all ==='
print allReporters
print len(allReporters)