Skip to content

Instantly share code, notes, and snippets.

View yuroyoro's full-sized avatar
🍣
🍣

しいたけ yuroyoro

🍣
🍣
View GitHub Profile
// FizzBuzz は時代遅れらしいので FibBuzz はどうでしょう #fibbuzz | cod.note : http://codnote.net/2011/10/13/fibbuzz/
// 163bytes
val x:BigInt=1
val f:Stream[BigInt]=x#::f.scanLeft(x){(a,b)=>a+b}
for(i<-f take 100;j=i-1)println(if(i%3*i%5>0)i else"Fizz"*(j%3/2).toInt+"Buzz"*(j%5/4).toInt)
//152bytes
val x:BigInt=1
for((i,_)<-(0 to 98).scanLeft((x,x)){case((b,c),a)=>(c,b+c)};j=i-1)println(if(i%3*i%5>0)i else"Fizz"*(j%3/2).toInt+"Buzz"*(j%5/4).toInt)
@yuroyoro
yuroyoro / Fate.scala
Created December 2, 2011 14:20
Scalaでも(Fate/Zero) や (Fate/stay night) でメソッド呼べる > @mnzktw 「(Fate/Zero) や (Fate/stay night) でJava のメソッドが呼べそうな気がしたらきっとあなたは clojurian」
scala> trait Term { def night = () }
defined trait Term
scala> object Zero extends Term
defined module Zero
scala> object stay extends Term
defined module stay
scala> object Fate {
Scanning . repo
Found 12 bugfix commits, with 43 hotspots:
Fixes:
- fixed Author at tips diplays commiter.
- fixed #5 Rendered duplicate commit node.
- fixed #4 related branche's commit are too many and rendering are too slow.
- fixed for #3 script error occurred when commit message includes double quote.
- fixed the issue link's string lacked '#'.
- fixed XHRequest had been sent to the server when the branch node was clicked.
@yuroyoro
yuroyoro / named_let.rb
Created January 6, 2012 14:08
rspecのlet(:name)で定義したオブジェクトのto_sとinspectの値を、:nameに変更する
# rspecのlet(:name)で定義したオブジェクトのto_sとinspectの値を、:nameに変更する
#
# named_let(:foo){ Object.new } ってやると、
# foo.to_sが"foo"になる
#
# named_let(:foo,"label for display"){ ... } って第二引数に別名を渡すと、
# その別名が、to_s/inspectの値になる
#
# subject should == fooとか書いたときの出力が
# ふつうは
@yuroyoro
yuroyoro / gist:1604839
Created January 13, 2012 05:49 — forked from j5ik2o/gist:1518723
こんな構文で階層型のログ出力をしたい
def connect = {
import LogOps._
log("connect") { implicit ctx => // connect start
// ... 何かの処理 ...
println("in connect")
log("login") { implicit ctx => // connect : login start
// ... 何かの処理 ...
println("in login")
@yuroyoro
yuroyoro / have_same_attributes.rb
Created January 28, 2012 12:14
have_same_attributes : RSpec用Custom Machter。ActiveRecord/ActiverResrouce/Hashなどをゆるふわくmatchさせる
# Rspec用のCustom Matcher
#
# attributesメソッドを持つオブジェクト同士やHashを再帰的にmatchさせる
#
# ActiveRecord/ActiveModel/ActiveResrouce/Hashなどをゆるふわく
# 一致するか調べる。例えば、StringとSymbolは区別しないし、[]や{}やnilは同一視する。
#
# it { should have_same_attributes(hash) }
# it { should have_same_attributes(:foo => 1,:bar => 2) }
#
@yuroyoro
yuroyoro / ognl.rb
Created January 31, 2012 10:12
RubyでOGNLっぽく、文字列で表現されたプロパティにアクセスするための適当なナニか
#!/usr/bin/env ruby
# RubyでOGNL(Object Notation Graph Language)っぽく、
# 文字列で表現されたプロパティにアクセスするための
# 適当なナニか。
#
#
# Ognl.new('foo_string').apply(foo)
# => object notation graph language!!
#
@yuroyoro
yuroyoro / propertiate.rb
Created February 10, 2012 07:37
hash = {:foo => 'bar'} なHashを、hash.fooのようにアクセスできるようにする
# This class extends Hash, it'll be able to access value like attribute acccessors.
#
# examples)
#
# hash = { :foo => "oppai", :bar => "ヽ(*゚д゚)ノ<カイバー" }
# => {:bar=>"ヽ(*゚д゚)ノ<カイバー", :foo=>"oppai"}
#
# phash = hash.propertiate
# => {"foo"=>"oppai", "bar"=>"ヽ(*゚д゚)ノ<カイバー"}
#
@yuroyoro
yuroyoro / self_type_annotaion_emuration_in_ruby.rb
Created March 14, 2012 01:32
Scalaのself-type-annotationのように、moduleがincludeされる先の型について、制約を記述する方法
[1] pry(main)> class Foo; end
=> nil
[4] pry(main)> module FooMixin
[4] pry(main)* def self.included(base)
[4] pry(main)* raise TypeError unless base <= Foo
[4] pry(main)* end
[4] pry(main)* end
=> nil
[5] pry(main)> class Bar < Foo
[5] pry(main)* include FooMixin
class Foo
def public_send_to_self(method_name)
self.public_send(method_name)
end
def send_to_self(method_name)
self.send(method_name)
end
def call_hoge