Skip to content

Instantly share code, notes, and snippets.

git branch | grep -v master | sed s/^..// | xargs git branch -D
@hzm-s
hzm-s / eratos.rb
Created April 24, 2016 08:26
Sieve of Eratosthenes
def compute(number)
sieve((2..number).to_a, [], Math.sqrt(number))
end
def sieve(list, primes, stopper)
return primes + list if list.first >= stopper
primes << list.shift
list.reject! { |n| n % primes.last == 0 }
sieve(list, primes, stopper)
end
@hzm-s
hzm-s / app.rb
Created March 18, 2015 13:31
rails
require 'bundler/setup'
Bundler.require
require 'active_record'
require 'action_controller/railtie'
require 'action_view/railtie'
# ActiveRecord::Config
ActiveRecord::Base.configurations = {'development' => {:adapter => 'sqlite3', :database => ':memory:'}}
ActiveRecord::Base.establish_connection :development
@hzm-s
hzm-s / regexp_union.rb
Created August 18, 2014 12:35
配列をもとに正規表現オブジェクトをつくる ref: http://qiita.com/haazime/items/9b39af6708cc214b2651
words = %w(foo bar baz)
regexp = Regexp.union(words)
@hzm-s
hzm-s / i_f.go
Created August 12, 2014 12:59
Goのインタフェースとその実装、およびstructへの埋め込み ref: http://qiita.com/haazime/items/2cc00097215ee8828224
package main
import "fmt"
// 料理を作るI/F
type Cooker interface {
Cook() string
}
// 塗るI/F
class KaraokeMachine
def initialize(melody_string)
@melody = Melody.parse(melody_string)
end
def transpose(amount)
@melody.transpose(amount).present
end
end
@hzm-s
hzm-s / mixin.go
Last active April 13, 2022 10:50
mixin with golang
package main
import "fmt"
// 料理を作るI/F
type Cooker interface {
Cook() string
}
// 塗るI/F
uname -a
@hzm-s
hzm-s / gist:9908372
Created April 1, 2014 05:46
MSS Interaction
#logs
@timeline = Timeline.find(current_user)
@timeline.each do |activity|
p activity.date
p activity.balance
p activity.outgo
p activity.income
end
@hzm-s
hzm-s / group_by.pl
Created February 13, 2014 09:18
PerlでRubyのEnumerable#group_by
sub group_by(&@) {
my $block = shift;
my %result;
for (@_) {
my $key = $block->($_);
$result{$key} = [] unless exists $result{$key};
push @{ $result{$key} }, $_;
}