Skip to content

Instantly share code, notes, and snippets.

View seamusabshere's full-sized avatar

Seamus Abshere seamusabshere

View GitHub Profile
@seamusabshere
seamusabshere / .gitignore
Created March 2, 2012 19:36 — forked from holman/gemspec-usage.md
brighter planet api gem (aka "carbon") - flattened
Gemfile.lock
.DS_Store
.rvmrc
.yardoc/
doc/
*.gem
@seamusabshere
seamusabshere / foo.txt
Created March 1, 2012 15:59
good point from bkutil about unix_utils's sha256 example...
On Thu, Mar 1, 2012, at 02:49 PM, Balazs Kutil wrote:
>I'd have one question though. Is there some specific reason behind not using
> $ Digest::SHA256.file("big.file").hexdigest
>in the SHA example in readme / in the code? It seems to do exactly the same as the second code snippet, while keeping the memory footprint low...
hi Balazs,
@seamusabshere
seamusabshere / cbecs.rb
Created February 9, 2012 23:44
fuzzy_inference_machine interface
require 'fuzzy_inference_machine'
class CBECS < ActiveRecord::Base
fuzzy_inference_machine :infers => [:electricity_per_room_night, :fossil_fuels_per_room_night], # list of columns that this model is designed to infer
:basis => [:rooms, :year, :hdd, :cdd, :floors, :ac], # list of columns that are believed to affect energy use (aka MU)
:sigma => "(STDDEV(:column)/5)+(ABS(AVERAGE(:column)-:value)/3)", # empirically determined formula (SQL!) that captures the desired sample size once all the weights are compiled, across the full range of possible mu values
:membership => :energy_use_membership, # name of instance method to be called on kernel
:weight => :cbecs_weighting # (optional) a pre-existing row weighting, if any, provided by the dataset authors
# empirically determined formul
@seamusabshere
seamusabshere / 1.crash.txt
Created February 8, 2012 19:13
successive runs of jlecour's amatch stress test
Process: ruby [5706]
Path: /Users/seamusabshere/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Identifier: ruby
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: bash [2964]
Date/Time: 2012-02-08 13:08:47.373 -0600
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
@seamusabshere
seamusabshere / results.txt
Created October 20, 2011 15:26
EM.spawn makes initial connect to Goliath server fast in spite of blocking code
# parallel 2
## plain
gargantuan1:~ $ http_load -parallel 2 -fetches 3000 urls.txt
3000 fetches, 2 max parallel, 54000 bytes, in 28.6926 seconds
18 mean bytes/connection
104.557 fetches/sec, 1882.02 bytes/sec
msecs/connect: 0.296469 mean, 9.802 max, 0.04 min
msecs/first-response: 18.8286 mean, 27.964 max, 9.277 min
@seamusabshere
seamusabshere / to_regexp.rb
Created April 18, 2011 22:43
String#to_regexp
#
# DEPRECATED - and probably broken
# use to_regexp gem instead
# https://github.com/seamusabshere/to_regexp
# https://rubygems.org/gems/to_regexp
#
class String
REGEXP_DELIMITERS = {
'%r{' => '}',
@seamusabshere
seamusabshere / remote_table_whitelist.rb
Created April 18, 2011 22:25
how to make a whitelist in remote table
#!/usr/bin/env ruby
require 'rubygems'
require 'remote_table'
# include to_regexp stuff from https://gist.github.com/926425
def manufacturer_whitelist?(candidate)
@manufacturer_whitelist ||= RemoteTable.new(:url => AAAAAAA)
@manufacturer_whitelist.any? { |record| record['Manufacturer'].to_regexp.match(candidate) }
@seamusabshere
seamusabshere / source_location.sh
Created April 18, 2011 18:56
how to get the source location of a method
vidalia:~/cm1 (statistics) $ rails console
Loading development environment (Rails 3.0.6)
ruby-1.9.2-p180 :001 > m = AutomobileTrip.method(:run_data_miner_on_belongs_to_associations)
=> #<Method: AutomobileTrip([...])(ActiveRecord::Base).run_data_miner_on_belongs_to_associations>
ruby-1.9.2-p180 :002 > m.source_location
=> ["/Users/seamus/.rvm/gems/ruby-1.9.2-p180/bundler/gems/earth-3b880b7687ac/lib/earth/active_record_ext.rb", 3]
@seamusabshere
seamusabshere / delayed_job_singleton.rb
Created February 18, 2011 15:38
how we hacked DelayedJob 2.0.3 logs in Rails 3
#!/usr/bin/env ruby
PRESUMPTIVE_RAILS_ROOT = "/data/[APP_NAME]/current"
LOG_PATH = "/data/[APP_NAME]/shared/log/delayed_job_singleton.log"
Dir.chdir PRESUMPTIVE_RAILS_ROOT
require 'home_run'
require "rubygems"
require "bundler/setup"
diff --git a/data_miner_test.rb b/data_miner_test.rb
index 69c9cd5..fca902c 100644
--- a/data_miner_test.rb
+++ b/data_miner_test.rb
@@ -4,12 +4,12 @@ class Shop < ActiveRecord::Base
end
class ItemDetail < ActiveRecord::Base
- set_primary_key :id
+ set_primary_key :row_hash