Skip to content

Instantly share code, notes, and snippets.

@rinmu
rinmu / bind_dakuten.rb
Created June 20, 2017 12:46
濁点(\u3099)と半濁点(\u309A)を別扱いしている文字を結合する
DAKUTEN = "\u3099".freeze
HANDAKUTEN = "\u309A".freeze
BIND_LIST = {
"か#{DAKUTEN}" => "が",
"き#{DAKUTEN}" => "ぎ",
"く#{DAKUTEN}" => "ぐ",
"け#{DAKUTEN}" => "げ",
"こ#{DAKUTEN}" => "ご",
"さ#{DAKUTEN}" => "ざ",
@rinmu
rinmu / file0.rb
Last active November 22, 2017 11:50
クラスメソッドを alias_method_chain ref: https://qiita.com/rin_mu/items/42b6090bbc0ba3574297
class A
def foo
"foo"
end
end
class B < A
def foo_with_bar
"foo bar"
end
@rinmu
rinmu / ranking.rb
Created September 27, 2012 10:15 — forked from ppworks/ranking.rb
配列の要素をランキングする
#!/usr/bin/env ruby
def ranks scores
rank = scores.sort.reverse
scores.map{|n| rank.index(n) + 1}
end
ranks([100, 80, 90, 90, 90, 70, 70, 80]) # => [1, 5, 2, 2, 2, 7, 7, 5]
@rinmu
rinmu / about
Created July 24, 2012 01:22 — forked from naoty/about
cui-about.me client
#!/usr/bin/env ruby
require 'thor'
class CuiAboutMeClient < Thor
ROOT_PATH = 'http://cui-about.me'
desc 'me', 'curl http://cui-about.me'
def me
system "curl #{ROOT_PATH}"
@rinmu
rinmu / gist:2417724
Created April 19, 2012 01:19
ダウンロード時間計測用スクリプト
domain="http://example.com"
paths=("/" "/foo.html" "/bar.html" "baz.html")
for _path in ${paths[@]}
do
echo "\n"$domain$_path
time wget -o /dev/null -O /dev/null $domain$_path
done
@rinmu
rinmu / _form.html.haml
Created June 16, 2011 18:45
フォームに入力された住所から緯度経度を取得してPOST
%script{type: "text/javascript", src: "http://maps.google.com/maps/api/js?sensor=false"}
:javascript
function addGeocode(){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': document.getElementById('place_address').value}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// 緯度、経度を取得
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
// 緯度、経度をhiddenパラメータを追加