Skip to content

Instantly share code, notes, and snippets.

@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/}
@squarism
squarism / wikipedia.rb
Created November 21, 2011 16:35
Wikipedia mirroring in 10 lines
# we are going to intentionally use the vanilla mongo driver
require 'mongo'
require 'nokogiri'
require 'open-uri'
require 'active_support/core_ext' # from rails
include Mongo
pages = Connection.new('localhost', 27017).db('loadtest').collection('pages')
wikipedia_page = "http://en.wikipedia.org/wiki/Special:Export/Ford_Motor"
@squarism
squarism / bot.rb
Created November 21, 2011 15:41
bot reply test
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require 'chatterbot/dsl'
require 'pokerthing'
exclude "http://" # block spam tweet
blacklist "jerkface, assbutt" # block jerks or self
#debug_mode true
@squarism
squarism / bot.rb
Created November 26, 2011 06:00 — forked from muffinista/bot.rb
bot reply test
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require 'chatterbot/dsl'
require 'pokerthing'
exclude "http://" # block spam tweet
blacklist "jerkface, assbutt" # block jerks or self
#debug_mode true