This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devin@predaking:~/projects/web/treeify$ ruby bin/bm_in_query_vs_execute.rb | |
-- drop_table(:nodes) | |
-> 0.0163s | |
-- create_table(:nodes) | |
-> 0.0058s | |
-- add_index(:nodes, [:parent_id, :id], {:unique=>true}) | |
-> 0.0037s | |
user system total real | |
in 0.000000 0.000000 0.000000 ( 0.000090) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Give it two procs to compare | |
def bm(o, n) | |
reload! | |
puts "Running 10 times" | |
Benchmark.bmbm(10) do |x| | |
x.report('Old Query:') { @olr = o.call } | |
x.report('New Query:') { @nr = n.call } | |
end | |
reload! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terms = Hash.new{|h,k|h[k]=h.size} | |
docs = DATA.collect { |line| | |
name = line.match(/^\d+/) | |
words = line.downcase.scan(/[a-z]+/) | |
vector = [] | |
words.each { |word| vector[terms[word]] = 1 } | |
{:name=>name,:vector=>vector} | |
} | |
current = docs.first # or any other | |
docs.sort_by { |doc| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// fibonacci is a function that returns | |
// a function that returns an int. | |
func fibonacci() func(int) int { | |
fib := make([]int, 100) | |
fib[0] = 0 | |
fib[1] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"strings" | |
"code.google.com/p/go-tour/wc" | |
) | |
func WordCount(s string) map[string]int { | |
words := strings.Fields(s) | |
wordCount := make(map[string]int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CarrierWave.configure do |config| | |
#if Rails.env.test? or Rails.env.rspec? | |
# CarrierWave.configure do |config| | |
# config.storage = :file | |
# end | |
#end | |
config.fog_credentials = { | |
:provider => 'AWS', # required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'csv' | |
write_to_file(hit_links) | |
def read_file | |
file = File.open(ARGV[0]).read | |
return file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def grouped_impression_data | |
raw_impression_data | |
@impression_data.group_by {|i| i.first}.each {|k,v| | |
v.each {|val| | |
val.shift | |
} | |
v.flatten | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'roo' | |
require 'csv' | |
require 'mechanize' | |
require 'date' | |
# 1. Read in excel file | |
# 2. Parse and grab columns of data needed | |
# 3. Push into an array of URLs, with an associated campaign id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Thumbnailer | |
* generate a thumbnail of an image | |
* | |
* ==Overview== | |
* {{{ | |
* val thumbnail = new Thumbnailer(.25, "image.jpg", "image-thumbnail.jpg") | |
* val resized = thumbnail.resize() | |
* thumbnail.save() | |
* }}} | |
*/ |