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
require 'ap' | |
$pair_size = (ENV['PAIR_SIZE'] || 2).to_i | |
def pairs(participants) | |
pairs = participants.shuffle.each_slice($pair_size).to_a | |
if pairs.last.size == 1 | |
loner = pairs.pop | |
pairs.last << loner.first |
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
Jill | |
Jack | |
Jim | |
Jane | |
Frank | |
Bob | |
Joe | |
Nancy | |
Alex | |
Somebody |
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
set PAIR_SIZE=3 | |
ruby pairs.rb people.txt | |
set /p=Hit Enter to quit... |
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
-- mssql 2000 | |
SELECT db_name(dbid), * | |
FROM master.dbo.sysaltfiles | |
ORDER BY size DESC | |
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
-- mssql 2005 and above (untested) | |
SELECT db_name(database_id) database_name, * | |
FROM sys.master_files | |
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 CreateWidgets < ActiveRecord::Migration | |
def self.up | |
create_table :widgets do |t| | |
t.string :name, :limit => 255, :null => false | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :widgets |
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
# before the work-around | |
class Widget | |
end | |
# after the work-around | |
require 'base64' | |
class Widget | |
# override the rails attribute (getter) | |
def name | |
Base64::decode64(self[:name]) |
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
# this worked as expected on mysql | |
# on postgresql it created a new widget with id of 0 | |
def some_method | |
widget = Widget.find_or_initialize_by_id(params[:widget_id]) | |
# ... | |
end | |
# workaround code for postgresql | |
def some_method | |
widget = Widget.find_or_initialize_by_id(params[:widget_id]) |
OlderNewer