Skip to content

Instantly share code, notes, and snippets.

View shugo's full-sized avatar

Shugo Maeda shugo

  • NaCl
  • Matsue, Shimane, Japan
View GitHub Profile
js> function foo (x) {
> function bar () {
> print(x)
> }
> bar()
> }
js> foo(1)
1
puts "hello"
@shugo
shugo / collatz.hs
Created December 10, 2011 06:15
Collatz sequence
collatz' :: Int -> Maybe (Int, Int)
collatz' 0 = Nothing
collatz' 1 = Just (1, 0)
collatz' n
| n `mod` 2 == 0 = Just (n, n `div` 2)
| otherwise = Just (n, 3 * n + 1)
collatz :: Int -> [Int]
collatz n = unfoldr collatz' n
@shugo
shugo / parse.y.diff
Created December 10, 2011 14:21
error message for BEGIN
diff --git a/parse.y b/parse.y
index 3061ed8..1cae0e5 100644
--- a/parse.y
+++ b/parse.y
@@ -686,7 +686,7 @@ static void token_info_pop(struct parser_params*, const char *token);
%type <node> words qwords word_list qword_list word
%type <node> literal numeric dsym cpath
%type <node> top_compstmt top_stmts top_stmt
-%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
+%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
@shugo
shugo / hello.hs
Created January 5, 2012 16:25
test
main = putStrLn "hello, world"
@shugo
shugo / Consumer.hs
Created January 5, 2012 16:43
Network.HTTPでHTTPSが使えないの知らなくて書いて、結局捨てたコード
module Whiteye.OAuth.Consumer (
Consumer (..),
oAuthRequest
) where
import Data.List
import Control.Applicative
import Network.URI
import Network.HTTP
import qualified System.Time as Time
@shugo
shugo / git-bugspots-error.txt
Created January 6, 2012 05:19
git bugspotsしたらエラーが:(
/home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/internal/loose.rb:108:in `unpack_object_header_gently': undefined method `>>' for "x":String (NoMethodError)
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/internal/loose.rb:56:in `get_raw_object'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/internal/loose.rb:32:in `[]'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/repository.rb:84:in `block in get_raw_object_by_sha1'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/repository.rb:83:in `each'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/repository.rb:83:in `get_raw_object_by_sha1'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/repository.rb:334:in `walk_log'
from /home/shugo/local/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git-ruby/repository.rb:287:in `log'
from /home/shugo/local/lib/ruby/gems/1.9.
@shugo
shugo / bugspots.txt
Created January 6, 2012 05:41
READMEが一番バグが多かった
Scanning . repo
Found 4 bugfix commits, with 2 hotspots:
Fixes:
- fixed a comment.
- fixed indentation once more.
- fixed indentation.
- added README.markdown.
Hotspots:
@shugo
shugo / constants.rb
Created January 12, 2012 07:10
How to invoke Module#constants on Module itself
# Module.constants returns constants accessible at the place where the
# method is called.
class A
X = 1
p Module.constants.include?(:X) #=> true
end
# Module#constants returns constants defined in the receiver. However,
# you need a trick to invoke Module#constants on Module itself.
p Module.instance_method(:constants).bind(Module).call #=> []
@shugo
shugo / round_robin_heap.rb
Created January 13, 2012 02:51
round-robin heaps in Ruby
require "pp"
class Tree
def insert(value)
BlueFork.new(value, Null, Null).merge(self)
end
def merge(other)
other._merge(self)
end