Skip to content

Instantly share code, notes, and snippets.

def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
value
end
block.call(result,key,value)
result
}
@iangreenleaf
iangreenleaf / rsync-retry.sh
Created January 18, 2010 07:12
rsync with retries
#!/bin/bash
### ABOUT
### Runs rsync, retrying on errors up to a maximum number of tries.
### Simply edit the rsync line in the script to whatever parameters you need.
# Trap interrupts and exit instead of continuing the loop
trap "echo Exited!; exit;" SIGINT SIGTERM
MAX_RETRIES=50
@codekitchen
codekitchen / Object#vdiff method for ruby
Created January 19, 2011 16:16
view a diff of two ruby objects using pp and your difftool
$vdiff_difftool = 'ksdiff'
require 'pp'
class Object
def vdiff(other)
require 'tempfile'
t1 = Tempfile.new(['vdiff', '.rb'])
t2 = Tempfile.new(['vdiff', '.rb'])
PP.pp self, t1
PP.pp other, t2
@jharjono
jharjono / sinatra_sass_coffee.rb
Created March 7, 2011 19:12
a setup of Sinatra using Slim for HTML, Sass for CSS, and CoffeeScript for JavaScript
#!/usr/bin/env ruby
# Libraries:::::::::::::::::::::::::::::::::::::::::::::::::::::::
require 'rubygems'
require 'sinatra/base'
require 'slim'
require 'sass'
require 'coffee-script'
# Application:::::::::::::::::::::::::::::::::::::::::::::::::::
@avdi
avdi / deep_fetch.rb
Created June 28, 2011 19:28
Deep Fetch
module DeepFetch
def deep_fetch(*keys, &fetch_default)
throw_fetch_default = fetch_default && lambda {|key, coll|
args = [key, coll]
# only provide extra block args if requested
args = args.slice(0, fetch_default.arity) if fetch_default.arity >= 0
# If we need the default, we need to stop processing the loop immediately
throw :df_value, fetch_default.call(*args)
}
catch(:df_value){
@bentruyman
bentruyman / Custom.css
Created August 17, 2011 00:30
IR_Black Theme for Chrome Developer Tools
/**********************************************/
/*
/* IR_Black Skin by Ben Truyman - 2011
/*
/* Based on Todd Werth's IR_Black:
/* http://blog.toddwerth.com/entries/2
/*
/* Inspired by Darcy Clarke's blog post:
/* http://darcyclarke.me/design/skin-your-chrome-inspector/
/*
@makevoid
makevoid / Gemfile
Created September 12, 2011 02:59
Rails 3.1 Gemfile with DataMapper, RSpec, Haml, Sass, CoffeeScript and Thin (in dev)
source 'http://rubygems.org'
gem 'activesupport', :require => 'active_support'
gem 'actionpack', :require => 'action_pack'
gem 'actionmailer', :require => 'action_mailer'
gem 'railties', :require => 'rails'
gem 'mysql2'
DM_VERSION = '~> 1.2.0.rc1'
@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@acook
acook / ruby_dev_machine_setup.sh
Last active September 28, 2015 13:18
Simple setup script for a ruby environment on Ubuntu server.
#!/usr/bin/env/bash
# run this like: `curl https://gist.github.com/acook/1444793/raw/ruby_dev_machine_setup.sh | bash`
echo "Enter password to install packages..."
sudo apt-get update
sudo apt-get install -y build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libtool ack-grep vim-nox ctags
\curl -#L https://get.rvm.io | bash -s stable --ruby
source ~/.bashrc
@dpiponi
dpiponi / example.cu
Created December 20, 2011 17:36
Minimal CUDA example (with helpful comments).
#include <stdio.h>
//
// Nearly minimal CUDA example.
// Compile with:
//
// nvcc -o example example.cu
//
#define N 1000