Skip to content

Instantly share code, notes, and snippets.

View kyanagi's full-sized avatar

Kouhei Yanagita kyanagi

View GitHub Profile
module ActiveRecord::ConnectionAdapters::SchemaStatements
alias orig_add_index add_index
def add_index(table_name, column_name, options = {})
orig_add_index(table_name, column_name, options || {})
end
end
# create table users (id integer auto_increment, primary key (id));
# create table items (id integer auto_increment, user_id integer, primary key (id));
# insert into users (id) values (1);
# insert into items (user_id) values (1);
% cat a.rb
require 'rubygems'
require 'active_support/dependencies'
require 'active_record'
instance_eval <<_E
puts "\xe3\x81\x82".encoding # => ASCII-8BIT
_E
instance_eval <<_E
# coding: utf-8
puts "\xe3\x81\x82".encoding # => UTF-8
_E
@kyanagi
kyanagi / main.rhtml
Created November 23, 2010 17:49
myapp.rb
ä
<%= @str %>
@kyanagi
kyanagi / gist:1582637
Created January 9, 2012 11:52
find-fileで*Completions*バッファに`../'と`./'を出さない
;; find-fileで*Completions*バッファに`../'と`./'を出さない
(defun find-file-read-args (prompt mustmatch)
(list (read-file-name prompt nil default-directory mustmatch nil
(lambda (name)
(and (file-exists-p name)
(not (member name '("../" "./"))))
))
t))
@kyanagi
kyanagi / gist:1640254
Created January 19, 2012 14:24
optimize vcs_info on Cygwin
--- /usr/share/zsh/4.3.12/functions/VCS_INFO_bydir_detect 2011-08-08 04:59:41.001000000 +0900
+++ VCS_INFO_bydir_detect 2012-01-19 21:52:35.293434600 +0900
@@ -6,7 +6,7 @@
local dirname=$1
local basedir="." realbasedir file
-realbasedir="$(VCS_INFO_realpath ${basedir})"
+realbasedir="${basedir:A}"
while [[ ${realbasedir} != '/' ]]; do
[[ -r ${realbasedir} ]] || return 1
a='VWXYZ'
${(l:3::abcdefg::1234567890:)a} # => XYZ
${(l:10::abcdefg::1234567890:)a} # => 67890VWXYZ
${(l:20::abcdefg::1234567890:)a} # => cdefg1234567890VWXYZ
${(r:3::abcdefg::1234567890:)a} # => VWX
${(r:10::abcdefg::1234567890:)a} # => VWXYZ12345
${(r:20::abcdefg::1234567890:)a} # => VWXYZ1234567890abcde
function f {
local s='old'
echo -n "${(r:15:: :)1}${(e)1}"
s=''
echo -n "\t${(e)1}"
unset s
echo -n "\t${(e)1}"
echo
}
s
k
t
h
ka
m
sh
n
z
ko
@kyanagi
kyanagi / skk2migemo.rb
Created February 11, 2012 08:53
Convert a skk dictionary to migemo's.
#!/usr/bin/env ruby
# usage: skk2migemo.rb SKK-JISYO.JIS3_4 > migemo-dict.jis3_4
require 'iconv'
dict = Hash.new{[]}
ARGF.each_line do |line|
line.chomp!
line = Iconv.conv('UTF-8', 'EUC-JISX0213', line)
next if line =~ /\A;/
if line =~ /\A([^ ]+) +(.*)\z/
key, value = $1, $2