Skip to content

Instantly share code, notes, and snippets.

View chocoby's full-sized avatar
🏠
Working from home

Kenta Okamoto chocoby

🏠
Working from home
View GitHub Profile
@chocoby
chocoby / port.rb
Last active December 16, 2015 03:29
空いているポートを探して返す
# ruby port.rb [begin] [end]
require 'socket'
if ARGV.count < 2
puts 'Usage: ruby port.rb [begin] [end]'
exit
end
port_begin = ARGV[0].to_i
function replaceIcon() {
if (timer) return;
timer = setTimeout(function() {
var iconClass = ""; // ex. cw_a123456
var newIconUrl = "https://gist.github.com/chocoby/5320696/raw/3afb39adf96976e5b76cda4fb9cf7c490021619c/mikudayo.jpg";
var icons = document.getElementsByClassName(iconClass);
for (var i = 0; i < icons.length; i++) {
icons[i].setAttribute("src", newIconUrl);
@chocoby
chocoby / nginx.conf
Created February 25, 2013 07:53
LTSV for nginx
# LTSV logformat
log_format ltsv "time:$time_local"
"\thost:$remote_addr"
"\tmethod:$request_method"
"\turi:$request_uri"
"\tprotocol:$server_protocol"
"\tstatus:$status"
"\tsize:$body_bytes_sent"
"\treferer:$http_referer"
"\tua:$http_user_agent"
@chocoby
chocoby / basic.rb
Last active December 13, 2015 21:39
jp_prefecture gem について https://github.com/chocoby/jp_prefecture
require 'jp_prefecture'
pref = JpPrefecture::Prefecture.find 13
#=> #<JpPrefecture::Prefecture:0x007fcd25909440 @code=13, @name="東京都">
pref.name
# => "東京都"
@chocoby
chocoby / fetch.rb
Last active July 2, 2016 16:54
Rails.cache.fetch を使った例
Rails.cache.fetch('Hatsune') do
'Miku'
end
# => "Miku"
@chocoby
chocoby / gist:4030093
Created November 7, 2012 07:55
ローカルブランチ/リモートブランチを削除するやつ
DELETE_BRANCH=feature/1234_hoge; git branch -d $DELETE_BRANCH && git branch -r -d origin/$DELETE_BRANCH && git push origin :$DELETE_BRANCH
# Git でマージ済みのブランチを一括削除する #git - Qiita
# http://qiita.com/items/10a57a4f1d2806e3a3b8
# と組み合わせると良いかもしれない
@chocoby
chocoby / file0.rb
Created October 31, 2012 02:24
Ruby で楽に範囲のチェックをする ref: http://qiita.com/items/2cbe429308edc93b7854
hoge >= min and hoge <= max
@chocoby
chocoby / merge.js
Created October 9, 2012 04:01
merge hash in jquery
a = { 'hoge': 'a' }
b = { 'hoge': 'b' }
$.extend(a, b);
// Object
// hoge: "b"
// __proto__: Object
@chocoby
chocoby / gist:3773724
Created September 24, 2012 01:25
shitajiki demo
$ curl http://shitajiki.herokuapp.com -X POST -d "data=# shitajiki \n寿司 :sushi:"
# <h1>shitajiki</h1>
#
# <p>寿司 <img src="http://shitajiki.herokuapp.com/emojis/sushi.png" width="20" height="20" title=":sushi:" alt=":sushi:" class="emoji" /></p>
@chocoby
chocoby / hoge.html
Created September 22, 2012 14:23
指定された id が何個目か探すやつ
<html>
<body>
<div id="gallery">
<div id="test1">a</div>
<div id="test2">b</div>
</div>
​</body>
</html>​​​​​​​​​​​​​​