Al Hoang

September 8, 2009

Getting Ruby 1.9.1p243 to work on OS X 10.5.8 with Japanese input support on irb

Filed under: fixes, japan, osx, programming, ruby — hoanga @ 3:47 am

Awhile back I installed Ruby 1.9.1 in such a way as to co-exist with my current Ruby installation [1], [2] (I should use rvm [3] these days…)

However, one issue that cropped up during an IRB session was I could not copy and paste Japanese characters into the IRB repl. This is very very painful for my day to day use with Ruby (Imagine not being able to use the ‘|’ character while writing UNIX pipelines).

Below is an example of me trying to enter the character あ into IRB and watching it fail.

$ irb
irb(main):001:0> ab = "?"    <---- Tried entering the character あ
SyntaxError: (irb):1: invalid multibyte char (UTF-8)
(irb):1: unterminated string meets end of file
from /usr/local/bin/irb19:12:in `'

After a lot of head scritching I was able to narrow it down to something with readline:

$ irb --noreadline
irb(main):002:0> ab = "あ"
=> "あ"
irb(main):003:0>

After some more digging into the issue. The root cause seems to be the lack of GNU readline. By default, Ruby will link in the system installed readline library on OS X which is called editline [4]. Unfortunately, editline does not support UTF8 or multi-byte character sets which makes this a no-go for daily usage.

Most of the other references suggest downloading readline from source and installing into /usr/local however I believe this defeats the purpose of using something like MacPorts. After a bit of finagling I found that this is the invocation to get things working.

wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/rub...
tar xvzf ruby-1.9.1-p243.tar.gz
cd ruby-1.9.1-p243
# Don't trust MacPorts version of autoconf because it somehow nuked the
# --with-readline-dir option
/usr/bin/autoconf
./configure --with-readline-dir=/opt/local --enable-shared --program-suffix=19 --enable-pthread
make
sudo make install

I have it wrapped up in a script which you can see here.

References

[1] http://wonko.com/post/how-to-compile-rub…
[2] http://frozenplague.net/2009/01/ruby-191…
[3] http://rvm.beginrescueend.com/
[4] http://thrysoee.dk/editline/

February 27, 2009

Nihon Town

Filed under: japan — hoanga @ 8:04 am

Nice town…

Thanks Pink Tentacle

December 31, 2008

Zoorasia and the Yokohama Greenery Foundation. It’s not all Dogs & Demons

Filed under: japan — hoanga @ 7:53 am

If you have ever heard of Alex Kerr and have read his book Dogs & Demonsyou would think much less of Japan as a country. Some of the things in that book refer to many pork-barrel politic government projects that include such monstrosities as huge concrete damns in the middle of nowhere. From personal experience, I have seen a couple of these concrete machinations when I did some hiking just outside of the Tokyo area. Very mind boggling indeed.

However, not all government projects are pork-barrel political showcases (I hope). One interesting project located in Yokohama is called Zoorasia. Zoorasia is a large zoo with a multitude of animals from around the planet. The Zoo itself is divided into 7 areas at present that match certain geographic areas of the world. In each area are a set of representative animals from that region. For example there is an Oceanian Grassland area and one of the prominent animals there are kangaroos.

The zoo is run by the Yokohama Greenery Foundation which was established as far back in the mid 70s. Back then it originally called itself the (sorry if I mistranslate here…) The Yokohama City Park Foundation (Nin-idantai Yokohama-shi Kouen Kyoukai – 任意団体横浜市公園協会) however renamed itself to the Yokohama Greenery Foundation in 1984.

The zoo itself is a little inconvenient to reach by public transportation (aka it takes awhile by bus and train). But from what I have seen the park is extremely nice with a very reasonable entrance fee (600Y). One thing I do wonder is whether Zoorasia can support itself in the long run since it is a great resource for families around the area. It would be a shame if maintaining such a nice zoo is actually not sustainable with the budget that they have. But it does seem that Zoorasia’s parent organization has some backing by the Yokohama government which I hope is a good thing. (At least I can feel some of the tax I pay is going to something interesting)

References (In Japanese)

December 22, 2008

On the origins of the name Akihabara

Filed under: geek, japan — hoanga @ 9:37 pm

Akihabara as many people in Japan know was originally the home for buying electronic goods in the Tokyo area. It still holds that reputation however the Anime Otaku crowd have changed the face of Akihabara to also accomodate their needs and desires.

One thing that is interesting is the origin of place name Akihabara. A friend of mine has an excellent post here

Read more!

November 15, 2008

Japanese declining population rates? How come I can’t find a doctor?

Filed under: gripe, japan, stupid — hoanga @ 7:27 am

少子化 is the term used to describe the shrinking population in Japan and the many hardships that will bring to the country economically. I remember hearing some analyses on why this is happening on a social standpoint. I’ve not heard (or really bothered that hard to search for) many proposals on how to fix the problem. However when I read stories like this.

It makes me wonder if some policy makers are out of touch with reality, sometimes.

November 3, 2007

A moment of silence for Prof Jun-ichiro Hagino

Filed under: japan, tech — hoanga @ 3:11 am

I ran across the news on the passing
of Professor Jun-ichiro Hagino aka ‘Itojun’.

Although I never knew ‘Itojun’ personally I
was always impressed by someone who was able
to hold commit rights to the main 3 families
of the *BSD trees and make a real difference
in trying to push out the adoption of IPv6 out
far and wide.

My understanding is that parts of the kame stack
that he had a major hand in were at one point
used as the basic for the IPv6 stack in the Linux
kernel. I’m not sure if that is the case anymore
with the IPv6 stack in Linux but I thought that
was an interesting tidbit in Linux networking
implementation history.

May he rest in peace.

December 14, 2006

Getting a Ruby C extension to compile on Windows

Filed under: japan, ruby — hoanga @ 12:39 am

The Programming Ruby book is one of those must have references if you’re going to program Ruby. I still use it all the time when I’m looking up information on Ruby. One thing I’ve started playing with is getting a C extension to work with Ruby. Chapter 21 of Volume 2 of Programming Ruby gives you a great example for writing a C extension from scratch and getting it to compile and work in a UNIX-based environment however it falls short on handholding you through the Windows process. Here’s my notes on what you need:

Executive Summary

  1. Install Visual Studio Express or some other Visual C++ variant
  2. Install the Platform SDK (You need this if you want windows.h and you DO)
  3. Make minor changes in Ruby config.h (Not necessary for all versions of Visual Studio)
  4. Write the MyTest code and extconf.rb file from the book
  5. Run ruby extconf.rb to generate a nmake-based Makefile
  6. Startup a command prompt with the SDK environment variables set
  7. Run nmake to compile the library
  8. Done!

The detailed version

Download Visual Studio

Unless you’re using cygwin or mingw as your compiler you’ll probably want to get Visual Studio. The latest incarnation is Visual Studio 2005 which is a free download. I’ve found that it’s a pain to find the right URL to download it from on Microsoft but that’s Microsoft for you.

Download the Windows Platform SDK

Since the Windows version of Ruby ties in with many Win32 libraries it’s necessary to get the Platform SDK. If you DON’T download it you will see strange error messages when trying to compile your Ruby extension such as this:

c:\ruby\lib\ruby\1.8\i386-mswin32\win32/win32.h(32) : fatal error C1083: Cannot
open include file: 'windows.h': No such file or directory
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\cl.EXE"' : return code '0x2'
Stop.

windows.h is NOT included by default in Visual Studio 2005 (but I believe it is in older versions of Visual Studio) so you need the platform SDKs to get the right development libraries. While it would be nice if the C-based version of Ruby could easily hook into the .Net platform, this would probably require significant hacking the mkmf library in Ruby to get it to work transparently. I doubt that will happen soon.

Once again, I found Microsoft’s website really annoying to navigate in order to try to find the Platform SDK so you might want to click here then make sure you have the latest platform SDK (As of this writing the latest was R1)

Tweak $RUBY_HOME/lib/ruby/1.8/i386-mswin32/config.h

For some versions Visual Studio (noteably Visual Studio 2005), the config file located in $RUBY_HOME/lib/ruby/1.8/i386-mswin32/config.h (Usually $RUBY_HOME installs to C:/Ruby) will require a tweak to allow compilation. Or you could rebuild Ruby from scratch yourself but I prefer to use the All-in-one installer. In the config.h file delete or comment out the following lines:

#if _MSC_VER != 1200
#error MSC version unmatch
#endif

Finally! Let’s compile it already

Okay now you’re ready to finally to actually compile your code. In order to get all the environment variables set properly you might want to launch a command prompt from the shortcuts the Platform SDK makes in the Start Menu then make sure to run vsvars32.bat from Visual Studio’s directory (Usually in C:\Program Files\Microsoft Visual Studio 8\VC\bin). Now with that all set you can finally compile something! (whew!):

C:\cygwin\home\foo\exttest>ruby extconf.rb
creating Makefile

C:\cygwin\home\foo\exttest>nmake

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -nologo -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/ruby/lib/ruby/1.
8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6  -c -Tcmy_test.c
cl : Command line warning D9035 : option 'Og-' has been deprecated and will be r
emoved in a future release
cl : Command line warning D9002 : ignoring unknown option '-G6'
my_test.c
        cl -nologo -LD -Femy_test.so my_test.obj msvcrt-ruby18.lib  oldnames.lib
 user32.lib advapi32.lib wsock32.lib  -link -incremental:no -debug -opt:ref -opt
:icf -dll -libpath:"c:/ruby/lib" -def:my_test-i386-mswin32.def -implib:my_test-i
386-mswin32.lib -pdb:my_test-i386-mswin32.pdb
   Creating library my_test-i386-mswin32.lib and object my_test-i386-mswin32.exp

C:\cygwin\foo\exttest>irb
irb(main):001:0> require 'my_test'
=> true
irb(main):002:0> test = MyTest.new
=> #

References

November 28, 2006

Linux powered Mp3 player

Filed under: japan, linux — hoanga @ 10:55 am

About time…


Linux Mp3 Player


Got to wait until Feb 2007 to get your hands on one though. Hope it doesn’t cost too much

November 14, 2006

PS3 Launch a mess in Japan?

Filed under: japan — hoanga @ 4:41 am

Here’s something you probably won’t read in the local Japanese newspapers:

This is the true face of the PlayStation 3 debut in Japan. Hardcore gamers are not here waiting in line overnight, buying a first-run PS3, and running home to play some good old next-gen gaming. Rather, opportunistic Japanese businessmen have the largest presence, hiring poor Chinese men and women to wait in line for a PS3

Frankly, this is yet another blunder for Sony but I bet it will be silenced by the Japanese media so the only people who will know about it are:

  • People reading this blog (All 3 of you!)
  • Gamers not in Japan
  • All the Kotaku.com readers

A very sad thing this is. It really makes me wonder whether it’s even fun anymore to sit in line for these launch events if some enterprising people are just going to hire some homeless folk to wait in line for them. Anyways, if you’re reading this. Spread the word far and wide, please.Read it yourself on Kotaku

November 1, 2006

Onna Otaku

Filed under: japan — hoanga @ 10:16 am

January 1, 2004

Voice over IP adoption in Japan

Filed under: japan, tech — hoanga @ 11:05 am

Happy New Year’s all. Slashdot linked to an article on Voice over IP Adoption in Japan.

I’ve looked over the pricing structure of Voice over IP and found it not that useful if you’re a light phone caller (me) as you must factor in the costs of an Internet connection monthly which costs around 5000Y or so for a broadband connection that can support VoIP practically. On top of which you are topped a surcharge monthyl fee to activate Voice over IP and of course you are charged for usage time. After doing the math out, a phone line is slightly cheaper. . . go figure.

Link to Story

December 21, 2003

Fleep

Filed under: japan — hoanga @ 3:19 am


It’s about a boy who wakes up in a telephone booth which has been mysteriously selaed in an envelope of concrete. Using only the contents of his pockets (two pens, a paperback novel, three coins and 20 ft of unwaxed dental floss) our hero must fashion and execute an escape plan before he runs out of oxygen.

December 17, 2003

Japanese homeless beat up by kids?

Filed under: japan — hoanga @ 9:21 am

There’s an article on the New York Times on the Japanese homeless and some of the problems they have to deal with. Many of them are out of work salary men who through some unfortunate twist lost their jobs and became homeless due to not being able to find a replacement job. It seems teen boys and young boys gang up and then go out hunting for them and beat them up.

Ick. They’re justification? “We’re cleaning up the garbage.” I’m not a fan of people not attempting to be productive to society but I’m not sure about outright hostility. That gets me incensed. Preying on the weak is a poor excuse. A better way would be to help find ways to educate these people and try to put wind in their sails again so they can float in wild ocean of life.

Link to story

December 13, 2003

Why do phone and cable companies make it so hard to…

Filed under: gripe, japan, stupid, tech — hoanga @ 11:32 pm

Why is that everyime I try looking on a phone or cable companies website for information for their brick & mortar stores I can’t find anything? It requires seaching and searching. Instead they’ve jumped on this notion of “Use the Online Services!!!” That’s great when things are workign as they planned. But how abuot when they aren’t? That’s where interacting with a human in person can be much more clarifying about the problem.

December 12, 2003

Why localization and internationalization is important

Filed under: gripe, japan, programming, tech — hoanga @ 10:00 pm

This article is mainly covering the Open Source movement and its local heroes. But this quote really caught my eye:


“An English-only or even an English-mainly policy necessarily condemns most people, and thus the country as a whole, to a permanent state of mediocrity, since people are unable to be spontaneous, creative and self-confident if they cannot use their first language,”

Most Americans probably won’t even think about this at all. The ones that probably really get it are ones that have spent some time abroad and have to use a computer that has been localized or speak another language at home. All of a sudden you can’t read the menus and dialogues and many of the interactions with the computer. You’re a little lost in what to do. Now imagine trying to ‘get work’ done in this environment. This is what many many people deal with when having to deal with a non-localized computer. On top of dealing with computing for the first time they are forced to use a language they have no internal sense of.

Link to story

Powered by WordPress

Protected by AkismetBlog with WordPress