Skip to content

Instantly share code, notes, and snippets.

View joker1007's full-sized avatar

Tomohiro Hashidate joker1007

View GitHub Profile
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
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
{-# 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
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
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
{-# 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)
@joker1007
joker1007 / commit_log_ts.rb
Created August 1, 2012 04:44
その日のコミットログの最初と最後を表示する
#!/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)
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'
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?
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 ()