Skip to content

Instantly share code, notes, and snippets.

Avatar

Masanori Kado kdmsnr

View GitHub Profile
View 金額を漢字フォーマットに変換.rb
# -*- coding: utf-8 -*-
numbers = [100, 100000500, 123456789]
numbers.each do |number|
scales = ["", "万", "億", "兆"]
puts number.to_s.gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1,").split(',').reverse.inject("") {|result, item|
scale = scales.shift
item = item.to_i.to_s.gsub(/(\d)(?=(?:\d\d\d)+(?!\d))/, '\1,')
result = item + scale + result unless item == "0"
result
} + '円'
View gist:624366
#############################################
### misc/standalone_cgi/bin/server
#############################################
kdmsnr:~# ab -n 100 -c 10 http://127.0.0.1:19292/index.rb
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
View blocked_lines.rb
blocked_lines = split_paragraph(lines).map {|i| ["<p>"] + i + ["</p>"] }
View mixi_diary_to_gmail.rb
# -*- coding: utf-8 -*-
# from: http://weed.cocolog-nifty.com/wzero3es/2010/03/090918-mixigmai.html
$KCODE = 'UTF-8'
require 'rubygems'
require 'mechanize'
require 'time'
class Mixi
View tdiary-section-permalink.diff
@kdmsnr
kdmsnr / gist:2413686
Created Apr 18, 2012
`gem install logaling-command` failed
View gist:2413686
checking for GCC... -------------------- yes
"/usr/bin/gcc-4.2 -o conftest -I/Users/kdmsnr/.rbenv/versions/1.9.3-p0/include/ruby-1.9.1/x86_64-darwin11.2.0 -I/Users/kdmsnr/.rbenv/versions/1.9.3-p0/include/ruby-1.9.1/ruby/backward -I/Users/kdmsnr/.rbenv/versions/1.9.3-p0/include/ruby-1.9.1 -I. -I'/Users/kdmsnr/.rbenv/versions/1.9.3-p0/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I'/Users/kdmsnr/.rbenv/versions/1.9.3-p0/include' -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L/Users/kdmsnr/.rbenv/versions/1.9.3-p0/lib -L. -L'/Users/kdmsnr/.rbenv/versions/1.9.3-p0/lib' -L/usr/local/lib -lruby-static -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
View review-ext.rb
# -*- coding: utf-8 -*-
ReVIEW::Compiler.defblock :tsv, 0..2, true
module ReVIEW
class Builder
# //tsv[ファイル名][キャプション]
def tsv(lines, id, caption = nil)
lines = File.open(id)
table(lines, id, caption)
end
@kdmsnr
kdmsnr / gist:c49487af5e83ac6f277b
Created Jan 29, 2015
metaprogramming ruby sample code: using.rb
View gist:c49487af5e83ac6f277b
module Kernel
def using(resource)
begin
yield
ensure
resource.dispose
end
end
def using2(resource)
View review-imenu.el
(defun review-create-imenu-index ()
(let ((index)
(pattern "^\=+\\({.+}\\)? "))
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern (point-max) t)
(push (cons (buffer-substring-no-properties (line-beginning-position) (line-end-position))
(match-beginning 0)) index))
(nreverse index))))
View gist:01af2946e63755b88a89
/Users/xxx/.nodebrew/node/v5.8.0/lib/node_modules/textlint/lib/task/textlint-core-task.js:13
f (typeof superClass !== "function" && superClass !== null) { throw new TypeEr
^
TypeError: Super expression must either be null or a function, not object
at _inherits (/Users/kdmsnr/.nodebrew/node/v5.8.0/lib/node_modules/textlint/lib/task/textlint-core-task.js:13:113)
at /Users/kdmsnr/.nodebrew/node/v5.8.0/lib/node_modules/textlint/lib/task/textlint-core-task.js:38:5
at Object.<anonymous> (/Users/kdmsnr/.nodebrew/node/v5.8.0/lib/node_modules/textlint/lib/task/textlint-core-task.js:160:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)