Skip to content

Instantly share code, notes, and snippets.

View matpalm's full-sized avatar
🎯
Focusing

mat kelcey matpalm

🎯
Focusing
View GitHub Profile
-module(median).
-export([from_file/1,from_list/1]).
from_file(File) ->
io:format("~w\n",[from_list(parse_file:to_list(File))]),
init:stop().
from_list(List) ->
nth_order_stat(round(length(List)/2), List).
# process files one at time, NUM_CPUS in parallel
@postcodes = `ls resem_per_postcode`.collect{|l| l.chomp}
def fork_for_next_postcode
postcode = @postcodes.shift
fork { run "cat resem_per_postcode/#{postcode} | ./connected_components.rb > result_per_postcode/#{postcode}" }
end
NUM_CPUS.times { fork_for_next_postcode }
while not @postcodes.empty?
Process.wait
fork_for_next_postcode
#!/usr/bin/env ruby
def emit tuple
puts "LongValueSum:#{tuple.join(' ')}\t1"
end
NGRAM_SIZE = 3
STDIN.each do |line|
terms = line.downcase.gsub(/\'/,'').gsub(/[^a-z0-9]/,' ').chomp.strip.split
next if terms.size < NGRAM_SIZE
#!/usr/bin/env ruby
STDIN.each do |line|
terms = line.downcase.gsub(/\'/,'').gsub(/[^a-z0-9]/,' ').chomp.strip.split
terms.each { |term| puts "LongValueSum:#{term}\t1" }
end
$ rails -v
Rails 3.0.0.beta
$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0.beta)
actionpack (3.0.0.beta)
activemodel (3.0.0.beta)
rvm install 1.9.1
rvm 1.9.1 --default
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rack-mount --version=0.4.0
gem install rails --pre
gem install webrat
gem install sqlite3-ruby
gem install rspec-rails --pre
script/rails g rspec:install
#!/usr/bin/env ruby
Graph = Struct.new :v, :gid, :pgid, :row, :height
CAUSE_WEIRD_BEHAVIOUR = true
class Dendrogramer
def initialize inputs
calculate_graphs_for inputs
end
@matpalm
matpalm / gist:442001
Created June 17, 2010 11:42
split and xargs eg
# ps. writing this from my head so there is probably a few errors
# calculate total number of lines across the files
TOTAL_LINES=`cat *.json | wc -l`
# calculate what 1/4 would be (for a quad core box)
let SPLIT_SIZE=$TOTAL_LINES/4
# split the original input into files of this size, can end up with 5 files due
# to rounding of /4 but doesnt matter too much
10 print "i can haz code!"
20 goto 10
mat@ubishop:~/qwe$ cat test.input
blah de blah
cat goal dog
dum dum dum
mat@ubishop:~/qwe$ cat terms_in_lines_with_goal.rb
#!/usr/bin/env ruby
# if a line has 'goal' in it, write each term to a seperate line
STDIN.each do |line|
next unless line =~ /goal/