Export Heroku Postgres to CSV

I needed to export a table in a Heroku Postgres table. But the COPY query requires administrator privileges, and I don’t have those on heroku. Luckily you can use the \COPY command:

% heroku pg:psql --app my-app-production
---> Connecting to DATABASE_URL
my-app-production::DATABASE=> select count(*) from some_table;
 count
-------
 20910
(1 row)

my-app-production::DATABASE=> \copy (SELECT * FROM some_table) TO some_table.csv CSV DELIMITER ','
COPY 20910

This writes the contents of some_table to some_table.csv in your working directory.



Fix Xcode's Open Quickly Navigation

Open quickly is one of the best features in Xcode. It saves you haveing to move your hand to the mouse and select a different file. But there is no way to navigate through the selection unless you use the arrow keys. The arrow keys that are so, so far from the home row. It baffels me that Control-N and Control-P, which are normal Cocoa controls for next and previous (try this in Safari for example).

I knew Karabiner should be able to fix this. It took a little tinkering, but I got it. It is so nice. Also added Control-J and Control-K to appease my vim habbits.

Add the following XML to ~/Library/Application\ Support/Karabiner/private.xml, then search for “Xcode” and enable them in Karabiner:

karabiner

<?xml version="1.0"?>
<root>

<appdef>
  <appname>XCODE</appname>
  <equal>com.apple.dt.Xcode</equal>
</appdef>

<item>
  <name>Remap Control+N to Down in Xcode</name>
  <appendix>Active in Xcode</appendix>
  <identifier>private.xcodeNDown</identifier>
  <only>XCODE</only>

  <autogen>
    __KeyToKey__
    KeyCode::N, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL,
    KeyCode::CURSOR_DOWN
  </autogen>
</item>

<item>
  <name>Remap Control+P to Up in Xcode</name>
  <appendix>Active in Xcode</appendix>
  <identifier>private.xcodePUp</identifier>
  <only>XCODE</only>

  <autogen>
    __KeyToKey__
    KeyCode::P, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL,
    KeyCode::CURSOR_UP
  </autogen>
</item>

<item>
  <name>Remap Control+J to Down in Xcode</name>
  <appendix>Active in Xcode</appendix>
  <identifier>private.xcodeJDown</identifier>
  <only>XCODE</only>

  <autogen>
    __KeyToKey__
    KeyCode::J, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL,
    KeyCode::CURSOR_DOWN
  </autogen>
</item>

<item>
  <name>Remap Control+K to Up in Xcode</name>
  <appendix>Active in Xcode</appendix>
  <identifier>private.xcodeKUp</identifier>
  <only>XCODE</only>

  <autogen>
    __KeyToKey__
    KeyCode::K, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL,
    KeyCode::CURSOR_UP
  </autogen>
</item>
</root>

You can find all my Karabiner settings in my dotfiles repo on GitHub.



Testing for TLS 1.2

iOS 9 requires all NSURLConnection connections to support TLS 1.2. So I needed to check my servers to see if this was indeed configured. After looking around a bit I was able to find that you could test for this using openssl.

On OS X with homebrew you can test with this command:

/usr/local/Cellar/openssl/1.0.2d_1/bin/openssl s_client -tls1_2 -connect www.codeography.com:443

If you have linux (with a new enough openssl) or have overridden the system openssl on OS X you can just leave off the full path:

openssl s_client -tls1_2 -connect www.codeography.com:443

If it is supported you’ll see the Certificate chain as well as some information about the connection. The bit I was looking for was “Protocol: TLSv1.2”

Looked something like this:

New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
SSL-Session:
    Protocol  : TLSv1.2
    TLS session ticket lifetime hint: 1200 (seconds)


Playing Minecraft when the Port is Blocked

I was at a conference this last weekend and the network blocked the port that minecraft needed to connect to the server. So I spent longer than I would like to admit setting up a ssh tunnel. Here’s what I did:

1) Create the tunnel

ssh -L 8080:yourminecraftserver.club:25565 -p 22 -l yoursshuser -N yoursshserver.com

This will stay running in the terminal. Just leave it going while you play.

2) Configure minecraft to use that tunnel

Create a new server by selecting “Multiplayer -> Add Server” and use the following settings:

Server Name:
Proxy
Server Address:
localhost:8080

Now you should be able to connect and build that dirt hobble you’ve been planning.



How do you write great commit messages?

The best way to learn to write great commit messages is to go back and read them.

When reading code take a moment and go look at the git history every time you mutter “why did they do that.” That’s the point in time when you want to know the real “why” behind the change. If you don’t already know how to to that, take moment to figure out a way quickly to access the history of a line in your editor or in your repo, the less friction the easier it is to go back and read about the changes.

If you make a habit out of this, you will quickly learn what is helpful and what is not. Then, if you are like me, you’ll want to go back to slap your past-self for being lazy and giving a few bullet points of “what” was changed and not “why” it was changed.

Sound good? You in? Cool.

To get started just add the word “because” to your commits.

Lets look at an example.

Changed the post title font size

Changed 0.8em 16px.

h2 {
-  font-size: 0.8em;
+  font-size: 16px;
}

And what if I ever come across this file, I might wonder why this person strayed from the convention of using relative font sizes to pixels. I would would mutter “wtf” to myself and pop open the git blame in my editor for that line and read the commit message. This right here is the point that I want to know why.

Changed the post title font size

Fixed it to 16 pixels because when we increased the overall font size on
the blog the titles were wrapping on mobile views.

h2 {
-  font-size: 0.8em;
+  font-size: 16px;
}

Now this is helpful. It gives me context. I get clues on what changed in this code and what might break. And I can see that it wasn’t some arbitrary change. Me in 6 months will appreciate this.

A commit already contains a diff, so it shows what was changed. No reason to write that up again. But nothing explains why you made that horrible hack or sweeping change.

Communicating the current reasoning to your future self is a super power.


Further Reading

There have been many posts about commit message from formatting to content. Here are a few of my favorite, should you want to level up:

Tim Pope’s A Note About Git Commit Messages. This is formatting and syntax, but if you follow this I will be much, much happier.

Caleb Thompson’s 5 Useful Tips For A Better Commit Message. A bit vim-centric, but great guidelines.

Stephen Ball’s Deliberate Git. An in depth guide to commit messages. Worth the time to read and understand.

Keavy McMinn’s How to write the perfect pull request. Slightly different than commit messages, but they really go well together.