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
megas@mps:~/Work/wordstat[production]$ RACK_ENV=test rake ar:migrate:reset | |
DEPRECATION WARNING: Yajl::HttpStream is going to be removed in 2.0 | |
== CreateUsers: migrating ==================================================== | |
-- create_table(:users) | |
-> 0.1053s | |
== CreateUsers: migrated (0.1054s) =========================================== | |
== CreateKeywordTrees: migrating ============================================= | |
-- create_table(:keyword_trees) | |
-> 0.0357s |
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
VI | |
#Move: | |
b - back + shift | |
w - word + shift | |
e - end of the word | |
$,0,^ | |
{} - paragraph | |
f - find the word | |
F - find the word backword | |
t, T - find and put the cursor before |
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
Here's my future code |
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
customer = { <id> => { :sex => <sex>, :height => <height>, :age => <age>, :sum => <sum>, :index => <index> } } | |
class Storage | |
def initialize | |
h = Hash.new{|hash,key| hash[key]=[]} | |
@storage = { :sex => h.dup, :height => h.dup, :age => h.dup, :sum => h.dup, :index => h.dup } | |
end | |
def add_customer( expr) | |
# it should return id of customer | |
end | |
def find( search_expr) |
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
class Array | |
def get_max(index,start) | |
index = 2*index + 1 - start | |
self[index] > self[index+1] ? index : index+1 | |
end | |
def heapsort | |
0.upto(length-3) do |start| |
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 bench(repetitions=100, &block) | |
require 'benchmark' | |
Benchmark.bmbm do |b| | |
b.report{ repetitions.times &block } | |
end | |
nil | |
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
class Trie | |
def initilize | |
@trie = Hash.new | |
end | |
def build(str) | |
node = @trie | |
str.each_char do |ch| | |
prev_node = node | |
node = prev_node[ch] = Hash.new unless node[ch] | |
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
ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>8000,:DocumentRoot=>".").start' |
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
a = [{:amount => "500.0", :when => "2012-03-13"}, | |
{:amount => "500.0", :when => "2012-03-24"}, | |
{:amount => "100.0", :when => "2012-04-14"}, | |
{:amount => "100.0", :when => "2012-04-16"}] | |
compressed = a.group_by{|hash| hash[:when][0,7]} | |
.map{|k,v| {:when=>k,:amount=>v.reduce{|sum,hash| sum+hash[:amount].to_i}}} | |
[ {:when => "2012-03", :amount => 1000}, | |
{:when => "2012-04", :amount => 200}] |
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
#user.rb | |
class User < SmartDB | |
rename_table_to :Customer | |
attr_accessor :address, :rename_to => :location | |
end | |
#After running rake smart task, the table, class, file and attribute will be modified to this | |
#customer.rb | |
class Customer < SmartDB |
OlderNewer