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 ApplicationController < ActionController::Base | |
protect_from_forgery | |
before_filter :current_user | |
protected | |
def current_user | |
@current_user ||= User.where(:id => session[:user_id]).first | |
end | |
helper_method :current_user |
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 ApplicationController < ActionController::Base | |
protect_from_forgery | |
before_filter :current_user | |
protected | |
def current_user | |
@current_user ||= User.where(:id => session[:user_id]).first | |
end | |
def require_authenticate |
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
{-# LANGUAGE Arrows #-} | |
import Control.Arrow | |
multiply2 :: (Num a) => (->) a a | |
multiply2 = arr (\x -> x * 2) | |
multiply4 :: (Num a) => (->) a a | |
multiply4 = arr (\x -> x * 4) | |
addA f g = proc x -> 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
replicate' :: Int -> a -> [a] | |
replicate' n x | |
| n <= 0 = [] | |
| otherwise = x : replicate' (n-1) x | |
zip' :: [a] -> [b] -> [(a, b)] | |
zip' [] _ = [] | |
zip' _ [] = [] | |
zip' (x:xs) (y:ys) = (x, y) : zip' xs ys |
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
module MyMaybe where | |
data MyMaybe a = MyJust a | MyNothing deriving Show | |
instance Monad MyMaybe where | |
return m = MyJust m | |
(>>=) m f = case m of | |
MyJust a -> f a | |
MyNothing -> MyNothing |
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
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-} | |
class Color a where | |
toValue :: a -> (Int, Int, Int) | |
data Red = Red deriving Show | |
data Blue = Blue deriving Show | |
instance Color Red where | |
toValue _ = (255, 0, 0) |
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
#!/bin/env ruby | |
require 'time' | |
require 'pp' | |
AUTHOR = "joker1007" | |
COMMAND = "/usr/bin/git log --author=#{AUTHOR} --all --pretty='%ci'" | |
timestamps = `#{COMMAND}`.each_line.map do |l| | |
Time.parse(l.chomp) |
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
module MyState where | |
data MyState s a = MyState {runMyState :: (s -> (a, s))} | |
instance Monad (MyState s) where | |
return a = MyState $ \s -> (a, s) | |
(>>=) m f = MyState $ \s -> let (a, s') = runMyState m s | |
in runMyState (f a) s' |
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 String | |
def is_ipv4? | |
self =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ && Regexp.last_match[1..4].map(&:to_i).all? {|i| i >= 0 && i <= 255} && Regexp.last_match[1..4].all? {|octet| octet == "0" || octet[0] != "0"} | |
end | |
def is_ipv6? | |
self =~ /([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+)/ && Regexp.last_match[1..8].all? {|hex_str| hex_str == "0" || hex_str[0] != "0"} | |
end | |
def is_mac? |
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 :: [String] | |
fizzbuzz = [fb x | x <- [1..]] | |
where | |
fb x | |
| x `mod` 15 == 0 = "fizzbuzz" | |
| x `mod` 5 == 0 = "buzz" | |
| x `mod` 3 == 0 = "fizz" | |
| otherwise = show x | |
main :: IO () |