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 / 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: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 / emacs-install.sh
Last active December 11, 2015 11:08
how to install emacs on centos
./configure --without-toolkit-scroll-bars --without-xaw3d --without-compress-info --without-sound --without-pop --without-xpm --without-tiff --without-rsvg --without-gconf --without-gsettings --without-selinux --without-gpm --without-makeinfo --with-x
make
sudo make install
@willnet
willnet / stub_cookies.rb
Created February 6, 2013 01:41
stub cookies for unit test
class StubCookies < Hash
def [](name)
super(name.to_s)
end
def []=(key, options)
if options.is_a?(Hash)
options.symbolize_keys!
else
options = { :value => options }
@willnet
willnet / delete_logs_before_last_month.rb
Last active December 18, 2015 08:38
ruby script to delete old tomcat logs (e.g. 'catalina.2013-06-11.log') usage `./delete_logs_before_last_month.rb /path/to/catalina/logs_directory`
#!/usr/bin/env ruby
require 'pathname'
require 'date'
require 'fileutils'
path = ARGV.first
path_name = Pathname.new(path)
last_month = Date.today.prev_month
last_month_beginning_of_day = last_month.prev_day(last_month.day - 1)
@willnet
willnet / master.rb
Created June 11, 2013 08:27
god setting example
RAILS_ROOT = "/path/to/root"
God.watch do |w|
w.name = "solr"
w.interval = 30.seconds # default
w.dir = RAILS_ROOT
w.log = "#{RAILS_ROOT}/log/god.log"
w.env = { 'RAILS_ROOT' => RAILS_ROOT,
'RAILS_ENV' => "production",
'HOME' => '/root'}
@willnet
willnet / agg
Created June 17, 2013 11:40
ag wrapper script for make output like grep
#!/bin/sh
exec ag --silent --color --color-match '01;31' --nogroup "$@"