Transitioning PGP Keys

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1,SHA512

2016-11-06 05:25:00 +0000

I am replacing my old DSA-1024 key with a stronger RSA-4096 key. The primary
motivation is to store my key on a Yubikey Nano which doesn't support DSA,
however there is a possibility that the old key has been compromised. Although
I don't have any evidence to suspect this, I certainly haven't been as careful
over the years as I could have.

The old key was:

sec 1024D/1209F481 2010-05-24
Key fingerprint = 093B A359 D87C E901 9AAE ACDF BF99 B090 1209 F481

And the new key is:

sec 4096R/5B640B9F9600F122 2016-02-29
Key fingerprint = 427E 0329 39DB 40F2 9D03 D80F 5B64 0B9F 9600 F122

To fetch the full key from a public key server, you can simply do:

gpg --keyserver pgp.mit.edu --recv-key 5B640B9F9600F122

If you already know my old key, you can now verify that the new key is
signed by the old one:

gpg --check-sigs 5B640B9F9600F122

If you don't already know my old key, or you just want to be double
extra paranoid, you can check the fingerprint against the one above:

gpg --fingerprint 5B640B9F9600F122

If you are satisfied that you've got the right key, and the UIDs match
what you expect, I'd appreciate it if you would sign my key:

gpg --sign-key 5B640B9F9600F122

Lastly, if you could upload these signatures, i would appreciate it.
You can either send me an e-mail with the new signatures (if you have
a functional MTA on your system):

gpg --armor --export 5B640B9F9600F122 | \
mail -s 'OpenPGP Signatures' philihp+signature@gmail.com

Or you can just upload the signatures to a public keyserver directly:

gpg --keyserver pgp.mit.edu --send-key 5B640B9F9600F122

Please let me know if there is any trouble, and sorry for the
inconvenience.

Jolan'tru,
Philihp Busby
-----BEGIN PGP SIGNATURE-----
Comment: http://keybase.io/philihp

iEYEARECAAYFAlgev3IACgkQv5mwkBIJ9IFQ0wCfThA3ak97QRVkgCDuFPDKNZfg
lJEAn0ANZrQsLZU2eBatwqXp89V2YJwViQIcBAEBCgAGBQJYHr9yAAoJEFtkC5+W
APEiqJgP/jUuel2Wf9/uf5AnghP7Qm55niGxCJKGc2+QYUUyzyKKTddcZNkfAqLe
Z4mtMelH2uVppU9KxLfe8aQCfXmY6iijJh2Hqreq0/T/F5pEzCQc5J5d/AcEI4PL
Lb3U8X1nIay7YeFtfqKHSFe06AbK1Bn6viMNHP4mVLqkw5S8A3+umFsTyq7ekfuq
sMZx1uppcjVrxAi4fbHQ5bYWf50aH7C+g2OISFOpTmbdgH7M3B+dTNuJ4TJrvvh6
4NPPglcnHlcBDUVZVFdL4f26Ig7OhGdvoCnBPE+vET8+D9qHpAdsgho5iMFpgp3x
erOQYFm4DvWx+HqdplhnWNpRH9PjjxOKy+14bCGbAurgytTJlACJReuQuVDW1yzU
y3xvKfMPheU6x4o9Px1X6ldhKn/lXwUW7z0wJxxzoCS8rveRF6pUwZhRWjaP5JuX
INIVxByiY9JLXeuImKpiV4UQ0IvYK7McKN9TiVpIYe9YRYn7I6miYf+BPTZmtBOr
qz72V8HwPjrrF+24QANL3wYIIsV2vVL2Lm60TkKt6qfkDXgO841pWGHY9IrPaSVA
S3YF5n/b/rFYx/k8AD7Na8uWS61d996pSn0vBkv8j6ReKlGuuKIxa60yTrNpnlmV
m22Y/8DtgN07K5zulcvD+KcZecPS47TlxspCPpQwzu1bsaCRBScQ
=DWIc
-----END PGP SIGNATURE-----

Raw Document

Why?

Error: ENOENT when installing Pow on macOS

I kept getting this error when installing pow on macOS. There are some old threads about it, with fixes for previous verisons of OSX prior to El Capitan, but for the most part it seems to be a solved bug.

philihp@sterling ~$ curl get.pow.cx | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9039  100  9039    0     0   8763      0  0:00:01  0:00:01 --:--:--  8767
*** Installing Pow 0.5.0...
*** Installing local configuration files...
*** Installing system configuration files as root...
Password: hunter2

/Users/philihp/Library/Application Support/Pow/Versions/0.5.0/lib/command.js:20
      throw err;
            ^
Error: ENOENT, open '/tmp/pow.98645.1466285627293.3185'

If you’re getting this error too, perhaps the solution will be similar to mine?

It turned out that I had at some point changed the default shell of my root user to /usr/local/bin/fish, then uninstalled fish, and never bothered to set it back. I guess this isn’t really a problem most of the time because not much should (hopefully) ever run as root, but it finally surfaced here when trying to install Pow.

My solution was the following:

  1. Enable the root user with dsenableroot
  2. If you try to sudo su, you will get something like su: /usr/local/bin/fish: No such file or directory
  3. Change root’s shell with sudo chsh -s /bin/sh
  4. Disable the root user with dsenableroot -d

Once I did this, installing worked as normal.

philihp@sterling ~$ curl get.pow.cx | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9039  100  9039    0     0  17142      0 --:--:-- --:--:-- --:--:-- 17151
*** Installing Pow 0.5.0...
*** Installing local configuration files...
*** Starting the Pow server...
*** Performing self-test...
*** Installed

For troubleshooting instructions, please see the Pow wiki:
https://github.com/basecamp/pow/wiki/Troubleshooting

To uninstall Pow, `curl get.pow.cx/uninstall.sh | sh`

Class ‘foo’ has no initializers

Quick post. It’s been a while. I’m just starting out with Swift, and this error kept coming up for me, but the error message could be a little more descriptive. It means that you have a non-optional member variable that needs to be initialized somehow.

class Foo: NSObject {
  var bar: String
}

That block will fail, saying Class 'Foo' has no initalizers. It isn’t that you need an init custructor, it’s that other things will depend on bar being set, and Swift doesn’t know what value to give it. This can be fixed by making bar optional, and anything using bar will have to handle the case where it’s missing

class Foo: NSObject {
  var bar: String?
}

or by giving it an initial value, so anything using it will either get its value, or (in this case) an empty string

class Foo: NSObject {
  var bar: String = ""
}

Configure MySQL on AWS t2.micro Linux AMI

I moved my blog over to an AWS VM, because I get 12 months of a free t2.micro instance. Can’t beat free hosting for a year, right? And about $10/month after that, on my own private virtual machine. Assumed things were going well, but I came back a few weeks later to find everything had gone to hell. WordPress was not connecting to the database.

[philihp@philihp.com ~]$ sudo service mysqld start
Starting mysqld:                                           [FAILED]

In looking at my /var/log/mysqld.log file, I found

160120 21:49:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160120 21:49:58 [Note] /usr/libexec/mysql55/mysqld (mysqld 5.5.46) starting as process 27540 ...
160120 21:49:58 [Note] Plugin 'FEDERATED' is disabled.
160120 21:49:58 InnoDB: The InnoDB memory heap is disabled
160120 21:49:58 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160120 21:49:58 InnoDB: Compressed tables use zlib 1.2.8
160120 21:49:58 InnoDB: Using Linux native AIO
160120 21:49:58 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
160120 21:49:58 InnoDB: Completed initialization of buffer pool
160120 21:49:58 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160120 21:49:58 [ERROR] Plugin 'InnoDB' init function returned error.
160120 21:49:58 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160120 21:49:58 [ERROR] Unknown/unsupported storage engine: InnoDB
160120 21:49:58 [ERROR] Aborting
160120 21:49:58 [Note] /usr/libexec/mysql55/mysqld: Shutdown complete

The important thing here is InnoDB: mmap(137363456 bytes) failed; errno 12.

It looks like it couldn’t allocate the memory, which makes sense because a t2.micro instance only has a gig of RAM. Ought to be enough for anyone, right? Not for MySQL! The way to fix this is to open up your /etc/my.cnf file, and add a param innodb_buffer_pool_size = 1M (something reasonable). If you haven’t made any other changes, it should look similar to this:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

innodb_buffer_pool_size = 1M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Now if you start MySQL back up, everything should be fine.

[philihp@philihp.com ~]$ sudo service mysqld start
Starting mysqld:                                           [  OK  ]

Using Java 8 Lambdas with Google Guava Caches

With Guava, you can define a simple in-memory cache with

import static java.util.concurrent.TimeUnit.DAYS;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

Cache cache =
    CacheBuilder.newBuilder()
        .maximumSize(100000)
        .expireAfterAccess(7, DAYS)
        .build();

With this you can use .put(K, V) to load values, and .getIfPresent(K), which returns null if the key isn’t present. Sometimes it’s more convenientĀ to use get(K key, Callable<? extends V> valueLoader), where the valueLoader is called on a cache miss, and populates the cache and gives you what a cache hit would have given you. The old Java 7 way of doing this was really ugly:

cache.get(key, new Callable() {
    @Override
    public V call() {
        return calculatedValue(key);
    }
});

Don’t write ugly code. With Java 8 Lambdas, just do this:

