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
# for rails 3 or higher | |
module ActiveRecord | |
module Querying | |
delegate :random_order, :to => :scoped | |
end | |
module QueryMethods | |
def random_order | |
relation = clone |
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
RSpec::Matchers.define :have_json do |hash| | |
match do |response| | |
hash.all? do |k,v| | |
JSON.parse(response.body)[k] == v | |
end | |
end | |
failure_message_for_should do |response| | |
body = JSON.parse(response.body) | |
"expected that #{body} would have #{hash}" |
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
#!/usr/bin/env ruby | |
number = ARGV[0] | |
number = number.to_i | |
raise if number == 0 | |
ary = [] | |
9.times do |
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
data Shape = Circle Float Float Float | Rectangle Float Float Float Float |
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
fizzbuzz :: Int -> String | |
fizzbuzz n | |
| n `mod` 15 == 0 = "fizzbuzz" | |
| n `mod` 3 == 0 = "fizz" | |
| n `mod` 5 == 0 = "buzz" | |
| otherwise = show n | |
main = do | |
mapM_ putStr $ map (++ ", ") (take 100 $ map fizzbuzz [1..]) |
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
-- http://www.rubyquiz.com/quiz93.html | |
import Data.Char | |
checkHappy :: Int -> Bool | |
checkHappy n = checkHappy' [n] | |
checkHappy' :: [Int] -> Bool | |
checkHappy' list | |
| firstInput == 1 = True | |
| firstInput == nextValue = False | |
| otherwise = checkHappy' (nextValue:list) |
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
-- http://www.haskell.org/haskellwiki/99_questions/54A_to_60 | |
-- Problem 55 | |
data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq) | |
leaf x = Branch x Empty Empty | |
cbalTree :: Int -> [Tree Char] | |
cbalTree 0 = [Empty] | |
cbalTree n = let (q, r) = (n - 1) `quotRem` 2 | |
in [Branch 'x' left right | i <- [q..(q+r)] | |
, left <- cbalTree i |
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
import Data.List | |
import Test.HUnit | |
poker :: String -> String | |
poker = check . split | |
split :: String -> [(String, String)] | |
split ('D':'1':'0':xs) = [("D", "10")] ++ split xs | |
split ('C':'1':'0':xs) = [("C", "10")] ++ split xs | |
split ('S':'1':'0':xs) = [("S", "10")] ++ split xs |
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
import Data.Char | |
import Test.HUnit | |
import System.Environment | |
data Image = Image Int String | |
instance Show Image where | |
show (Image l d) = "Image " ++ [(intToDigit l)] ++ ":" ++ (apply $ appendZero d) | |
appendZero :: String -> String |
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
import Data.Char | |
import System.Environment | |
main = do | |
args <- getArgs | |
print . process. head $ args | |
process = foldl (\acc x -> cal acc x) [] | |
cal acc x = acc ++ [r x] |