Skip to content

Instantly share code, notes, and snippets.

View akahn's full-sized avatar

Alex Kahn akahn

View GitHub Profile
#while true; end
file = File.new('/Users/akahn/out', 'w')
loop do
begin
buf = ""
buf << STDIN.read_nonblock(1024)
if buf =~ /^.*?\n/
file.write_nonblock(buf)
end
Thor::Actions::CreateFile
#invoke!
creates a file
does not create a file if pretending
shows created status to the user
does not show any information if log status is false
returns the given destination
converts encoded instructions
when file exists
class ActiveRecord::NamedScope::Scope
def values_for(column)
sql = self.scoped(:select => column).construct_finder_sql({})
connection.select_values(sql)
end
end
>> nice
NameError: undefined local variable or method `nice' for main:Object
>> if false
>> nice = "yep"
>> end
=> nil
>> nice
=> nil
@akahn
akahn / Euler1.hs
Created October 4, 2011 02:18
Some Project Euler solutions in Haskell
-- Calculate the sum of all multiples of 3 or 5 under 1000
-- http://projecteuler.net/problem=1
import Control.Monad(guard)
multipleOf3 x = x `mod` 3 == 0
multipleOf5 x = x `mod` 5 == 0
multipleOfEither x = multipleOf3 x || multipleOf5 x
-- Using the list monad:
" Edit a file in the current directory
set wildcharm=<C-Z>
noremap <Leader>e :e %:h<C-Z>
Process: WebProcess [39316]
Path: /System/Library/PrivateFrameworks/WebKit2.framework/WebProcess.app/Contents/MacOS/WebProcess
Identifier: com.apple.WebProcess
Version: 6534 (6534.50)
Build Info: WebKit2-75345000~2
Code Type: X86-64 (Native)
Parent Process: Safari [39286]
Date/Time: 2011-08-12 17:31:45.431 -0400
OS Version: Mac OS X 10.6.8 (10K549)
class BusLineName
attr_reader :boro, :number
def initialize(boro, number)
@boro = boro
@number = number
end
def to_s
case boro
var moodpics = {"32":"http://l-stat.livejournal.com/img/mood/os/triangles/touched.gif","127":"http://l-stat.livejournal.com/img/mood/os/triangles/distressed.gif","90":"http://l-stat.livejournal.com/img/mood/os/triangles/accomplished.gif","118":"http://l-stat.livejournal.com/img/mood/os/triangles/predatory.gif","71":"http://l-stat.livejournal.com/img/mood/os/triangles/pessimistic.gif","102":"http://l-stat.livejournal.com/img/mood/os/triangles/nerdy.gif","18":"http://l-stat.livejournal.com/img/mood/os/triangles/hungry.gif","125":"http://l-stat.livejournal.com/img/mood/os/triangles/cheerful.gif","16":"http://l-stat.livejournal.com/img/mood/os/triangles/high.gif","44":"http://l-stat.livejournal.com/img/mood/os/triangles/amused.gif","55":"http://l-stat.livejournal.com/img/mood/os/triangles/disappointed.gif","27":"http://l-stat.livejournal.com/img/mood/os/triangles/sore.gif","84":"http://l-stat.livejournal.com/img/mood/os/triangles/cold.gif","57":"http://l-stat.livejournal.com/img/mood/os/tr
@akahn
akahn / output
Created July 9, 2011 00:33 — forked from bkeepers/output
$ ruby serialization.rb
Sizes:
marshal: 55
msgpack: 35
json: 46
Rehearsal -----------------------------------------------------
marshal 1.590000 0.050000 1.640000 ( 1.647142)
json 1.890000 0.200000 2.090000 ( 2.091030)
marshal with yajl 1.590000 0.030000 1.620000 ( 1.624589)
json with yajl 1.860000 0.060000 1.920000 ( 1.926875)