Skip to content

Instantly share code, notes, and snippets.

squarism / watchr.rb
Created Feb 3, 2011
Watchr config file for ruby programs with growl
View watchr.rb
# run me with watchr watchr.rb in a ruby project
# don't run me in a rails project. :)
# run me with test unit.
# don't run me with rspec or cucumber, check out my other watchr gists
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
squarism / watchr_rspec.rb
Created Feb 3, 2011
A watchr.rb file for use with rspec for continuous ruby (not rails) testing.
View watchr_rspec.rb
# this is a watchr script for command line programs
# not rails. @squarism
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
passed = message.include?('0 failures')
squarism / wtchr
Created Feb 10, 2011
A watchr one-liner shell script, perfect for single .rb projects
View wtchr
#!/usr/bin/env bash
# wtchr shell script - @squarism
# gem install watchr
# cp wtchr ~/bin
# chmod u+x ~/bin/wtchr
# Run with: wtchr foo.rb
squarism / python_koans_watchr.rb
Created Feb 11, 2011
watchr script for running python 3 koans
View python_koans_watchr.rb
# watchr script for running python 3 koans:
# put this in <python_koans_home>/python_koans_watchr.rb
# cd python_3
# watchr ../python_koans_watchr.rb
ENV["WATCHR"] = "1"
system 'clear'
squarism / .irbrc
Created Mar 17, 2011
My current .irbrc
View .irbrc
# load wirble
require 'rubygems'
require 'wirble'
# start wirble (with color)
# customize the colors a bit
squarism / watchr_rspec.rb
Created Mar 25, 2011
Watchr file for use with spork, rails, rspec2 and growl
View watchr_rspec.rb
# sometimes watchr freaks out when you view this file in textmate (hits timestamp?)
# ie: it prints "Watching..." over and over
# just hit Ctrl-\ to run all tests and it calms down
ENV["WATCHR"] = "1"
puts "Watching..."
def growl(result)
result_lines = result.split("\n")
message = result_lines[result_lines.size - 1]
squarism / keycodes.rb
Created Apr 11, 2011
ruby-processing keyCode for key_pressed
View keycodes.rb
# 38up 39right 40down 37left
def key_pressed
case key_code
when 32
puts 'space'
when 37
puts 'left'
when 38
puts 'up'
squarism / mongodb_sharding.txt
Created Aug 26, 2011
MongoDB sharded cluster install
View mongodb_sharding.txt
OS Setup
- Install VMs (base OS = Ubuntu 11.04)
- 6GB disk is not enough. Probably 20-40GB would be good. Mongo has a lot of compression and cleanup features coming.
- Create user to run MongoDB as
- Get DNS or Hosts file set up so all nodes in the cluster can talk to each other
- Generate ssh-keygen -t rsa
- Copy ssh public keys from each node to node01. Then cat all keys to authorized_keys. Then copy that file to each node. Each node will have ssh key trust now. You will also want to ssh from node01 to 02,03,04; from node02 to 01,03,04 etc to test it out.
- Create an initial architecture:
node01: master (replica set 1)
node02: slave (replica set 1)
squarism / ruby_operator.rb
Created Sep 14, 2011
perl scalars vs ruby classes
View ruby_operator.rb
# I agree that Perl probably 'wins' because it just works.
# But consider how you'd make this work and what this means for less
# trivial "save typing" problems.
var = "1"
if var > 0
puts "yep"
squarism / rubygems_specs.rb
Created Nov 9, 2011
Read rubygems specs file
View rubygems_specs.rb
# mirror rubygems somewhere with rubygems-mirror gem or git clone
# this is huge output, so try adding the ;1 at the end to suppress irb output
specs = Marshal.load open '/tmp/rubygems/specs.4.8'; 1
# get a few gems to play with
few_gems = specs[0...10]
some.find_all {|gem| gem[0] =~ /24/}