cache.get(key, () -> {
    calculatedValue(key);
}

How to parameterize an RSpec shared context

I had a RSpec shared_context which was creating a FactoryGirl user mock and then logging in with it, and then running some shared examples for testing permissions on a generic user. I needed to modify it to accept a parameter of using a different user.

It originally looked like this:

RSpec.shared_context "auth" do
  let(:current_user) { FactoryGirl.create(:user) }

  before(:each) do
    allow(User).to receive(:find_by_id)
    allow(User).to receive(:find_by_id).with(current_user.id) { current_user }
  end

  shared_context "logged in" do
    before(:each) do
      login_as current_user
    end
  end
end

In my spec files, it was included by doing this:

describe MyController do
  include_context 'auth'

  context "when logged in as a normal user" do
    include_context 'logged in'

    ...
  end
end

However I needed MyController to override current_user and use an admin user instead. Rather conveniently, you can override a context by sending it a block.

describe MyController do
  include_context 'auth'

  context "when logged in as an admin" do
    include_context 'logged in' do
      let(:current_user) { FactoryGirl.create(:admin) }
    end

    ...
  end
end

This works because the let inside of the block given is called again, and the new block calls let(:current_user) again and overrides the original block and FactoryGirl.create(:user) is never called.

This is documented here, however they don’t really show that it can be used for making your shared_context parameterized. So I’m going to say the word parameterized a lot here, and hope that when I (or you!) google “How do I parameterize an RSpec shared_context?”, you find this post.

Weblabora, Sailing, and Portland

Hi friends. I’ve been learning a lot of things recently, but nothing cool enough to be worth an entire blog post of its own, so here they are.

Weblabora

I’ve been resurrecting Weblabora recently by abstracting out the game logic into a JAR and rewriting the front-end with more modern technology. The front-end is also open source on Github and will be hosted at Kennerspiel.com. Not much to see right now, but I am making slow and steady progress. The idea, this time, is to make it so that more games can be added relatively easily.

A JAR of the game library is published to Maven repositories is the first JAR I’ve published under the com.philihp group http://maven-repository.com/artifact/com.philihp/weblabora.

Sailing

Lately I’ve been learning how to sail. The other day in practicing man-over-board drills in a J/24 we spotted a watermelon floating in San Francisco Bay. We rescued it and ate it for lunch.

Baymelon

Portland

For the second half of 2015 I will be living in Portland, Oregon. That’s about all there is to say about that.

How to use JUnit4 Hamcrest Matchers

JUnit borrows matchers from a library called Hamcrest, which look a lot like RSpec matchers in Ruby. They can be tricky to write, but end up being much more readable for complex assertions. At its simplest case, we can turn this assertion

assertTrue(board.isGameOver());

into

assertThat(board.isGameOver(), is(true));

It’s slightly wordier, but I think it reads in English a little better, and is capable of still-readable more-complex assertions. The is() function here isn’t from extending TestCase (JUnit 4 no longer needs this, that was a JUnit 3 thing). It’s actually a static import, although there seems to be conflicting information on the internet on what needs to be imported. I found these to work in most cases:

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

From what I can tell, JUnit pulled in some, but not all of the matchers from Hamcrest. There are still some useful matchers in Hamcrest, so I like to import them, and there aren’t any namespace collisions. It doesn’t add any additional lines to your POM since you can actually leave out the JUnit dependency and just import the Hamcrest library (since it itself depends on JUnit).


  org.hamcrest
  hamcrest-all
  1.3
  test

In the actual test that motivated this post, I had a really specific need to test that a method would return a list which contained at any index a POJO bean which had properties for settlement being an instance of a Village class and score being 42. I was able to express this as

assertThat(
      settlementScoresList,
      hasItem(allOf(
          hasProperty("settlement", instanceOf(Village.class)),
          hasProperty("score", is(42)))));

New City, New Job, New Format

I have relocated to San Francisco, and I now work at Airbnb as a Software Engineer.

Unfortunately, this blog will probably not see many more SAS-related posts until I can get my hands on a license. It will probably see a lot of new blog posts with newer, freer technologies. I’m learning a lot of Ruby and Rails, so expect some cool stuff on that front.

Also, I’ll probably drop more F-bombs.

Using SUBSTR on the left of an assignment in SAS

This is a pretty cool feature, and as far as I know it’s unique to SAS and Perl. In SAS, you can have a substr to the left of an assignment.

stringDate='29MAR1984';
substr(stringDate,3,3)='FEB';

This avoids potentially awkward situations like this:

stringDate='29MAR1984';
stringDate=substr(stringDate,1,2)||'FEB'||substr(stringDate,6,4);

The bounds don’t have to be static. Lets suppose we have a dataset with 1 row per letter, and we want to combine those letters into a word.

data have;
    input letter $1.;
    datalines;
h
e
l
l
o
;
run;

My initial thought was to just retain and append each letter:

data want;
  length word $200;
  retain word;
  set have nobs=nobs;
  call cats(word,letter);
  if(nobs=_n_) then output;
run;

However this breaks if one of the letters is a space, and SAS treats the space as null, so appending a space has no effect on the string. Instead of appending, just stick the letter where it’s supposed to be.

data want;
  length word $200;
  retain word ' ';
  set have nobs=nobs;
  substr(word,_n_,1) = letter;
  if(_n_==nobs) then output;
run;