Skip to content

Instantly share code, notes, and snippets.

View willnet's full-sized avatar
👶
parenting

Shinichi Maeshima willnet

👶
parenting
View GitHub Profile
@willnet
willnet / gist:1699502
Created January 29, 2012 16:24
install node manual on ec2-micro
sudo yum install gcc-c++
wget http://nodejs.org/dist/v0.6.9/node-v0.6.9.tar.gz
tar zxvf node-v0.6.9.tar.gz
cd node-v0.6.9
./configure
make
sudo make install
@willnet
willnet / gist:1701448
Created January 29, 2012 23:58
install pssenger and nginx manual on ec2-micro
sudo yum install libcurl-devel
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar zxvf nginx-1.0.11.tar.gz
sudo /usr/local/bin/gem install passenger
cd /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/bin
sudo env PATH=/usr/local/bin:$PATH ./passenger-install-nginx-module
@willnet
willnet / gist:1703102
Created January 30, 2012 07:48
install manual of swfmill on mac
# http://download.savannah.gnu.org/releases/freetype/ から最新のfreetypeをダウンロード
tar zxvf freetype-x.x.x
cd freetype
./configure
make
sudo make install
curl -O http://www.swfmill.org/releases/swfmill-0.3.2.tar.gz
tar zxvf swfmill-0.3.2.tar.gz
cd swfmill-0.3.2
@willnet
willnet / random_order.rb
Created February 23, 2012 02:46
monkey patch to add random_order to ActiveRecord with multi DB driver
# for rails 3 or higher
module ActiveRecord
module Querying
delegate :random_order, :to => :scoped
end
module QueryMethods
def random_order
relation = clone
@willnet
willnet / gist:2042787
Created March 15, 2012 07:51
RSpec custom matcher's
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}"
@willnet
willnet / amida.rb
Created June 2, 2012 05:10
minato-amida
#!/usr/bin/env ruby
number = ARGV[0]
number = number.to_i
raise if number == 0
ary = []
9.times do
@willnet
willnet / type.hs
Created July 28, 2012 06:10
learn you a haskell for great good
data Shape = Circle Float Float Float | Rectangle Float Float Float Float
@willnet
willnet / fizzbuzz.hs
Created August 7, 2012 11:39
fizzbuzz
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..])
-- 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)
-- 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