Skip to content

Instantly share code, notes, and snippets.

@squarism
squarism / watchr.rb
Created February 3, 2011 03:28
Watchr config file for ruby programs with growl
# 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
squarism / watchr_rspec.rb
Created February 3, 2011 03:58
A watchr.rb file for use with rspec for continuous ruby (not rails) testing.
# 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
squarism / wtchr
Created February 10, 2011 20:18
A watchr one-liner shell script, perfect for single .rb projects
#!/usr/bin/env bash
# wtchr shell script - @squarism
# INSTALL
# gem install watchr
# cp wtchr ~/bin
# chmod u+x ~/bin/wtchr
# Run with: wtchr foo.rb
@squarism
squarism / python_koans_watchr.rb
Created February 11, 2011 21:37
watchr script for running python 3 koans
# watchr script for running python 3 koans:
# https://github.com/gregmalcolm/python_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
squarism / .irbrc
Created March 17, 2011 15:49
My current .irbrc
begin
# load wirble
require 'rubygems'
require 'wirble'
# start wirble (with color)
Wirble.init
Wirble.colorize
# customize the colors a bit
@squarism
squarism / watchr_rspec.rb
Created March 25, 2011 16:20
Watchr file for use with spork, rails, rspec2 and growl
# 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
squarism / keycodes.rb
Created April 11, 2011 20:38
ruby-processing keyCode for key_pressed
# 38up 39right 40down 37left
def key_pressed
case key_code
when 32
puts 'space'
when 37
puts 'left'
when 38
puts 'up'
@squarism
squarism / mongodb_sharding.txt
Created August 26, 2011 18:36
MongoDB sharded cluster install
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
squarism / ruby_operator.rb
Created September 14, 2011 19:58
perl scalars vs ruby classes
# 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"
begin
if var > 0
puts "yep"
end
@squarism
squarism / rubygems_specs.rb
Created November 9, 2011 21:21
Read rubygems specs file
# 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/}