This file contains hidden or 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
10 million sequential scores insert: | |
ruby-1.8.7-p302 > insert_time = Benchmark.measure do | |
ruby-1.8.7-p302 > 1.upto(10000000) do |index| | |
ruby-1.8.7-p302 > highscore_lb.add_member("member_#{index}", index) | |
ruby-1.8.7-p302 ?> end | |
ruby-1.8.7-p302 ?> end | |
=> #<Benchmark::Tms:0x101605660 @label="", @stime=173.61, @total=577.52, @real=911.718175172806, @utime=403.91, @cstime=0.0, @cutime=0.0> | |
Average time to request an arbitrary page from the leaderboard: |
This file contains hidden or 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
Create a new leaderboard or attach to an existing leaderboard named 'highscores': | |
ruby-1.8.7-p302 > highscore_lb = Leaderboard.new('highscores') | |
=> #<Leaderboard:0x1018e4250 @page_size=25, @port=6379, @host="localhost", @redis_connection=#<Redis client v2.1.1 connected to redis://localhost:6379/0 (Redis v2.1.10)>, @leaderboard_name="highscores"> | |
If you need to pass in options for Redis, you can do this with the redis_options parameter: | |
redis_options = {:host => 'localhost', :port => 6379, :password => 'password', :db => 'some_redis_db'} | |
highscore_lb = Leaderboard.new('highscores', redis_options[:host], redis_options[:port], Leaderboard::DEFAULT_PAGE_SIZE, redis_options)) |
This file contains hidden or 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
NOTE: You will need at least Redis 2.1.6 to use the ZREVRANGEBYSCORE method. | |
Add players to HIGHSCORES table: | |
fossil:~ dczarnecki$ redis-cli | |
redis> zadd HIGHSCORES 1 player_1 | |
(integer) 1 | |
redis> zadd HIGHSCORES 2 player_2 | |
(integer) 1 | |
redis> zadd HIGHSCORES 3 player_3 |
This file contains hidden or 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
Define a constant if not defined: | |
define_if_not_defined(:A, 1) | |
assert_equal 1, A | |
Define a constant and redefine it: | |
define_if_not_defined(:B, 1) | |
redefine_without_warning(:B, 2) |
This file contains hidden or 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
source 'http://rubygems.org' | |
gem 'rails', '3.0.3' | |
gem 'thin', '1.2.7' | |
gem 'will_paginate' | |
gem 'nokogiri' | |
gem 'haml' |
This file contains hidden or 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
* We have 3 files that are modified in our local git repository, but we only want to stash 2 of those files. | |
* If we use git stash save, git will save all 3 files in the stash. How can we stash only README and TODO? | |
fossil:gitstash dczarnecki$ git status | |
# On branch master | |
# Changed but not updated: | |
# (use "git add <file>..." to update what will be committed) | |
# (use "git checkout -- <file>..." to discard changes in working directory) | |
# | |
# modified: README |
This file contains hidden or 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
dczarnecki-agora:fixtureapp dczarnecki$ rake | |
(in /Users/dczarnecki/projects/fixtureapp) | |
Loaded suite /Users/dczarnecki/.rvm/gems/ruby-1.9.2-head/gems/rake-0.8.7/lib/rake/rake_test_loader | |
Started | |
. | |
Finished in 0.040870 seconds. | |
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips | |
Test run options: --seed 37894 |
This file contains hidden or 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
require 'test_helper' | |
class PeopleControllerTest < ActionController::TestCase | |
setup do | |
@person = Factory(:person) | |
end | |
... |
This file contains hidden or 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
dczarnecki-agora:fixtureapp dczarnecki$ rake db:create:all ; rake db:migrate ; rake | |
(in /Users/dczarnecki/projects/fixtureapp) | |
(in /Users/dczarnecki/projects/fixtureapp) | |
== CreatePeople: migrating =================================================== | |
-- create_table(:people) | |
-> 0.1024s | |
== CreatePeople: migrated (0.1025s) ========================================== | |
(in /Users/dczarnecki/projects/fixtureapp) | |
Loaded suite /Users/dczarnecki/.rvm/gems/ruby-1.9.2-head/gems/rake-0.8.7/lib/rake/rake_test_loader |
This file contains hidden or 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
# Read about factories at http://github.com/thoughtbot/factory_girl | |
Factory.define :person do |f| | |
f.first_name "MyString" | |
f.last_name "MyString" | |
end |