Author Archives: Philihp

Removing the First Instance of an Element from a ES6 JavaScript Array

To build upon Marius Schulz‘s approaches to removing from an array, if you want to remove the first instance of an element in an array, and you don’t want to mutate it but instead return a new array (because perhaps you want your React components to update), use a slice. function removeFirst(src, element) { const […]

Prefer `if object.present?` over `if object`

So you’ve got a controller method class DressesController < ApplicationController def show @dress = Dress.find_by(params.permit(:id)) end end And a view <div class=”<%= dress ? ‘dress&.status’ : ” %>”>Status Indicator</div> Looks good! Works great! Now your app grows, and you have a lot of other views that use the dress. Long after your view has been […]

R2: The Infinite Composer

For the San Francisco Stupid Hackathon, I wrote a program that would convert your keystrokes and mouse clicks into random tones. It was inspired by nbeep, and I wrote it in a few hours having absolutely no idea what I was doing beforehand. It turns out, macOS programming is a lot like iOS. Neat! It […]

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 […]

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 | sh % Total % Received % Xferd Average Speed Time […]

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 […]

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 […]

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; import; 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> […]

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) { […]

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 […]