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

Sunday, April 26, 2009

git-mv completion

Since one day, I've been unable to complete argument filenames of git-mv. So I've had to mv filename1 filename2 and then add git at the head of the command. It's too much of a bother.

Today I found the casus of trouble and its solution. Put the following patch:

--- /usr/share/zsh/4.3.4/functions/_git.orig 2009-04-26 14:53:11.000000000 -0700
+++ /usr/share/zsh/4.3.4/functions/_git  2009-04-26 14:53:28.000000000 -0700
@@ -1160,7 +1160,7 @@
 __git_files () {
   local expl files

-  files=("${(@f)$(git-ls-files 2>/dev/null)}")
+  files=("${(@f)$(git ls-files 2>/dev/null)}")
   if (( $? == 0 )); then
     _wanted files expl 'index file' _multi_parts $@ - / files
   else

Obviously, the cause was the change of git subcommands' usage.

enjoy!

Saturday, April 25, 2009

Refactored kmdsbng's opt_simple

http://github.com/ujihisa/opt_simple/tree/master

The patch summary here:

$ git diff dabfeb66321e01ed59a8127ffe545ff01ae8ca4d..HEAD -- lib

diff --git a/lib/opt_simple.rb b/lib/opt_simple.rb
index 1810d3d..b917afb 100644
--- a/lib/opt_simple.rb
+++ b/lib/opt_simple.rb
@@ -5,36 +5,27 @@ class OptSimple

   def initialize(spec, argv)
     parser = OptionParser.new
-    spec.each{|s|
-      main_option_name = option_names = nil
-      if (!(s.kind_of? Array))
-        s = [s]
-      end
+    spec.each do |s|
+      s = [s] unless s.kind_of? Array

-      option_names = s[0..1].select{|o| o =~ /^-/}.map{|o| o.split[0].gsub(/^(\-)+/, '').gsub(/-/, '_')}
-      main_option_name = option_names.shift
+      main_option_name, *option_names = s[0..1].select {|o| /^-/ =~ o }.
+        map {|o| o.split[0].gsub(/^(\-)+/, '').gsub('-', '_') }

-      # regist parser
-      parser.on(*s){|v|
+      # register parser
+      parser.on(*s) {|v|
         instance_variable_set('@' + main_option_name, v)
       }

       # define getter
-      self.class.class_eval {
-        define_method(main_option_name) {
-          instance_variable_get('@' + main_option_name)
-        }
-      }
+      self.class.__send__(
+        :attr_reader, main_option_name.to_sym)

       # define getter alias
-      option_names.each{|s|
-        self.class.class_eval {
-          alias_method s, main_option_name
-        }
-      }
-    }
+      option_names.each do |s|
+        self.class.__send__(
+          :alias_method, s, main_option_name)
+      end
+    end
     @remain = parser.parse(argv)
   end
 end
-
-

KansaiRubyWorkshop++

Thursday, April 23, 2009

Now Rubygems Can Generate a Graph

RubyGems 1.3.2 now has plugins feature. The gem plugins feature is like subcommands of git, and is able to be added easily.

For example, rubygems can show a dependency graph of installed gem packages. Let's try!

$ sudo gem update --system
$ sudo gem install graph
$ gem graph

An error occured. I need graphviz library. OK.

$ sudo port install graphviz
--->  Fetching urw-fonts
--->  Attempting to fetch urw-fonts-1.0.7pre44.tar.bz2 from http://distfiles.macports.org/urw-fonts
--->  Verifying checksum(s) for urw-fonts
--->  Extracting urw-fonts
--->  Configuring urw-fonts
--->  Building urw-fonts
--->  Staging urw-fonts into destroot
--->  Installing urw-fonts @1.0.7pre44_0
--->  Activating urw-fonts @1.0.7pre44_0
--->  Cleaning urw-fonts
--->  Fetching graphviz
--->  Attempting to fetch graphviz-2.22.2.tar.gz from http://distfiles.macports.org/graphviz
--->  Verifying checksum(s) for graphviz
--->  Extracting graphviz
Error: On Mac OS X 10.5, graphviz 2.22.2 requires Xcode 3.1.2 or later but you have Xcode 3.1.
Error: Target org.macports.extract returned: incompatible Xcode version
Error: Status 1 encountered during processing.

omg

Tuesday, April 21, 2009

Noooooooooo

After a struggle for two hours, I just found an ommision of the ! of shebaing. The first line of code was treated as just a comment.

Saturday, April 11, 2009

Why Ruby doesn't have the IO.write method

While Ruby has a class method IO.read to read the whole contents of a file, Ruby doesn't have the corresponding method IO.write. The reason why Ruby doesn't have the class method IO.write is already mentioned by Matz in Japanese.

Q. Is there any positive reason why IO.write isn't there even though IO.read is there?

A. No. I have only the negative reason that IO.write won't be used as many times as IO.read. I'm also afraid the method causes users to waste memories. I ignore the symmetrical property.

I also found another disscussion about it in English.

Although Ruby doesn't have IO.write, we can define it in just three lines. That's OK. But, it's laborious to define it every time we need IO.write or to write equivalent one. There must be shortcuts.

I searched that from Rails' ActiveSupport::CoreExtentions and Merb's Extlib. There are a lot of utility methods, but there isn't IO.write! Does nobody feel bothered by it?

Sunday, April 5, 2009

Move to Vancouver, Canada from Osaka, Japan

I took some photos and uploaded them:

At KIX

Kansai Airport Kansai Airport Kansai Airport

Ate Japanese lunch at NRT

Narita Airport

That was very expensive. 1,000 yen!

Flight across the Pacific

Seattle Airport

That monitor system was broken. Even when we were arriving Seattle Airport, the monitor showed us that we were now on the Pacific.

Seattle! (SEA)

Seattle Airport

It was rainy that day. Seattle was a nice wooded town.

Ate breakfast at Seattle Airport

Seattle Airport

I ate Asian Veggie Wrap with coke. It was not bad.

And finally I arrived in Vancouver. The airport was badly crowded. I had to wait for the immigration for two hours! I never want to get lined up the immigration queue again.

Our new house

Vancouver

I was surprised that our new house was located in a such place. The view seemed very nice even if it was rainy.

The first day was rainy. The second day was cloudy. Since third day, it has been sunny! yeah!

Vancouver Vancouver Vancouver

We can see the Olympic Stadium from the window of our room.

Saturday, April 4, 2009

Comparison between Japan, Canada and the US about the MBA price

  • Japan: 214,800yen

  • Canada(tax 12%, 1$ = 80yen): 159,920+19,190 = 179,110yen

  • US(tax 8.5%, 1$ = 100yen): 179,900+15,291= 195,191yen

Canada is the country that sells the cheapest MacBook Air!

Followers