Skip to content

Instantly share code, notes, and snippets.

View kdmsnr's full-sized avatar

Masanori Kado kdmsnr

View GitHub Profile
# -*- 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
} + '円'
#############################################
### 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
blocked_lines = split_paragraph(lines).map {|i| ["<p>"] + i + ["</p>"] }
# -*- 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
@kdmsnr
kdmsnr / gist:2413686
Created April 18, 2012 13:49
`gem install logaling-command` failed
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 */
# -*- 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 January 29, 2015 05:35
metaprogramming ruby sample code: using.rb
module Kernel
def using(resource)
begin
yield
ensure
resource.dispose
end
end
def using2(resource)
(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))))
@kdmsnr
kdmsnr / gist:01af2946e63755b88a89
Created March 14, 2016 01:59
error of textlint
/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)