This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TimeInterval() { | |
this.seconds = 0; | |
this.addTo = function(ti) { | |
this.seconds += ti.seconds; | |
return this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cron = require('./cron'), sys = require('sys'); | |
cron.Every((2).seconds(), function() { sys.puts('Working!'); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample for http://oliveriskindoffunny.tumblr.com/post/247975858/implementing-a-user-friendly-cron-module-with-node-js | |
var cron = require('./cron'), sys = require('sys'); | |
cron.Every((2).seconds(), function() { sys.puts('Working!'); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
latest_migration = Dir.entries('db/migrate/').select{ |fname| fname =~ /^\d{14}/ }.sort.last | |
exec "$EDITOR db/migrate/#{latest_migration}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if condition | |
result | |
end | |
# result can be any type, condition can be any type; anything that's not false or nil is considered true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require File.join( File.dirname(__FILE__), '..', 'lib', 'carmen_sandiego.rb' ) | |
detective = CarmenSandiego::Detective.new('GeoAPI API Key') | |
results = detective.search do |q| | |
q.radius 500 | |
q.radius_unit :m | |
q.lat 27.93547 | |
q.lng -82.50429 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
au FileType c set ts=4 | |
au FileType c set shiftwidth=4 | |
au FileType ruby set expandtab | |
au FileType ruby set shiftwidth=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Never Again. | |
def link_tree(location, options=nil) | |
return "" unless location | |
options ||= {} | |
max_depth = options[:max_depth] || 5 | |
partial = options[:partial] || "shared/location_subtree" | |
loc_tree = [] | |
max_depth.times do | |
loc_tree << {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def substring(haystack, needle) | |
0.upto(haystack.length) do |i| | |
return i if haystack[i,(needle.length)] == needle | |
end | |
return nil | |
end | |
puts substring("stupid", "smart") | |
puts substring("stupid", "stu") | |
puts substring("stupid", "pid") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cylinder | |
def initialize(r,h) | |
@r = r | |
@h = h | |
end | |
def volume | |
pi * r * r * h | |
end | |
end |
OlderNewer