Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
dakatsuka / mail_patch.rb
Created April 17, 2011 14:14
Mailライブラリのsubjectをデコードする機能を上書き(EncodingからKconvを使うように変更)
# coding: utf-8
module Mail
class Ruby19
def Ruby19.b_value_decode(str)
match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Ruby19.decode_base64(match[2])
str.force_encoding(fix_encoding(encoding))
@dakatsuka
dakatsuka / .tmux.conf
Created April 29, 2011 18:27
.tmux.conf
# basic
set-option utf8-default on
set-window-option -g utf8 on
set-window-option -g mode-keys vi
set-window-option -g automatic-rename off
# key bind
set-option -g prefix C-j
unbind-key C-j
bind-key C-j send-prefix
require 'capistrano/recipes/deploy/strategy/remote_cache'
class RemoteCacheSubdir < Capistrano::Deploy::Strategy::RemoteCache
private
def repository_cache_subdir
if configuration[:deploy_subdir] then
File.join(repository_cache, configuration[:deploy_subdir])
else
repository_cache
end
@dakatsuka
dakatsuka / deploy.rb
Created May 13, 2011 17:14
Capistrano deploy.rb
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
require 'erb'
set :application, "app"
set :scm, :git
set :repository, "git://domain.com/path/to/repository.git"
set :deploy_subdir, "/path/to/app" # require https://gist.github.com/970910 to Capfile
set :deploy_via, :copy
set :use_sudo, false
if defined? Rails::Console
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveResource::Base.logger = Logger.new(STDOUT)
if defined? Hirb
Hirb.enable
end
end
@dakatsuka
dakatsuka / gist:980534
Created May 19, 2011 10:59
タブ文字をスペース2文字に置き換える
find . -name '*.html.erb' | xargs grep -l ' ' | xargs sed -i.bak 's/ / /g'
@dakatsuka
dakatsuka / app.js
Created June 7, 2011 10:44
node.js + express (Hello World)
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res) {
res.send('Hello World');
});
app.listen(3000);
@dakatsuka
dakatsuka / app.js
Created June 7, 2011 13:00
Sign in with twitter
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What The Fuck You Want
// To Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/wtfpl/COPYING for more details.
var express = require('express');
var app = express.createServer();
var oauth = new (require('oauth').OAuth)(
'https://api.twitter.com/oauth/request_token',
@dakatsuka
dakatsuka / app.js
Created June 12, 2011 05:04
中継サーバをnode.js + WebSocketで実装してみる
var sys = require('sys');
var ws = require('websocket-server');
var server = ws.createServer();
var relay = new (require('websocket-client').WebSocket)('ws://localhost:8000');
var Parameter = {
pack: function(json) {
return JSON.stringify(json);
},
@dakatsuka
dakatsuka / reverse.rb
Created June 18, 2011 13:25
配列に入っている文字列を1文字ずつ逆順出力
["ABC", "DEF", "GHJ"].join("").split("").reverse.each {|str| puts str}