Skip to content

Instantly share code, notes, and snippets.

@pjkelly
pjkelly / calculate-construction-cost.md
Created March 8, 2012 00:38
Calculating Time and Cost of Building Floors in Tiny Tower

Calculating Construction Cost

According to the Tiny Tower Wiki the equation for calculating how much it costs to build a given floor is:

cost = 150 × floor_number 2

A simple way to evaluate this equation in Ruby would be:

@pjkelly
pjkelly / setup-vmware-image-with-static-IP.markdown
Created July 7, 2011 01:06
VMWare Fusion Images with a static IP Address on Mac OS X Snow Leopard

How to setup your VMWare Fusion images to use static IP addresses on Mac OS X

At Crush + Lovely, we use Railsmachine's Moonshine to automate the configuration of our servers. When writing our deployment recipes, VMWare Fusion's ability to take snapshots and rollback to these snapshots is a huge timesaver because it takes just seconds to roll a server image to it's original state.

When you're just configuring a single server, having a static IP address for your server image isn't too important, but when you're configuring multi-server setups, it can be useful to duplicate a number of server images and give each a static IP address so you can consistently deploy to them. While not documented well at all, it turns out that this is relatively easy to accomplish in four simple steps.

1. Determine the MAC address of your guest machine

Let's say you have a guest machine with the name ubuntu-lucid-lynx-base a

@pjkelly
pjkelly / PgError.md
Last active February 8, 2023 04:49
PG gem error after PostgreSQL upgrade.

When upgrading PostgreSQL on your machine, previously installed versions of the pg Rubygem will complain because their native extensions were compiled against an older version of Postgres. The error will look like this:

[daley (qa)]$ be rake db:create
rake aborted!
LoadError: dlopen(/opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle, 9): Library not loaded: /opt/boxen/homebrew/lib/libpq.5.5.dylib
  Referenced from: /opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle
  Reason: image not found - /opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle
/Users/pjkelly/src/daley/config/application.rb:7:in `<top (required)>'
@pjkelly
pjkelly / s3-file-sharing.md
Created September 3, 2014 18:15
Setting up an Amazon S3 bucket to share files.

Setting up an Amazon S3 bucket to share files

  1. Sign into your AWS console: https://console.aws.amazon.com/console/home
  2. Click on “S3”.
  3. Click “Create Bucket” and enter a Bucket Name using only alphanumeric characters and no spaces. We recommend prefixing it with your organization’s name, so something like “myorganization-downloads” works well. No other customization is necessary, so then click “Create” to complete the creation process.
  4. Choose the bucket you just created from the list of buckets to navigate into it.
  5. Once inside the folder, click “Upload” and upload all the files you want there.
  6. After your files are done uploading, select them by clicking the square to their left and then choose “Actions” -> “Make Public”. This will make the files publicly accessible.
  7. To get the public URL of a file, select the file and then click the Properties tab (in the top right of the window). The Link attribute contains the publicly accessible URL of the file.
@pjkelly
pjkelly / 1-How-We-Build-JSON-APIs-in-Rails.md
Last active April 25, 2022 10:19
Crush + Lovely Blog Posts

How We Build JSON APIs in Rails

Over the past few years, we've seen the projects we work on go from occasionally to almost always requiring a REST API. There are several reasons for this, all of them necessitating our ability to construct clean, performant APIs that are easy to work with:

  • More than ever, we are using client-side applications to provide rich, responsive interfaces.
  • The products we build span multiple platforms (web, iOS, Android, Blackberry) that all need to be kept in sync.
  • People and organizations have accumulated large amounts of data, and they need to have that data aggregated and/or sanitized so it can be used in new ways.

As a Ruby shop, we've always had a wide array of tools and libraries to choose from when building our applications. While this is most definitely a good problem to have, it's still a problem, and finding a combination of tools that made API development feel right to us took a few tries.

@pjkelly
pjkelly / serverless.yml
Last active December 16, 2021 19:59
Cloudformation Template for Public/Private VPC - Used to create peering connection between Lambda VPC and MongoDB Atlas, also allows public outbound traffic.
service: project-vpc
variablesResolutionMode: 20210326
# Concepts From:
# https://raw.githubusercontent.com/awsdocs/aws-lambda-developer-guide/main/templates/vpc-privatepublic.yaml
# https://datachef.co/blog/aws-vpc-with-public-and-private-subnets/
# https://ordina-jworks.github.io/cloud/2020/02/19/Combining-MongoDB-and-AWS-Lambda.html#vpc-peering-connect-your-lambda-functions-with-your-mongodb-atlas-cluster
custom:
stage: ${opt:stage}
@pjkelly
pjkelly / install-phantomjs.md
Last active January 27, 2020 21:30
Installing PhantomJS

Installing PhantomJS via Homebrew and fixing Ruby if it breaks

PhantomJS is an awesome tool for doing automated, full-stack acceptance tests in a headless browser. It's a great alternative to capybara-webkit because it doesn't depend on QT or xvfb, and it's way better than Selenium in most cases because it's faster (you don't need to open Firefox to run your tests).

Unfortunately, installing PhantomJS via Homebrew can wreak havoc on your Rubies if you're using rbenv. These are the steps that worked for me in fixing my Ruby installations.

# Update Homebrew
brew update
# Install PhantomJS
@pjkelly
pjkelly / serverless.yml
Created December 14, 2019 00:46
Serverless / LocalStack - DynamoDB Table
service: my-service
frameworkVersion: ">=1.45.0 <2.0.0"
plugins:
- serverless-localstack
- serverless-deployment-bucket
custom:
stage: ${opt:stage}
@pjkelly
pjkelly / Readme.md
Created April 12, 2013 15:44
GitHub Flow: Keeping Feature Branches Up-to-Date & Merging Work Back Into Master

Keeping Feature Branches Up-to-Date & Merging Work Back Into Master

The basic flow is this:

  • When you want to update a feature branch you're working on, rebase on to it.
  • When you're ready to integrate the work you've been doing into the master branch, merge it.

Detailed Step-by-Step

Given the name of your feature branch is registration-page:

Keybase proof

I hereby claim:

  • I am pjkelly on github.
  • I am pjkelly (https://keybase.io/pjkelly) on keybase.
  • I have a public key ASABfS-Igq-O3-uBbvoG2rvBftrNakjRot4KsqS4OFf4oAo

To claim this, I am signing this object: