Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'rubygems'
require 'rack'
server = Rack::Handler::Mongrel
app = Rack::ShowExceptions.new(Rack::Lint.new(Rack::File.new(".")))
server.run(app, :Port => 9292)
# Loops are cool I guess...
def fib(num)
return 1 if num == 1
return 1 if num == 2
x = 1
y = 1
a = 0
require 'benchmark'
def loopy_fib(num)
return 1 if num == 1
return 1 if num == 2
x = 1
y = 1
a = 0
require 'test/unit'
# First of all, let's write a test
#
# A new board should be empty
class BoardTest < Test::Unit::TestCase
def test_a_new_board_should_be_empty
board = Board.new
assert_equal(0, board.size)
@jish
jish / compare.js
Created December 3, 2009 18:41 — forked from wycats/compare.js
// prototype
new Ajax.Request("/your/mom", onSuccess: function(response) { $("lightbox_content").innerHTML = response.responseJSON.contents })
new Ajax.Updater("lightbox_content", "/your/mom");
// jquery
$.getJSON("/your/mom", function(json) { $("#lightbox_content").html(json.contents) })
require 'benchmark'
# This takes like forever because '+=' adds seconds, not days.
bm = Benchmark.measure do
next_meeting = Time.now.next_month.beginning_of_month
while next_meeting.strftime("%a") != "Thu"
next_meeting += 1
end
end
bm.real
require 'open-uri'
require 'rubygems'
require 'ri_cal'
ics = open("http://www.google.com/calendar/ical/2skt4ks0v2ka25svaitomsnc60%40group.calendar.google.com/public/basic.ics")
cal = RiCal.parse(ics)
cal.first.events.each do |event|
puts event.start_time
end
gems$ git clone http://github.com/wycats/artifice.git
Initialized empty Git repository in /Users/josh/code/gems/artifice/.git/
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 21 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (21/21), done.
gems$
gems$ cd artifice/
artifice$
artifice$ rake
require 'pp'
class Base
def self.update_all(one, two = nil, three = {})
puts "one:"
pp one
puts "two:"
pp two
require 'benchmark'
n = 1_000_000
Benchmark.bm(7) do |x|
x.report('gsub') { for i in 1..n; 'hello'.gsub('l', ''); end }
x.report('tr') { for i in 1..n; 'hello'.tr('l', ''); end }
x.report('delete') { for i in 1..n; 'hello'.delete('l'); end }
end
# user system total real