This file contains 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
# Array#tap mistery | |
array = [].tap do |array| | |
array << [1,3] | |
end | |
p array #=> [[1,3]] | |
array = [].tap do |array| | |
array += [1,3] |
This file contains 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
# 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 } |
This file contains 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
#!/bin/bash -x | |
while getopts d opt; do | |
case $opt in | |
d) DEBUG="y" ;; | |
esac | |
done | |
if [ -z $DEBUG ]; then | |
echo "NO DEBUG" |
This file contains 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
" | |
" $VIM_HOME なディレクトリにあるファイルを無視させるにはどうしたらよいか? | |
" * このファイルは読み込ませつつ .vim/plugins/*.vim などを無視させたい。 | |
" * `--noplugin` だとこのファイルで読み込み指定したプラギンも無視される…。 | |
" | |
if has('vim_starting') | |
set nocompatible | |
set runtimepath+=$HOME/.vim/bundle/neobundle.vim | |
endif |
This file contains 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
# http://magazine.rubyist.net/?0034-FiberForBeginners | |
# | |
# fibonacci by Fiber | |
# | |
fib = Fiber.new do | |
a, b = 0, 1 | |
loop do | |
a, b = b, a + b |
This file contains 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
// http://golang.jp/go_tutorial#index12 | |
package main | |
import "fmt" | |
func generate(ch chan int) { | |
for i := 2; ; i++ { | |
ch <- i | |
} |
This file contains 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 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) |
This file contains 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
# coding: utf-8 | |
require "pathname" | |
require "rake" | |
module DIR | |
ROOT = Pathname(__dir__) | |
ORG = ROOT.join("org") | |
OUT = ROOT.join("out") |
This file contains 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 "wisper" | |
require "date" | |
class MyPublisher | |
include Wisper::Publisher | |
def tick(time) | |
publish(:tack, time) | |
end | |
end |
This file contains 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
# 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 |