Skip to content

Instantly share code, notes, and snippets.

@tmtm
tmtm / groonga_http_client.rb
Created November 26, 2010 15:52
Groonga HTTP Client for Ruby
require 'cgi'
require 'json'
require 'socket'
class GroongaHttpClient
Error = Class.new StandardError
def initialize(host, port)
@host, @port = host, port
@tmtm
tmtm / mysql_unicode_collation.rb
Created April 16, 2011 06:25
MySQL 5.5.11 unicode_ci で同一視される文字
#!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
require 'cgi'
filename, = ARGV # path of file `ctype-uca.c'
ctype_uca = File.read(filename)
ctype_uca =~ /^uchar uca_length\[256\]={\n(.*?)};$/m or raise 'uca_length not found'
uca_length = $1.gsub(/\s/,'').split(/,/).map(&:to_i)
@tmtm
tmtm / vending_machine.rb
Created October 24, 2011 18:08
TDDBC Nagano 0.1
# -*- coding: utf-8 -*-
class VendingMachine
attr_reader :total_money
class Drink
@hash = {}
attr_reader :id, :price
def initialize(id, price)
@id, @price = id, price

Postfix で特定ドメインだけ1宛先ずつメールを送る方法

  • master.cf

    smtp の行をコピーして smtp2 という名前の行を作る

      smtp2     unix  -       -       -       -       -       smtp
    
  • main.cf

% ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

次のスクリプトを実行すると

# coding: utf-8
Encoding.default_external = 'cp932'
Encoding.default_internal = 'utf-8'
File.open('cp932.txt', 'r').read
@tmtm
tmtm / gist:5179451
Last active December 15, 2015 01:19
NSEG #37 Code Golf <http://nseg-golf.herokuapp.com>
$><<('%04d'%$*).chars.zip(%w{千 百 十}).join.gsub(/1(.)|0.?|(\d)/){$2?'0一二三四五六七八九'[$2.to_i]:$1}
@tmtm
tmtm / patch_for_mvno_sim.rb
Created April 6, 2013 18:06
b-mobile や IIJmio などの MVNO SIM で Android を使用する際にアンテナ表示がされない問題に対処するためのパッチを自動適用するスクリプト。 パッチの内容は http://hyzero3.blogspot.jp/2012/12/galaxy-noteandroid421romjellybeer-v351.html このツールを使わなくても、簡単にできる方法あり→ http://bl.oov.ch/2013/04/android-docomo-mvno-sim.html
#!/usr/local/bin/ruby
require 'fileutils'
system 'adb pull /system/framework/telephony-common.jar' or raise 'adb pull'
FileUtils.cp 'telephony-common.jar', 'telephony-common.jar.orig', :preserve=>true
system 'unzip telephony-common.jar classes.dex' or raise 'unzip'
system 'java -jar baksmali-1.4.2.jar classes.dex' or raise 'java baksmali'
file = 'out/com/android/internal/telephony/gsm/GsmServiceStateTracker.smali'
src = <<EOS
:pswitch_data_20
@tmtm
tmtm / avoid_invalid_byte_sequence_patch.rb
Last active December 16, 2015 12:18
Rack アプリで、URL のパス(PATH_INFO)中に `%FF` が入っていたり、クエリ文字列(QUERY_STRING)中に `%FF=hoge` が入っていても Invalid byte sequence で落ちないようにするパッチ
require 'rack/utils'
require 'rack/protection/path_traversal'
module Rack
module Utils
orig_normalize_params_singleton = method(:normalize_params)
define_singleton_method(:normalize_params) do |params, name, *args|
return unless name && name.valid_encoding?
orig_normalize_params_singleton.call(params, name, *args)
end
@tmtm
tmtm / gist:5881545
Last active December 19, 2015 02:18
初めての rabbit-slide new

--markup-language 未指定

% rm -rf ~/.rabbit
% rabbit-slide new --id hoge --base-name hoge
[情報]
ディレクトリを作成中: hoge
[情報]
ファイルを作成中:     hoge/.gitignore
[情報]
ファイルを作成中:     hoge/.rabbit
@tmtm
tmtm / xkb_symbols_tmtms
Last active December 19, 2015 10:19
jp106 キーボードを英語配列風にする XKB symbols ファイル
default partial alphanumeric_keys modifier_keys
xkb_symbols "tmtms" {
key <AE00> { [ Escape ] };
key <TLDE> { [ Escape ] };
key <HKTG> { [ Escape ] };
key <AE01> { [ 1, exclam ] };
key <AE02> { [ 2, at ] };
key <AE03> { [ 3, numbersign ] };
key <AE04> { [ 4, dollar ] };