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 / poker.hs
Created August 21, 2012 12:02
http://qiita.com/items/cbc3af152ee3f50a822f の問題をhaskellで解いてみた
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
@willnet
willnet / turn.hs
Created September 4, 2012 07:40
http://qiita.com/items/9d80de41903775296ca6 の問題を haskell で解いてみた
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
@willnet
willnet / baseball.hs
Created September 4, 2012 12:49
http://qiita.com/items/ebd8a56b41711ba459f9 の問題をhaskellで解いてみた
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]
@willnet
willnet / tm.rb
Created October 16, 2012 13:15
オフラインリアルタイムどう書く四回をrubyで解いてみた
require 'test/unit'
class TM
def self.calc(ary)
ary.sort!.map!(&:to_i)
touch_info = ary.permutation(2).map { |a,b| check_touch(a, b) }
touch_numbers = touch_info.each_slice(3).map {|i| i.compact.length }
return 'T' if touch_numbers.max == 3
return 'O' if touch_numbers.all? { |i| i == 2 }
@willnet
willnet / gist:4128828
Created November 22, 2012 01:05
attributes custom matcher for minitest
# -*- coding: utf-8 -*-
class EqualAttributesMatcher
def initialize(attrs)
@attrs = attrs
end
def matches?(model)
@model = model
@attrs.all? { |k,v| @model.send(k) == v }
end
@willnet
willnet / gist:4128831
Created November 22, 2012 01:06
valid attribute custom matcher for minitest
class ValidAttributeMatcher
def initialize(attr_name)
@attr_name = attr_name
end
def matches?(subject)
@subject = subject
@subject.valid?
@subject.errors[@attr_name].empty?
end
@willnet
willnet / nginx
Last active December 10, 2015 08:18
nginx init script for centos
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
@willnet
willnet / dotemacs
Created December 30, 2012 13:46
minimum .emacs
(define-key global-map "\C-h" 'delete-backward-char)
(define-key isearch-mode-map "\C-h" 'isearch-delete-char)
@willnet
willnet / install-nginx.sh
Last active December 10, 2015 09:18
nginx install script for sakura vps
sudo yum install pcre-devel
wget http://nginx.org/download/nginx-1.2.6.tar.gz
tar zxvf nginx-1.2.6.tar.gz
cd nginx-1.2.6
./configure --with-openssl=/usr/lib64/openssl/engines
make
sudo make install
git clone git://gist.github.com/4406334.git
sudo mv 4406334/nginx /etc/init.d/
sudo chmod 755 /etc/init.d/nginx
@willnet
willnet / tomcat6
Last active February 23, 2017 05:27 — forked from tcocca/tomcat6
tomcat init script for centos
#!/bin/bash
# description: Tomcat6 service
# processname: java
# chkconfig: - 99 1
# Source function library.
. /etc/init.d/functions
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre
export TOMCAT_USER=solr
export CATALINA_HOME=/opt/tomcat6