Monday, March 29, 2010

External iterator for Ruby 1.9

Until Ruby 1.8, there was only internal iterator. But from Ruby 1.9, external iterator comes.

external_iterator.rb
array_1 = %w{1 2 3 4 5 6 7 8 9}
array_2 = %w{a b c d e f g h i}

external_iterator_1 = array_1.each
external_iterator_2 = array_2.each

begin
  while (element_1 = external_iterator_1.next) and
    (element_2 = external_iterator_2.next)
    puts "#{element_1} #{element_2}"
  end
rescue StopIteration
  puts 'External iterator has finished'
end
Let's check!
> ruby external_iterator.rb
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
External iterator has finished

Friday, March 26, 2010

Learn the QML #1

Let's start the "Hello World" sample straightforwardly - using QtCreator 2.0.0 tech preview.

At first create the QML project with wizard.

At second, switch the IDE in "project" mode, then set "QML Viewer" and "Main QML File". "QML Viewer" is executable file qml in your Qt 4.7.0's bin directory.

At last, launch the QML widget from IDE.

Wednesday, March 24, 2010

QtCreator 2.0.0 Technology Preview is released

QtCreator 2.0.0 Technology Preview is also released at the same time when Qt 4.7 Technology Preview is released. It needs Qt 4.7.0 or later.

Normally, you can download installer from here and can install with it.
# chmod +x qt-creator-linux-x86-opensource-2.0.0-alpha1.bin
# ./qt-creator-linux-x86-opensource-2.0.0-alpha1.bin
But some CJK font users need more instructions as I described in this post.

Monday, March 22, 2010

Ruby 1.9.2 release plan is unveiled

1 week ago, in ruby-core mailing list, Release plan of Ruby 1.9.2 is unveiled.
- 31 Mar. freeze the spec
- 30 Apr. freeze the code
- 31 May. release 1.9.2-preview2
- 30 Jun. release 1.9.2-rc
- 31 Jul. release 1.9.2-p0

Friday, March 19, 2010

Appendix for Qt 4.7 Technology Preview is released

If you are CJK font user, and its font has incorrect behavior for "Global Advance Width", phosphorescence: Qt 4.7 Technology Preview is released is not enough. The width of glyphs is too wide for ASCII characters. It's me too.

There are hints in Japanese Qt mailing list. I try to summarize and translate to English, to fix the width of glyphs correctly, we should set FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH on in corresponding source. For instance, at Qt 4.7 Technology Preview, We set at once in src/gui/text/qfontengine_ft.cpp file:

qfontengine_ft.cpp.diff
622c622
< default_load_flags = 0;
---
> default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;

Then I rebuild Qt 4.7 Technology Preview, and succeed with correct font width.

Tuesday, March 16, 2010

Qt 4.7 Technology Preview is released

5 days ago, Qt 4.7 Technology Preview was released. I download it from here, then build like below:

# ./configure -declarative -optimized-qmake -nomake demos -nomake examples \
-no-qt3support -no-gtkstyle -system-sqlite -qt-sql-sqlite \
-opensource -prefix /opt/Qt-4.7.0
# make
# make install
Check with launching Qt Designer.


In this time, I enable sqlite3 driver and QML, and disable Qt3 support, GTK style, demos and examples. It takes about 3 hours.

Saturday, March 13, 2010

openSUSE Connect

I had known in openSUSE weekly news (in Japanese edition), openSUSE Connect has been launched.

It's the repository portal for openSUSE community built on gitorious.

Thursday, March 11, 2010

Design Patterns in Ruby

I have started reading "Design Patterns in Ruby". The cover of English edition is below:

But I bought Japanese Edition. Its cover is below:

Now I'm reading Chapter 1 yet.

Monday, March 8, 2010

Ruby lambda Puzzle (answer part)

(continued from phosphorescence: Ruby lambda Puzzle (question part))

Answer 1
irb(main):001:0> lambda_a = lambda do |x|
irb(main):002:1*   lambda do |y|
irb(main):003:2*     puts "Hello #{x} #{y}"
irb(main):004:2>   end
irb(main):005:1>   lambda do |z|
irb(main):006:2*     puts "Goodbye #{x} #{z}"
irb(main):007:2>   end
irb(main):008:1> end
=> #<Proc:0x22864c0@(irb):1 (lambda)>
irb(main):009:0> lambda_a.(1).(2)
Goodbye 1 2
=> nil

Answer 2
irb(main):010:0> lambda_b = lambda do |x|
irb(main):011:1*   lambda do |y|
irb(main):012:2*     puts "Hello #{x} #{y}"
irb(main):013:2>   end
irb(main):014:1>   lambda do |z, zz|
irb(main):015:2*     puts "Goodbye #{x} #{z} #{zz}"
irb(main):016:2>   end
irb(main):017:1> end
=> #<Proc:0x20c2fe0@(irb):10 (lambda)>
irb(main):018:0> lambda_b.(1).(2)
ArgumentError: wrong number of arguments (1 for 2)
        from (irb):18:in `call'
        from (irb):18
        from C:/ruby-1.9.1/bin/irb:12:in `<main>'

Friday, March 5, 2010

Ruby lambda Puzzle (question part)

In Ruby 1.9.1,

Question 1
irb(main):001:0> lambda_a = lambda do |x|
irb(main):002:1*   lambda do |y|
irb(main):003:2*     puts "Hello #{x} #{y}"
irb(main):004:2>   end
irb(main):005:1>   lambda do |z|
irb(main):006:2*     puts "Goodbye #{x} #{z}"
irb(main):007:2>   end
irb(main):008:1> end
=> #<Proc:0x223d780@(irb):1 (lambda)>
irb(main):009:0> lambda_a.(1).(2)
???

Question 2
irb(main):010:0> lambda_b = lambda do |x|
irb(main):011:1*   lambda do |y|
irb(main):012:2*     puts "Hello #{x} #{y}"
irb(main):013:2>   end
irb(main):014:1>   lambda do |z, zz|
irb(main):015:2*     puts "Goodbye #{x} #{z} #{zz}"
irb(main):016:2>   end
irb(main):017:1> end
=> #<Proc:0x1dfd680@(irb):10 (lambda)>
irb(main):018:0> lambda_b.(1).(2)
???

Tuesday, March 2, 2010

OSC Tokyo 2010

In 3 days ago, Open source Conference Tokyo 2010 was held at Meisei-Univ, Tokyo. I attended 3 sessions.