Skip to content

Instantly share code, notes, and snippets.

James Chevalier JamesChevalier

Block or report user

Report or block JamesChevalier

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View get_nodes.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'nokogiri'
require 'json'
require 'ap'
# Small script for scraping POIs from JOSM (http://wiki.openstreetmap.org/wiki/JOSM_file_format).
class Parser
# Tags in data that we ignore.
View keybase.md

Keybase proof

I hereby claim:

  • I am jameschevalier on github.
  • I am jameschevalier (https://keybase.io/jameschevalier) on keybase.
  • I have a public key ASAQJByN_kqSZ1GZddqGIXmHZ_yBBo8GelVseYAaPBgEiAo

To claim this, I am signing this object:

@JamesChevalier
JamesChevalier / update_all_docker_images.sh
Created Jan 18, 2017
Update all docker images, ignoring untagged images, and then remove dangling images
View update_all_docker_images.sh
#!/bin/bash
# collect the list of docker images
images=$(docker images --format "{{.Repository}}:{{.Tag}}")
# iterate through each image
for image in $images
do
if [[ $image != *"<none>"* ]]; then
# the image is tagged, so pull the latest version
@JamesChevalier
JamesChevalier / benchmark.rb
Created Dec 14, 2016
Ruby benchmark to compare <<, push, and concat
View benchmark.rb
require 'benchmark'
iterations = 100_000
array_one = []
array_two = []
array_three = []
Benchmark.bmbm do |bm|
bm.report('<<') do
iterations.times do
@JamesChevalier
JamesChevalier / uuid_example.md
Created Nov 8, 2016
Simple example of how to get Rails to use UUID as a primary key as well as with a relation
View uuid_example.md

migration to enable uuid in postgres

class EnableUuidExtension < ActiveRecord::Migration[5.0]
  def change
    enable_extension 'uuid-ossp'
  end
end
@JamesChevalier
JamesChevalier / howto.md
Created Oct 13, 2016
How to create a new EC2 instance from an existing EC2 instance
View howto.md
  • select the existing instance in the Instances list
  • open the Actions menu
  • select Image -> Create Image
  • enter 'Interim AMI' for the Image name
  • enter 'Interim AMI' for the Image description
  • if you cannot accept downtime of the origin instance, check the box for No reboot
    • The No reboot option means that the new image is created without gracefully stopping the machine first.
    • This can be problematic for some things, like a database that's mid-write.
    • If you can handle downtime, don't check the No reboot box.
  • click the Create Image button
@JamesChevalier
JamesChevalier / info.md
Created Oct 7, 2016
Caveat with making strict has_one relations in Rails
View info.md

Let's say you have a User with this relation:

has_one :item

The has_one relation disallows you from doing this:

first_user = User.first
first_user.item.create(field_one: value, field_two: value)
@JamesChevalier
JamesChevalier / NominatimOnEC2.md
Created Sep 21, 2016 — forked from econandrew/NominatimOnEC2.md
Instructions for installing an OpenStreetMap Nominatim geocoder instance on Amazon Linux / EC2 (Dec 2014)
View NominatimOnEC2.md

Installing Nominatim on Amazon Linux / EC2

  1. Introduction

The official instructions for installing Nominatim are complete, but brief in places, and several steps must be changed in the Amazon Linux environment (which is roughly CentOS / Redhat). The steps below are rough record of what I did to get it working, but I didn't keep perfect track so you shouldn't rely on them as a shell script. Just follow each step, make sure it worked, and hopefully you'll need to adapt very little (version numbers, for one thing). (I also skip in and out of root, but you can be more careful if you like.)

  1. Setting up the EC2 instance

@JamesChevalier
JamesChevalier / readme.md
Created Sep 4, 2016
How to set up S3/CloudFront/SSL
View readme.md

Create an SSL Certificate for your website

  • In the Certificate Manager console, click the Request a certificate button
  • Enter the domain name in the field
  • Click the Review and request button
  • Click the button in the email that this request sends you to validate the request

Create the bucket for your website in S3

  • Create a new bucket in s3
@JamesChevalier
JamesChevalier / about.md
Created Jul 28, 2016
Quick description of attr_encrypted
View about.md

attr_encrypted is a nice gem for encrypting fields in Rails.

You add this line to a model: attr_encrypted :field_name, key: ENV['attr_encrypted_key']. I used rake secret to generate that attr_encrypted_key referenced in that line.

The field itself needs to be created in a particular way in the migration:

add_column :table_name, :encrypted_field_name,    :text
add_column :table_name, :encrypted_field_name_iv, :text
You can’t perform that action at this time.