Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
BUNDLE_BASE=~/ruby/bundle-paths/rails3
if [ -f .bundle/config ]; then
echo "Bundle config file already exists"
bundle install
else
projname=$(basename $(pwd))
BUNDLE_PATH="$BUNDLE_BASE/lib"
#!/bin/bash
for branch in $(git branch --merged | egrep -v '(master)|(staging)|(production)'); do
echo Cleaning: $branch
#If we can delete the branch remotely, delete it locally
git push origin :$branch && git branch -d $branch
done
@nyarly
nyarly / Proposal
Created February 2, 2013 22:39
A Rubygems trust proposal
Here's the basic premises: invent as little cryptography as you can. Make the tools as simple as possible.
Here's the proposal: use PGP for agent authentication, use git for verification distribution.
The kernel of the idea is this: in a public git repo, any user can create file(s) that are a list of tuples of the form:
{domain,object identifier,public identity,signature}
When I release a gem, I sign it, and add
rubygems mygem-x.y.z [email protected] {signature}
@nyarly
nyarly / meta-state.rb
Created December 3, 2012 20:49
Module + metaprogramming based FSM in Ruby
module MetaState
class Error < ::StandardError; end
class WrongStateError < Error; end
class InvalidStateError < Error; end
class Machine
NON_MESSAGES = [:on_exit, :on_enter]
class << self
def add_state(state)
@nyarly
nyarly / fibanocci.rb
Created September 13, 2012 19:36
Enumerable Examples
class Fibonacci
include Enumerable
def initialize
@this = 1
@next = 1
end
@nyarly
nyarly / BM results
Created May 31, 2012 20:18
Dynamic method def: eval strings vs define_method with a block
Adding 1 10x10 times: 100
Adding 1 10x10 times: 100
user system total real
evald 15.760000 0.000000 15.760000 ( 15.772606)
block 15.920000 0.000000 15.920000 ( 15.926385)
user system total real
eval_string 10.070000 0.110000 10.180000 ( 10.184233)
define_with_block 1.120000 0.020000 1.140000 ( 1.143636)
@nyarly
nyarly / bundle_setup
Created May 15, 2012 05:32
Gemsets? Why?
#!/bin/sh
BUNDLE_BASE=~/ruby/bundle-paths/rails3
if [ -f .bundle/config ]; then
echo "Bundle config file already exists"
bundle install
else
projname=$(basename $(pwd))
BUNDLE_PATH="$BUNDLE_BASE/lib"
@nyarly
nyarly / tmux-locate
Created March 23, 2012 00:40
Vim + TMux work
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 <cmd>"
exit 17
fi
session_idx=$(tmux display -p "#S")
window_idx=$(tmux display -p "#I")
pane_idx=$(tmux display -p "#P")
@nyarly
nyarly / gist:1852503
Created February 17, 2012 10:27
Reinventing a wheel? (ActiveRecord)
def self.build_pairs(rel)
require 'pp'
records = connection.select_all(sanitize_sql(rel.to_sql), "#{name} Load Pairs", [])
records.map do |record|
split = record.to_a.map do |key,value|
key.split(".",2) + [value]
end.group_by do |list|
list.first
end.values.map do |record|
instantiate(Hash[record.map{|triple| triple[1..2]}])
@nyarly
nyarly / gist:1792699
Created February 10, 2012 20:41
Change Rake exception handling behavior
Put this at the top of your Rakefile
class Rake::Application
def display_error_message(ex)
$stderr.puts "#{name} aborted!"
$stderr.puts "#{ex.class}: #{ex.message}"
$stderr.puts rakefile_location(ex.backtrace)
$stderr.puts "Tasks: #{ex.chain}" if has_chain?(ex)
$stderr.puts ex.backtrace.join("\n")
end