Skip to content

Instantly share code, notes, and snippets.

View riywo's full-sized avatar
🏈
Go 49ers!

Ryosuke Iwanaga riywo

🏈
Go 49ers!
View GitHub Profile
@riywo
riywo / c.coffee
Last active December 29, 2015 09:59
comprehension
coffee> i*i for i in [1..9] when i % 2 == 0
[ 4, 16, 36, 64 ]
# https://github.com/jashkenas/coffee-script/issues/2030
# http://brehaut.net/blog/2011/coffeescript_comprehensions
coffee> [i,j] for j in [1..3] for i in [1..3]
[ [ [ 1, 1 ],
[ 1, 2 ],
[ 1, 3 ] ],
[ [ 2, 1 ],
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
aaaa bbb
ccc ddd
class String
def to_bin
bytes = self.size/2
self.unpack('a2'*bytes).map{|x| x.hex}.pack('C'*bytes)
end
end
"20814804c1767293b99f1d9cab3bc3e7".to_bin #=> " \x81H\x04\xC1vr\x93\xB9\x9F\x1D\x9C\xAB;\xC3\xE7"
@riywo
riywo / p.py
Created September 29, 2013 03:33
from subprocess import Popen, PIPE
p = Popen(["cat"], stdin=PIPE, stdout=PIPE)
print "stdin.write"
p.stdin.write("aaa")
p.stdin.flush()
print "stdout.read"
print p.stdout.readlines()
p.stdin.close()
p.wait()
@riywo
riywo / config.ru
Last active December 20, 2015 12:09
nginx with pow
require "anypow"
extend Anypow
run_pow "erb ./conf/nginx.conf.erb > ./conf/nginx.conf && ./sbin/nginx"
@riywo
riywo / gist:5937400
Created July 5, 2013 21:33
cross multiple arraies
class Array
def cross(array)
product(array).map { |e| e.flatten }
end
end
p [1,2].cross([3,4])
#=> [[1, 3], [1, 4], [2, 3], [2, 4]]
p [1,2].cross([3,4]).cross([5,6])
#=> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
2013-07-03 10000
2013-07-02 9000
2013-07-01 4000
2013-06-30 300
2013-06-29 100
@riywo
riywo / test.json
Last active December 19, 2015 03:19
$ ./bin/packer -v
Packer v0.1.0
$ ./bin/packer build test.json
virtualbox output will be in this color.
==> virtualbox: Downloading VirtualBox guest additions. Progress will be shown periodically.
==> virtualbox: Copying or downloading ISO. Progress will be reported periodically.
panic: EOF
goroutine 41 [running]:
{
"builders": [{
"type": "virtualbox",
"guest_os_type": "Ubuntu_64",
"iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.2-server-amd64.iso",
"iso_md5": "af5f788aee1b32c4b2634734309cc9e9",
"ssh_username": "packer",
"ssh_wait_timeout": "60s",
"boot_wait": "30s",
"boot_command": [
@riywo
riywo / gist:5883286
Last active December 19, 2015 02:29
rbenv install
MAKE_OPTS="-j 4" RUBY_CONFIGURE_OPTS="--enable-load-relative --with-readline-dir=`brew --prefix readline`" rbenv install -k -v 2.0.0-p247