Skip to content

Instantly share code, notes, and snippets.

View tkfm-yamaguchi's full-sized avatar

Takafumi Yamaguchi tkfm-yamaguchi

View GitHub Profile
# config/initializers/sprockets.rb
YourAppName::Application.configure do |config|
config.assets.context_class.instance_eval do
# enables to use named_route in the asset files.
# ( asset file should be ERB )
include Rails.application.routes.url_helpers
end
end
@tkfm-yamaguchi
tkfm-yamaguchi / wisper-blocks.rb
Last active August 29, 2015 14:03
wisper blocks publisher according to subscriber's process
require "wisper"
require "date"
class MyPublisher
include Wisper::Publisher
def tick(time)
publish(:tack, time)
end
end
@tkfm-yamaguchi
tkfm-yamaguchi / Rakefile
Created July 28, 2014 01:37
usage of String#ext ( injected by rake )
# coding: utf-8
require "pathname"
require "rake"
module DIR
ROOT = Pathname(__dir__)
ORG = ROOT.join("org")
OUT = ROOT.join("out")
@tkfm-yamaguchi
tkfm-yamaguchi / mysort.rb
Last active August 29, 2015 14:04
easy sorting on ruby
class Array
def my_sort!
1.upto(size-1) do |i|
i.downto(1) do |j|
swap!(j, j-1) if less?(j, j-1)
end
end
end
def swap!(ind1, ind2)
@tkfm-yamaguchi
tkfm-yamaguchi / sieve.go
Last active August 29, 2015 14:04
ruby implementation of golang's sieve routine example
// http://golang.jp/go_tutorial#index12
package main
import "fmt"
func generate(ch chan int) {
for i := 2; ; i++ {
ch <- i
}
@tkfm-yamaguchi
tkfm-yamaguchi / fibfib.rb
Last active August 29, 2015 14:04
fibfib(fibonacci and fiber)
# http://magazine.rubyist.net/?0034-FiberForBeginners
#
# fibonacci by Fiber
#
fib = Fiber.new do
a, b = 0, 1
loop do
a, b = b, a + b
@tkfm-yamaguchi
tkfm-yamaguchi / minimal.vim
Last active August 29, 2015 14:05
WIP - creating minimal rc to configure neocomplete
"
" $VIM_HOME なディレクトリにあるファイルを無視させるにはどうしたらよいか?
" * このファイルは読み込ませつつ .vim/plugins/*.vim などを無視させたい。
" * `--noplugin` だとこのファイルで読み込み指定したプラギンも無視される…。
"
if has('vim_starting')
set nocompatible
set runtimepath+=$HOME/.vim/bundle/neobundle.vim
endif
@tkfm-yamaguchi
tkfm-yamaguchi / getopts_test.sh
Last active August 29, 2015 14:05
getopts is a command of sh/bash
#!/bin/bash -x
while getopts d opt; do
case $opt in
d) DEBUG="y" ;;
esac
done
if [ -z $DEBUG ]; then
echo "NO DEBUG"
@tkfm-yamaguchi
tkfm-yamaguchi / newton.rb
Created August 12, 2014 03:42
sqrt by newton method
# coding: utf-8
#
# sqrt by newton method
#
def gen_sqrt_iter(square, seed=1)
Fiber.new do
f = ->(x){ x**2.0 - square }
fd = ->(x){ 2.0 * x }
@tkfm-yamaguchi
tkfm-yamaguchi / array-tap.rb
Created August 12, 2014 06:20
Array#tap mistery
# Array#tap mistery
array = [].tap do |array|
array << [1,3]
end
p array #=> [[1,3]]
array = [].tap do |array|
array += [1,3]