This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GoodName | |
refine(String) do | |
def good_name? | |
true | |
end | |
end | |
def bad_name? | |
false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使い方: | |
# yml = File.read(path) | |
# yml_to_struct(yml) | |
def yml_to_struct(yml) | |
yml_object = YAML.load(ERB.new(yml).result) | |
yml_object_to_struct(yml_object) | |
end | |
# YAML.load した結果の Object に含まれる Hash を Struct に変換し、 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
array = (1..10_000).map { |n| [n] } | |
Benchmark.bm do |x| | |
x.report('map & flatten:') { array.map { |a| a << 'yuno' }.flatten } | |
x.report('map & flatten!:') { array.map { |a| a << 'yuno' }.flatten! } | |
x.report('flat_map:') { array.flat_map { |a| a << 'yuno' } } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'json' | |
module Ruboty | |
module Handlers | |
class IizukaWeather < Base | |
CITY_CODE = 400030 | |
on /飯塚.+天気\z/, name: 'weather', description: 'Return weather in Iizuka' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Slack | |
def notice | |
# 処理はサブクラスのインスタンスに委譲したい。 | |
my_child._notice | |
end | |
protected | |
# とりあえずメソッド名の先頭に _ を付けてごまかしている。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lodge: | |
per_size: 30 | |
right_list_size: 10 | |
slack: | |
defaults: &defaults | |
url: https://slack.com | |
channel: #channel | |
# トークンは Slack API のページで発行できます。 | |
token: my_token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage | |
# ruby rename.rb ~/Downloads/reg_test "homu_(\d+)_homu.(txt)" "sayaka_@[email protected]" | |
require "fileutils" | |
dir = File.expand_path(ARGV[0]) | |
pattern = /#{ARGV[1]}$/ | |
after = ARGV[2] | |
Dir.glob(File.join(dir, "**/*")).each do |filename| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# normal with Lo-Dash | |
konami = (handler) -> | |
keys = [] | |
command = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65] | |
$(document).on "keydown", (event) -> | |
keys.push event.which | |
keys.shift() if keys.length > command.length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# コマンドのまとまりを記述、hogeがコマンド名になる | |
function hoge () { | |
echo command | |
} | |
# ラインエディタを有効にする。自分が新しいコマンドを作る場合に必要 | |
zle -N hoge | |
# キーバインドを設定 | |
bindkey '^a' hoge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# peco | |
function peco-select-history () { | |
local tac | |
if which tac > /dev/null; then | |
tac="tac" | |
else | |
tac="tail -r" | |
fi | |
BUFFER=$(\history -n 1 | \ | |
eval $tac | \ |