Skip to content

Instantly share code, notes, and snippets.

@takehiko
takehiko / match-paren-japanese.el
Created November 18, 2012 21:18
Extensions to match-paren
;; 対応するカッコにジャンプ
(defun match-paren-japanese (arg)
"Go to the matching parenthesis."
(interactive "p")
(cond ((looking-at "[([{({[「『《〔【〈]") (forward-sexp 1) (backward-char))
((looking-at "[])}){]」』》〕】〉]") (forward-char) (backward-sexp 1))
(t (message "match-paren-japanese ignored"))))
(global-set-key [f5] 'match-paren-japanese)
;; 対応するカッコまでをコピー
@takehiko
takehiko / commit-email.rb
Created November 10, 2012 18:31
Send email after commit; a hook script of Subversion
#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
# commit-email.rb for Ruby 1.9/1.8
# http://d.hatena.ne.jp/takehikom/20121111/1352572653
require "rubygems"
require "mail-iso-2022-jp" # gem install mail-iso-2022-jp
require "kconv"
@takehiko
takehiko / tri3.rb
Created October 20, 2012 20:01
Tripartition of equilateral triangle
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# When you execute this Ruby script,
# two SVG files "tri3a.svg" and "tri3b.svg" will be generated.
# Those files show a tripartition of an equilateral triangle,
# and you can make sure it by SVG-readable browsers (Firefox),
# SVG drawers (Inkscape), or even text editors (Emacs).
class Point
@takehiko
takehiko / ncr.rb
Created October 1, 2012 20:38
Numerical Character References
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Numerical Character References
if RUBY_VERSION < "1.9"
$KCODE = "u"
class String
def ord
@takehiko
takehiko / cpuinfo.rb
Created September 22, 2012 10:37
Get processor name, number of processors and clock speed using Win32OLE
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# cpuinfo.rb : get processor name, number of processors and clock speed
# using Win32OLE
require "win32ole"
wmi = WIN32OLE.connect("winmgmts://")
query = wmi.ExecQuery("select * from Win32_Processor")
@takehiko
takehiko / now.sh
Created September 9, 2012 21:38
Print current time in various formats
function now() {
case ${1:-_} in
-h*|--h*) # now --help
echo usage: now '[date|httpdate|rfc2822|iso8601]' ;;
d*) # now date
LC_ALL=C date ;;
h*) # now httpdate
ruby -e 'require "time"; puts Time.now.httpdate' ;;
i*|x*) # now iso8601, now xmlschema
ruby -e 'require "time"; puts Time.now.iso8601'\(${2:-0}\) ;;
@takehiko
takehiko / hash-all-zero.rb
Created August 5, 2012 19:21
Find all-zero hash
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class StringAndHash
def initialize(s, h)
@string = s
@hash = h
@length_zero = (/^0+/ =~ @hash) ? $&.length : 0
end
@takehiko
takehiko / replace-punctuation.el
Created July 12, 2012 19:45
Replace Punctuation (ten-maru and comma-period in Japanese)
;; 句読点変換(M-x tenmaru / M-x commamaru / M-x commaperiod)
;; http://d.hatena.ne.jp/takehikom/20120713/1342122621
(defun replace-punctuation (a1 a2 b1 b2)
"Replace periods and commas"
(let ((s1 (if mark-active "選択領域" "バッファ全体"))
(s2 (concat a2 b2))
(b (if mark-active (region-beginning) (point-min)))
(e (if mark-active (region-end) (point-max))))
(if (y-or-n-p (concat s1 "の句読点を「" s2 "」にしますがよろしいですか?"))
(progn
@takehiko
takehiko / rot90d.rb
Created March 22, 2012 20:30
Four fives: Method D
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class Rot90d
def initialize
@field_s = (<<EOS).gsub(/\n/, "")
**
**
******
******
@takehiko
takehiko / amazon-searcher.rb
Created January 8, 2012 19:04
Book & Product Searcher with Ruby/AWS
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# amazon-searcher.rb by takehikom
# run "gem install ruby-aaws"
# and prepare "~/.amazonrc"
require "rubygems"
require "amazon/aws/search"