Skip to content

Instantly share code, notes, and snippets.

Ben Wong spannerinworks

View GitHub Profile
View slug.rb
class Slug
CIPHER = 'RC2'.freeze
def initialize(key, iv)
@key = key
@iv = self.class.hex_to_bytes(iv)
end
def self.generate_iv
bytes_to_hex(OpenSSL::Cipher.new(CIPHER).random_iv)
@spannerinworks
spannerinworks / route-constraints.md
Last active Aug 17, 2017
Route toggling with contraints
View route-constraints.md
module Mode
  class Constraint
    def initialize(mode)
      @mode = mode
    end

    def matches?(_request)
      @mode == Rails.application.config.mode # configured from the environment
    end
View keybase.md

Keybase proof

I hereby claim:

  • I am spannerinworks on github.
  • I am spannerinworks (https://keybase.io/spannerinworks) on keybase.
  • I have a public key whose fingerprint is B78E C80C 409B 7EA3 6E59 7009 AD07 BFEE A1C4 AA4A

To claim this, I am signing this object:

View rspec_hash_with_regex_spec.rb
RSpec.describe 'test' do
it 'works' do
a = {a: 1, b: 'foobar'}
d = double
expect(d).to receive(:meh).with(a: 1, b: match(/ob/))
d.meh(a)
end
end
@spannerinworks
spannerinworks / remigrate_schema.sh
Created Mar 18, 2015
Remigrate test database to create a clean schema.rb. For use during rebasing or when you have a dirty dev DB.
View remigrate_schema.sh
#!/bin/bash
set -v
git show integration:db/schema.rb > db/schema.rb
RAILS_ENV=test rake db:drop
RAILS_ENV=test rake db:create
RAILS_ENV=test rake db:schema:load
RAILS_ENV=test rake db:migrate
View bad_event.rb
require 'ostruct'
id = OpenStruct.new(to_i: 'BAD SQL')
bad_event = OpenStruct.new(id: id)
# > bad_event.id.to_i
# => "BAD SQL"
View bash_profile.sh
export HOMEBREW_GITHUB_API_TOKEN=0123456789abcdef
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="~/scripts:$PATH"
if [ ! -z "$PS1" ] ; then
source ~/scripts/git-prompt.sh
RVM_PROMPT="\[\033[1;36m\]\$(rvm-prompt.sh)\[\033[0m\]"
@spannerinworks
spannerinworks / fullcross.css
Created Oct 22, 2013
Possible fix for uncentred "+" in new collection
View fullcross.css
&:before {
@include border-radius(20px);
color: white;
position: absolute;
background-color: $link-text-colour;
content: "\FF0B";
font-size: 30px;
height: 40px;
width: 40px;
left: 0;
@spannerinworks
spannerinworks / commit-msg
Created Apr 30, 2013
git hook to prepend story number to commit messages
View commit-msg
#!/usr/bin/perl -pi
$branch = `git symbolic-ref HEAD`;
chomp($branch);
$branch =~ s|^refs/heads/(MYC.\d+).*|\1|;
print "[${branch}] " if ($. == 1 && $branch =~ /^MYC.\d+$/);
@spannerinworks
spannerinworks / gist:2789543
Created May 25, 2012
Running a script on heroku and piping input and output
View gist:2789543
Don't expect pretty, it's a hack...
We need and END marker on the input because we have to tell the script to exit
$ cat > input.txt
a quick brown
fox jumple over the
laszy dog
END
$ heroku run "perl -pe 'exit if /^END$/; s/(\w)/\1\1/g;'" < input.txt > output.txt
You can’t perform that action at this time.