Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Saturday, November 28, 2009

Trying Stomp and Stompserver on Ruby

STOMP: Streaming Text Orientated Messaging Protocol is getting important, particularly for web programmers who need to think scalability. There are Ruby implementations of STOMP, called stomp and stompserver. Here is the brief introduction of them.


$ gem install stomp
$ gem install stompserver

Currently it is reported that stompserver cannot be installed well on ruby 1.9. I don't know why so far.


Get three terminals ready.

[Terminal 1]$ mkdir tmp && cd tmp
[Terminal 1]$ stompserver

[Terminal 2]$ irb -rubygems
> require 'stomp'
>'/a/b') {|m| p m.body }

[Terminal 3]$ irb -rubygems
> require 'stomp'
>'/a/b', 'Hello, world!')

And then check your terminal 2.

stompserver creates etc and log directories on the current directly and opens port 61613.

Thursday, November 19, 2009

I'm Attending RubyConf 2009

Now I'm staying at a hotel near San Francisco Airport where RubyConf 2009 will be held on Nov 19 to 21 and JRubyConf on Nov 22 as well.

As an attendee

This is my first time to attend a conference not in Japan. I had lived in Vancouver, Canada for a half year, so now I can speak and listen English better than last year, but I still feel difficulty in using English, particularly in listening. Also, I'm shy and nervous.

If you find such person, feel free to talk to him. It's me. I may have a nameplate that is written "ujihisa".

As a speaker

I'll talk about Ruby's parser. The presentation will be not for a great Ruby hacker, but for an ordinary programmer.

If you are interested in my presentation, I highly recommend you to build the Ruby trunk in advance. It's easy but takes long time.

$ mkdir ~/rubies
$ svn co (ruby trunk)
$ cd (the directory)
$ ./configure --prefix=$HOME/rubies
$ make
$ make install

As a Japanese

If you are interested in Japanese culture, feel free to ask me about it as well as about Ruby.


Wednesday, November 18, 2009

Playing with JRuby's Parser

Apply this patch to JRuby.

diff --git a/src/org/jruby/lexer/yacc/ b/src/org/jruby/lexer/yacc/
index dd1733e..dc591a2 100644
--- a/src/org/jruby/lexer/yacc/
+++ b/src/org/jruby/lexer/yacc/
@@ -1208,6 +1208,12 @@ public class RubyYaccLexer {
     private int colon(boolean spaceSeen) throws IOException {
         int c =;

+        if (c == '-' && src.peek(')')) {
+          lex_state = LexState.EXPR_BEG;
+          yaccValue = new Token("=>", getPosition());
+          return Tokens.tASSOC;
+        }
         if (c == ':') {
             if (isBEG() || lex_state == LexState.EXPR_CLASS || (isARG() && spaceSeen)) {
                 lex_state = LexState.EXPR_BEG;

Now you can write :-) as => in braces as Hash literals.

$ ./bin/jruby ./bin/jirb
> {1 => 2}
=> {1=>2}
> {1 :-) 2}
=> {1=>2}
> {:aaa => :bbb}
=> {:aaa=>:bbb}
> {:aaa:-):bbb}
=> {:aaa=>:bbb}

This patch is almost same as my previous patch to MRI.

diff --git a/parse.y b/parse.y
index b8d9b59..a592aed 100644
--- a/parse.y
+++ b/parse.y
@@ -7125,6 +7125,11 @@ parser_yylex(struct parser_params *parser)

       case ':':
         c = nextc();
+        if (c == '-' && peek(')') {
+            nextc();
+            lex_state = EXPR_BEG;
+            return tASSOC;
+        }
         if (c == ':') {
             if (IS_BEG() ||
                 lex_state == EXPR_CLASS || (IS_ARG() && space_seen)) {

One Month In Japan

I had been in Japan for a month until yesterday. I went to my parents' home, did things related to my admission to the graduate universities, attended some conferences and workshops, and met many friends.

List of workshops I attended:

  • uuuu

  • Kansai Ruby Workshop #38

  • Vim Workshop #4

  • LiveCoing#7

  • Kansai Ruby Kaigi #2 at Kansai Open Forum 2009

  • "Working Effectively with Legacy Code" Study Group

  • Golang Hackathon

  • xUnit Workshop

  • Tokyo Rails Workshop #45

I made presentations at the workshops, mostly about parse.y of Ruby.

Other events:

  • Professor Konami and his students
  • Big Buddha
  • Hoso Hackathon
  • SVTour Alumni Party
  • Teppan lunch
  • ujihkn
  • Ramen Hackathon
  • Todai Hackathon
  • ujihkn

My Sincerely Friends

I feel too thankful for my sincerely friends to say thank you. I proud them. May luck with you!

Thursday, November 12, 2009

RubyConf 2009 Schedule


My talk "Hacking parse.y" will be on Thursday Nov. 18 which is the first day of RubyConf 2009.

Wednesday, November 4, 2009

Accepting Both Get And Post Method in Sinatra

Whe you would like to accept both GET and POST request with the same block, use the following get_or_post method.


require 'rubygems'
require 'sinatra'

get '/' do

post '/' do


require 'rubygems'
require 'sinatra'

def get_or_post(path, opts={}, &block)
  get(path, opts, &block)
  post(path, opts, &block)

get_or_post '/' do

Sunday, November 1, 2009

4th Vim Workshop at Osaka

Today I attended a workshop about Vim. Originally I started the workshop, and kozo_ni took over from the workshop and the soul.

The number of the attendees were 10, including a person from far Yokohama.

Presentations of the workshop were broadcast on ustream. Some presentations were recorded.