Skip to content

Instantly share code, notes, and snippets.

View tsnow's full-sized avatar

Tim Snowhite tsnow

  • Palantir
  • Washington, DC
View GitHub Profile
@tsnow
tsnow / alter_ego_spec.rb
Created October 18, 2010 23:05
The Spec of the Alter-Ego gem
#alter-ego.rubyforge.org
require 'ostruct'
require File.expand_path('spec_helper', File.dirname(__FILE__))
# let's define a traffic light class with three states: proceed, caution, and
# stop. We'll leave the DSL for later, and use old-school class definitions to
# start out.
class TrafficLightWithClassicStates
include AlterEgo
@tsnow
tsnow / goseetell.sql
Created October 20, 2010 18:18
Trying to find the siteids for place searching
--EXISTING SQL FOR SPHINX
SELECT SQL_NO_CACHE
`places`.`id` * 2 + 1 AS `id` ,
`places`.`name` AS `name`,
`places`.`address` AS `address`,
`places`.`city` AS `city`,
`places`.`description` AS `description`,
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`body`, '0') SEPARATOR ' ') AS `body`,
GROUP_CONCAT(DISTINCT IFNULL(`reviews`.`title`, '0') SEPARATOR ' ') AS `title`,
GROUP_CONCAT(DISTINCT IFNULL(`tags`.`name`, '0') SEPARATOR ' ') AS `tags`,
ruby-1.8.7-p302 > e = Ebates.first
ruby-1.8.7-p302 > first = e.current_protos.select{|i| i.rname =~ /shoe/i}[0]
"ShoeMall" "http://www.ebates.com/stores/shoemall.com.htm", cb: "8.0% "
ruby-1.8.7-p302 > dup = e.current_protos.select{|i| i.rname =~ /shoe/i}[11]
"ShoeMall" "http://www.ebates.com/stores/shoemall.com.htm", cb: "8.0% "
ruby-1.8.7-p302 > first.process
##The original processing done by this protoperk. (From rbs_hrz.sql)
ruby-1.8.7-p302 > puts ProtoPerk.find(324076).stdout
ICE.com - After Christmas Sale - Save an additional 20% at Ice.com (2011-01-17) {187391}
finding 0 locations for ICE.com - After Christmas Sale - Save an additional 20% at Ice.com (2011-01-17) {187391} (324076)
Processing tbds: christmas sale
locs benefit applies_to type reward_fixed dollars_off min_overall reward_var free_shipping per_n_dollars store_id reward_multi free_gift unrestricted min_dollars program_id reduced_shipping percent_off
updated: Coupon(249980,289207,315750)
Status: updated
# Note the:
@tsnow
tsnow / users_controller_test.rb
Created April 15, 2011 17:50
A controller test example
We couldn’t find that file to show.
@tsnow
tsnow / .gitignore
Created May 20, 2011 23:43
For stackoverflow Q#4955355
db
@tsnow
tsnow / README.mkdown
Created June 8, 2011 20:34
For stackoverflow Q#6267059
@tsnow
tsnow / notes.mk
Created June 8, 2011 21:43
Mapping RRV/SemVer to test structure for auto~versioning
# Mapping RRV to Tests:
1. Patch releases (3.2.1) should only include bug fixes and internal implementation changes.
test/bugs/ can change
test/internal/ can change
2. Minor releases (3.2.0) can include bug fixes, internal changes, and new features, but no breaking changes.
test/feature_stories/ can be added to
#!/bin/bash
# System-wide crontab file and cron job directory. Change these for your system.
CRONTAB='/etc/crontab'
CRONDIR='/etc/cron.d'
# Single tab character. Annoyingly necessary.
tab=$(echo -en "\t")
# Given a stream of crontab lines, exclude non-cron job lines, replace
>> x = (1..10000000).to_a; x.length
=> 10000000
>>
?> by_reverse = Proc.new{|p,o| Proc.new{|a,b| b.send(p,o) <=> a.send(p,o)}}
=> #<Proc:0x000000013b68a330@(irb):50>
>> Benchmark.bm do |y|
?> y.report("sort_by neg") { x.sort_by{|i| - (i + 1)} }
>> y.report("sort no_send") { x.sort{|a,b| (b + 1) <=> (a + 1)} }
>> y.report("sort send") { x.sort{|a,b| b.send('+', 1) <=> a.send('+', 1)}}
>> y.report('procs send') { x.sort(&(by_reverse.call('+',1))) }