Skip to content

Instantly share code, notes, and snippets.

@hagiyat
hagiyat / termitecolors_from_iterm2colors.bash
Last active March 25, 2017 16:59
Converts the color scheme of Xresources defined in iTerm2-Color-Schemes to the termite color definition.
#!/usr/bin/env bash
IFS=$'\n';
for file in `ls ./iTerm2-Color-Schemes/Xresources`; do
cat "./iTerm2-Color-Schemes/Xresources/${file}" \
| sed -e 's/^\!/#/g' -e 's/^\*\.//g' -e 's/: / = /g' \
> "./termite-colors/${file}"
done
@hagiyat
hagiyat / kintai.rb
Last active December 29, 2016 06:29
Record the geolocation record via IFTTT
#!/usr/bin/env ruby
require 'time'
require 'json'
unless ARGV.length == 1
puts "Usage: ruby kintai.rb [input file]"
exit 1
end
@hagiyat
hagiyat / bench.rb
Created April 6, 2016 01:20
Benchmark method of performance measurement methods
module SimpleBenchmark
require 'benchmark'
def benchmarker(report_name)
Benchmark.bm 10 do |r|
r.report(report_name) do
yield
end
end
end
end
def search(key, list) do
list
|> Enum.split(2) # convert list to key/value
|> Tuple.to_list
|> Enum.filter_map(fn(v) -> v |> List.first == key end, &(&1 |> List.last))
|> List.first
end
search("hoge", ["hoge", 1, "fuga", 2, "piyo", "baz"]) # 1
@hagiyat
hagiyat / gist:16bec3d1b2de4e849971
Created November 17, 2015 06:47
If you write a Ruby of Time.now.to_i in Elixir?
# mix.exs
defp deps do
[{:timex, "~> 1.0.0-rc2"}]
end
# on your source
Timex.Time.now(:secs)
@hagiyat
hagiyat / search_key_from_flat_list.ex
Last active August 29, 2015 14:27
search by key from flat list
def search(key, list) do
list
|> Enum.split(2) # convert list to key/value
|> Tuple.to_list
|> Enum.filter_map(fn(v) -> v |> List.first == key end, &(&1 |> List.last))
|> List.first
end
search("hoge", ["hoge", 1, "fuga", 2, "piyo", "baz"]) # 1
source = {
hoge: { piyo: {
piyo1: 'piyo1',
piyo2: 'piyo2'
}, baz: 'baz' },
fuga: { foo: 'foo', bar: 'bar' }
}
fetch_hash = ->(source, key, separator='_') do
key.split(separator)
.reduce(source) { |msg, v| msg[v.to_sym] || {} }
class Hoge
private
def fuga
'hoge'
end
end
module Piyo
def baz
fuga()
# No.4
list = [50, 2, 1, 9]
list.sort_by(&:to_s).reverse.join
# No.5
[*2..9].reduce(['1']) do
|res, v| res.map { |r| ['', ' + ', ' - '].map { |oper| "#{r}#{oper}#{v}" } }.flatten
end.select { |v| eval(v) == 100 }
@hagiyat
hagiyat / wercker.yml
Last active April 8, 2016 14:50
test-queue on wercker
# only run spec
box: nanapi/ubuntu-rvm-with-phantomjs@0.0.2
no-response-timeout: 10
services:
- ibash/mysql5.6
build: