Skip to content

Instantly share code, notes, and snippets.

View samaaron's full-sized avatar

Sam Aaron samaaron

View GitHub Profile
_,gggggg,
,d8P"" ""Y .-.
,d8' ( ~ )
d8' `-' __
8P. .8` _ _____ _____/ /_____ ____ ___
`Y8, ,8P'/ | / / _ \/ ___/ __/ __ \/ __ \/ _ \
`Y8b,,__,,d8P' | |/ / __/ / / /_/ /_/ / / / / __/
`"Y8888P"' |___/\___/_/ \__/\____/_/ /_/\___/
build
|-- ChangeLog
|-- Help
| |-- 3vs2
| | |-- Backwards-Compatibility.html
| | |-- SC3vsSC2.html
| | |-- Spawning.html
| | |-- Sync-Async.html
| | |-- SynthDefsVsSynths.html
| | `-- attachments
Graeme has been making a nuisance of himself on the Internet and in various
open source communities since 1992 when he managed to blag a 9k6 modem from
school. However, he didn't discover Ruby until late 2005 when he was frustrated
with Zope (Python's only web framework at the time) and heard about this
thing called Rails.
Graeme was so impressed with Rails (and Ruby) that he quit his day job and
started his own company, Rubaidh, so he could work with it full time. Since
then he's worked with a variety of companies – from tiny startups to
household names – using Ruby to deliver awesome software.
GameOfLife = Origin mimic do(
initialize = method(rows:, columns:,
@grid = Grid withDimensions(rows, columns))
evolve = method(
nextGrid = grid blankGrid
survivingCells = grid filter(live?) filter(numLiveNeighbours in?(2..3))
newCells = grid reject(live?) filter(numLiveNeighbours == 3)
(newCells + survivingCells) each(cellData,
GameOfLife = Origin mimic do(
initialize = method(rows:, columns:,
@grid = Grid withDimensions(rows, columns))
evolve = method(
nextGrid = @grid blankGrid
@grid seq each(cellInfo,
if(#{2,3} include?(cellInfo numLiveNeighbours), nextGrid spawnCell(cellInfo coords first, cellInfo coords second)))
@grid = nextGrid
)
.
|-- README
|-- lib
| |-- iktex
| | `-- translator.ik
| `-- iktex.ik
`-- test
|-- ispec_helper.ik
`-- unit
|-- iktex_spec.ik
List random = method(
"returns a random element from the list",
[System randomNumber % length])
List pick = method(
"picks a random element from the list. If a quantity is specified it returns a list of that size picked randomly which is a subset of the original list. If the specified quantity is greater than the length of the list, the returned list will be padded with nils.",
quantity nil,
if(quantity,
result = list()
counts = method(
files_to_read = FileSystem["**"] reject(name, FileSystem directory?(name))
combined_text = files_to_read map(filename, FileSystem readFully(filename)) join("")
filtered_words = #/\w+/ allMatches(combined_text) map(lower)
filtered_words inject({} withDefault(0), counts, word, counts[word]++. counts)
)
spit = method(outfile, enumerable,
FileSystem withOpenFile(outfile, fn(file, enumerable each(x, file println(x)))))
#!/usr/bin/ruby -wKU
require 'benchmark'
class WordCounter
def initialize(directory)
files_to_count = Dir["#{ARGV[0]}/**"].reject{|name| File.directory?(name)}
@counts = Hash.new(0)
count_words_in_files(files_to_count)
end
#!/usr/bin/ruby -wKU
require 'benchmark'
class WordCounter
def initialize(directory)
files_to_count = Dir["#{ARGV[0]}/**/**"].reject{|name| File.directory?(name)}
@counts = Hash.new(0)
count_words_in_files(files_to_count)
end