Skip to content

Instantly share code, notes, and snippets.

View tmaeda's full-sized avatar

tmaeda

  • Enishi Tech Inc.
  • Sapporo, Japan
View GitHub Profile
@tmaeda
tmaeda / gist:125383
Created June 7, 2009 16:13
emacs-rails 2.3.2 test
;; 2.3.2 test
(defun rails-core:current-test-name ()
(save-excursion
(when (search-backward-regexp "^[ ]*test[ ]*\"\\([a-z0-9_ ]+\\)\"" nil t)
(format "test_%s"
(replace-regexp-in-string " " "_" (match-string-no-properties 1))
))))
(defun rails-test:run-current-method ()
"Run a test for the current method."
@tmaeda
tmaeda / gist:161065
Created August 4, 2009 06:57
bash cd alias
# どうせcdした後はlsも打つんでしょ?
# => .bashrc などに以下を記述。
function cd() {
builtin cd "$@"
#ls -lrt
ls
}
@tmaeda
tmaeda / gist:170860
Created August 20, 2009 05:38
ruby-debug remote debug
# ruby-debug でリモートデバッグ
require 'ruby-debug'
Debugger.wait_connection = true
Debugger.start_remote
# これでプログラムを起動すれば待ち受け状態になるので、$rdebug -c とすればサーバーに接続できる
MacRuby0.5動かしてみた。めちゃめちゃ速い。
@MacBook Core2Duo 2.2GHz/4MB二次キャッシュ/4GBメモリ/800MHzバス
tmaeda-no-macbook:tmp tmaeda$ time ruby -v fib.rb 41
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
165580141
real 3m18.873s
user 3m14.033s
sys 0m1.499s
-- プログラミングHaskell 5章
import Data.Char
let2int :: Char -> Int
let2int c = ord c - ord 'a'
int2let :: Int -> Char
int2let n = chr (ord 'a' + n)
shift :: Int -> Char -> Char
@tmaeda
tmaeda / monadic_parser.rb
Created March 1, 2010 00:07
Programming in Haskell Chapter 8: Monadic Parser cf) http://tmaeda.s45.xrea.com/td/20100228.html
require 'rubygems'
require 'active_support'
def return_(v)
lambda{|input| [[v, input]]}
end
def failure
lambda{|input| []}
end
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# カレントディレクトリに存在するjpgsディレクトリ以下の全てのファイルに
# 顔認識を試行して、何らかの顔が検出できたファイルのみを
# detectedディレクトリ以下に保存します。
require 'opencv'
include OpenCV
# 顔検出に使うカスケードをロード
detector = CvHaarClassifierCascade::load('/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml')
@tmaeda
tmaeda / gist:757146
Created December 28, 2010 11:23
Ruby win32ole で Range に セル範囲名
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
excel.visible = TRUE
workbook = excel.Workbooks.Add();
worksheet = workbook.Worksheets(1);
worksheet.Range("A1:C1").Name = "hani"
worksheet.Range("hani").value = [1,2,3]
@tmaeda
tmaeda / gist:825717
Created February 14, 2011 10:43
なぜyamlをrequireしただけで、Rationalの例外があがるんだろう?
bash-3.2$ ruby -v -r yaml -e ""
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]
bash-3.2$ ruby -d -v -r yaml -e ""
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]
Exception `NoMethodError' at /Users/tmaeda/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/rational.rb:78 - undefined method `gcd' for Rational(1, 2):Rational
bash-3.2$ ruby -d -v -r yaml -e ""
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
Exception `NameError' at /Users/tmaeda/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/syck/tag.rb:81 - method `yaml_as' not defined in Module
@tmaeda
tmaeda / .emacs.anything.el
Created March 29, 2011 09:29
anything-filelist+ に anything-c-source-mac-spotlight を追加して使ってみることにした
(require 'anything-startup)
(defun my-anything-filelist+ ()
"Preconfigured `anything' to open files/buffers/bookmarks instantly.
This is a replacement for `anything-for-files'."
(interactive)
(anything-other-buffer
'(anything-c-source-ffap-line
anything-c-source-ffap-guesser