Skip to content

Instantly share code, notes, and snippets.

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 August 17, 2017 12:03
Route toggling with contraints
module Mode
  class Constraint
    def initialize(mode)
      @mode = mode
    end

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

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:

@spannerinworks
spannerinworks / rspec_hash_with_regex_spec.rb
Created May 7, 2015 15:52
Rspec hash with regex values
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 March 18, 2015 13:48
Remigrate test database to create a clean schema.rb. For use during rebasing or when you have a dirty dev DB.
#!/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
require 'ostruct'
id = OpenStruct.new(to_i: 'BAD SQL')
bad_event = OpenStruct.new(id: id)
# > bad_event.id.to_i
# => "BAD SQL"
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 October 22, 2013 16:06
Possible fix for uncentred "+" in new collection
&: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 April 30, 2013 15:31
git hook to prepend story number to commit messages
#!/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 18:04
Running a script on heroku and piping input and output
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