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
-- supplied with two group ids, return all users with ONLY those two groups. | |
SELECT users.*, count(*) as grp_count | |
FROM users | |
JOIN users_groups | |
ON users.id = users_groups.user_id | |
WHERE users_groups.group_id in (730, 733) | |
GROUP BY users.id | |
HAVING count(*) = 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
SELECT favorites.id, drink_id, count(*) as times | |
FROM favorizations, favorites | |
WHERE favorites.id = favorite_id | |
GROUP BY favorites.id, drink_id | |
HAVING times > 0 | |
ORDER BY times desc | |
LIMIT 15 |
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 Kelly | |
def have_another_beer? | |
return "yes".upcase | |
end | |
def racist? | |
ALWAYS_ESPECIALLY_THE_JEWS | |
end | |
def a_robot? |
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
module CertificateMagic | |
def self.included(base) | |
base.send :extend, ClassMethods | |
end | |
module ClassMethods | |
def some_class_method | |
end | |
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
require 'rubygems' | |
require 'nokogiri' | |
# Place this file in your rails app/lib folder | |
class TplParse | |
attr_accessor :registrars | |
def initialize | |
self.registrars = [] |
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 ArrayExpander | |
attr_accessor :replacements | |
attr_accessor :column_order | |
def initialize | |
self.replacements = {} | |
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
context "something" do | |
setup do | |
# outer setup | |
end | |
should "do things" do | |
assert :stuff | |
end | |
context "without some extras" do |
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 service_level_values | |
ServiceLevel.all.collect do |s| | |
[service_level_label(s), s.id] | |
end | |
end | |
def service_level_label(service_level) | |
"#{service_level.name.capitalize} Service (#{format_price_for_select service_level.price}) - Up to #{pluralize service_level.delay, 'business day'} before despatch" | |
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
#!/usr/bin/ruby | |
# inkscape -b '#ffffff' -e circles.png -w 3000 circles.svg | |
# gem install color-tools | |
require 'color' | |
# http://code.google.com/p/chipmunk-physics/ | |
# svn checkout http://chipmunk-physics.googlecode.com/svn/trunk/ chipmunk-physics-read-only | |
# cmake -D BUILD_RUBY_EXT=ON . | |
# make && sudo make install |
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 'rubygems' rescue nil | |
require 'gosu' | |
require 'chipmunk' | |
class Array | |
# e.g. [1,2,3].each_link yields [1,2], [2,3] | |
def each_link | |
prev = first | |
self[1, size].each do |item| | |
yield prev, item |