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
| irb(main):007:0> g = Game.joins("INNER JOIN (SELECT * FROM scores WHERE player = 'brian') s1 on s1.game_id = games.id").joins("INNER JOIN (SELECT * FROM scores WHERE player = 'dj') s2 on s2.game_id = games.id").includes(:scores) | |
| Game Load (0.3ms) SELECT "games".* FROM "games" INNER JOIN (SELECT * FROM scores WHERE player = 'brian') s1 on s1.game_id = games.id INNER JOIN (SELECT * FROM scores WHERE player = 'dj') s2 on s2.game_id = games.id | |
| Score Load (0.3ms) SELECT "scores".* FROM "scores" WHERE "scores"."game_id" IN (1, 3) | |
| => [#<Game id: 1, created_at: "2012-11-19 08:35:03", updated_at: "2012-11-19 08:35:03">, #<Game id: 3, created_at: "2012-11-19 08:36:54", updated_at: "2012-11-19 08:36:54">] | |
| irb(main):008:0> |
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 TABLE games (id int); | |
| CREATE TABLE scores (game_id int, player_name VARCHAR(255)); | |
| INSERT INTO games(id) VALUES (1); | |
| INSERT INTO games(id) VALUES (2); | |
| INSERT INTO games(id) VALUES (3); | |
| INSERT INTO scores(game_id, player_name) VALUES (1, "dj"); | |
| INSERT INTO scores(game_id, player_name) VALUES (1, "brian"); | |
| INSERT INTO scores(game_id, player_name) VALUES (1, "daniel"); |
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
| (0..25).to_enum.reduce({}) do |memo,i| | |
| memo[(i + 'a'.ord).chr] = i + 1 | |
| memo | |
| 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
| def yourls_shorten(url) | |
| # use yourls shortener | |
| # need to provide url config option | |
| require 'rubygems' | |
| require 'json/pure' | |
| params = ['action=shorturl'] | |
| params << 'format=simple' | |
| params << 'url=' + URI.encode(url) | |
| yourls_url = Weechat.config_get_plugin('yourls_url') | |
| api_url = [yourls_url, params.join('&')].join(yourls_url.include?('?') ? '&' : '?') |
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
| # build a hash that links number to char, so { "1" => "a", "2" => "b", ... } | |
| CODES = (0..25).reduce Hash.new do |memo, code| | |
| memo[(code + 1).to_s] = (code + 'a'.ord).chr | |
| memo | |
| end | |
| # recursive method | |
| def decode(str) | |
| # terminal case if the string given is empty |
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
| Run filtered excluding {:skip_on_windows=>false} | |
| ...............F..................................F..F.FF............FF....................F..............................................F.....................................FF..........................F.............FFFF........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ | |
| Failures: | |
| 1) Capybara::Driver::Webkit::Browser#set_proxy uses URLs changed by javascript | |
| Failure/Error: browser.requested_url.should == 'http://example.org/blah' | |
| expected: "http://example.org/blah" | |
| got: "http://example.org/" (using ==) | |
| # ./spec/br |
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
| class Medium < ActiveRecord::Base | |
| serialize :payload, JSON | |
| 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
| therubyracer> Person.prototype.test = function() { return "hello world"; } | |
| function () { return "hello world"; } | |
| therubyracer> var Hippo; | |
| therubyracer> Hippo = Person.prototype.constructor; | |
| function () {} | |
| therubyracer> var mystery = new Hippo(); | |
| therubyracer> mystery.test(); | |
| hello world | |
| therubyracer> mystery instanceof Hippo | |
| true |
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
| puts "Hello World!" |
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
| /* | |
| * Content-Type:text/javascript | |
| * | |
| * A bridge between iPad and iPhone touch events and jquery draggable, | |
| * sortable etc. mouse interactions. | |
| * @author Oleg Slobodskoi | |
| * | |
| * modified by John Hardy to use with any touch device | |
| * fixed breakage caused by jquery.ui so that mouseHandled internal flag is reset | |
| * before each touchStart event |