Skip to content

Instantly share code, notes, and snippets.

@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
@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'
@acook
acook / Install RBenv.bash
Last active September 28, 2015 04:20
The process to get a full working rbenv setup.
export RBENV_ROOT="$HOME/.rbenv"
export RBENV_PLUGINS="$RBENV_ROOT/plugins"
git clone https://github.com/sstephenson/rbenv.git "$RBENV_ROOT"
export PATH="$RBENV_ROOT/bin:$PATH"
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> ~/.bash_profile
eval "$(rbenv init -)"
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
@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
module PubSub
class << self
def create type, channel, object
channel = channel.to_sym
case type
when :listener
listeners[channel] ||= Array.new
listeners[channel] << object
channels[channel] ||= Array.new
@acook
acook / ubuntu_server_setup.bash
Last active December 20, 2015 20:48
Ubuntu server setup for Ruby, Nginx, and Node.js.
#!/usr/bin/env/bash
# run this like: `curl https://gist.github.com/acook/6192391/raw/ubuntu_server_setup.bash | bash`
echo "Enter the email address for this server's SSH key: "
read email
mkdir ~/.ssh
ssh-keygen -t rsa -C $email
echo "Enter password to install packages: "
@acook
acook / BinaryDataHandling.markdown
Last active December 23, 2015 10:29
List of gems useful for parsing/generating binary data from Ruby.

Binary Data

It can be challenging to use Ruby for handling raw binary data, involving a lot of Array#pack and String#unpack with the possibility of String#ord and Numeric#chr for good measure. Some of these tools might make the job a bit easier, allowing your to define schemas of the binary data and how to parse it, or even just allowing your to specify the format in a more verbose way.

Gems

BinData

@renato-zannon
renato-zannon / module.rb
Created September 4, 2012 04:07
Subclass module + use module_eval to define methods
class AttributeAccessor < Module
def initialize(name)
@name = name
module_eval { define_accessors }
end
private
def define_accessors
ivar = "@#{@name}"
@msimpson
msimpson / .Xdefaults
Created January 7, 2012 16:57
Darken
urxvt.termName: rxvt
urxvt.loginShell: true
urxvt*urlLauncher: /usr/bin/chromium
urxvt*perl-lib: /usr/lib/urxvt/perl/
urxvt*perl-ext-common: default,matcher,searchable-scrollback
urxvt*font: xft:DejaVu Sans Mono:pixelsize=10
urxvt*boldFont: xft:DejaVu Sans Mono:pixelsize=10
urxvt.scrollBar: false
urxvt.saveLines: 65535
urxvt.secondaryScroll: true
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo