This file contains hidden or 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
| (defn foldr [f acc coll] | |
| (if (first coll) | |
| (f (first coll) (foldr f acc (rest coll))) | |
| [])) |
This file contains hidden or 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/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') |
This file contains hidden or 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 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])) |
This file contains hidden or 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
| 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++) |
This file contains hidden or 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
| 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] |
This file contains hidden or 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 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| = 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 |
This file contains hidden or 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 Object | |
| def call | |
| self | |
| end | |
| end | |
| def myif(expr, trueProc, falseProc) | |
| expr ? trueProc.call : falseProc.call | |
| end |