Skip to content

Instantly share code, notes, and snippets.

View pjb3's full-sized avatar

Paul Barry pjb3

View GitHub Profile
(defn foldr [f acc coll]
(if (first coll)
(f (first coll) (foldr f acc (rest coll)))
[]))
#!/usr/local/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'twitter'
url = "http://apress.com/info/dailydeal"
max_book_title_length = 140 - url.length - 8
if book = Hpricot(open(url)).at('.bookdetails h3 a').inner_html
httpauth = Twitter::HTTPAuth.new('apressdotd', 'too_many_secrets')
function each(f, arr) {
for(var i=0; i < arr.length; i++) {
f.apply(null, [arr[i]])
}
}
function map(f, arr) {
var result = []
each(function(e) {
result.push(f.apply(null, [e]))
Array.prototype.each = function(f) {
for(var i = 0; i < this.length; i++) {
f(this[i])
}
}
Array.prototype.eachWithIndex = function(f) {
var i = 0;
this.each(function(e){
f(e, i++)
Prelude> let numberOfAttendeesToAnyGivenLanguageGroup totalNumberOfAttendeesAtTheFirstMeeting meetingNumber = round $ totalNumberOfAttendeesAtTheFirstMeeting ** (1/meetingNumber)
Prelude> map (numberOfAttendeesToAnyGivenLanguageGroup 16) [1..12]
[16,4,3,2,2,2,1,1,1,1,1,1]
class FooBar
define_method("[GET] /") do
"Apparently Ruby methods can have spaces and other weird characters in their name"
end
end
puts FooBar.new.send("[GET] /")
puts FooBar.instance_methods(false).inspect
def rgb_hex_to_dec(rgb)
if m = rgb.match(/#([a-zA-Z0-9]{2,})([a-zA-Z0-9]{2,})([a-zA-Z0-9]{2,})/)
"%0.2f %0.2f %0.2f" % m.captures.map{|hex| hex.to_i(16) / 255.0}
end
end
namespace :load do
ZIP_CODE_DATA_URL = 'http://www.census.gov/tiger/tms/gazetteer/zips.txt'
# Swiped from ActiveRecord migrations.rb
def announce(message)
length = [0, 75 - message.length].max
puts "== %s %s" % [message, "=" * length]
end
= f.cms_text_field :name
= f.cms_drop_down :handler, ActionView::Template.template_handler_extensions, :default => "haml"
= f.cms_text_area :template, :default_value => @block.class.default_template
class Object
def call
self
end
end
def myif(expr, trueProc, falseProc)
expr ? trueProc.call : falseProc.call
end