Saturday, February 27, 2010

Ruby 1.9.2dev has passed RubySpec

I know it by Nick Sieger's tweet, "Ruby 1.9.2dev has passed RubySpec"! See the post on the ruby-core below.

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/28329

Thursday, February 25, 2010

Start/End of String/Line regular expression in Ruby

Regular expressions about "Start of string", "Start of line", "End of line" and "End of String" are difficult and complex because of differences in each programming languages. So I try to explain Ruby's case visually.

There is a multi-line string like below:
Title

one
two, three, four


five, six, seven
eight, nine, ten



And each regular expressions (\A, ^, $, \Z, \z) match like below:


Title

one
two, three, four


five, six, seven
eight, nine, ten

Monday, February 22, 2010

Qt 4.6.2 was released

In MWC, Qt 4.6.2 was released. This release supports more mobile devices and more mobile features. I download and install Qt 4.6.2 SDK (LGPL) from here.

Friday, February 19, 2010

MariaDB can be worked with #3: rubymysql

(continued from phosphorescence: MariaDB can be worked with #2: QMYSQL)

ruby-mysql also refers libmysql.

i.e., any applications using ruby-mysql can work with MariaDB. So I check it with simple Ruby on Rails application. Both migration and server application work.

Tuesday, February 16, 2010

MariaDB can be worked with #2: QMYSQL

(continued from phosphorescence: MariaDB can be worked with #1: MySQL workbench)

Qt's database driver for MySQL is named "QMYSQL". It refers libmysqlclient.

And, of course, it works correctly. I re-run the sample program of C++ GUI Programming with Qt 4 chapter 13.

Saturday, February 13, 2010

MariaDB can be worked with #1: MySQL workbench

As I expressed in phosphorescence: Installing MariaDB on openSUSE 11.2, MariaDB uses some libraries from MySQL - libmysqlclient16 and llibmysqlclient_r16. This means MySQL related program already existing can work that is using either library and is never using other libraries.

For example, MySQL Workbench can work with MariaDB.

Wednesday, February 10, 2010

Comprime and Residue class group

Ruby has the library 'prime'. And I create sample program to handle "coprime" and "residue class group".

residue.rb
class Integer

  # return all coprimes of self
  def coprimes
    if self.prime?
      (1...self).to_a
    else
      [1] + (Integer.each_prime(self).to_a - self.prime_division.transpose[0])
    end
  end
  
  # Is self comprime with argument number?
  def coprime_with?(other)
    coprimes.include?(other)
  end

  # return reduced residue class group
  def reduced_residue_class_group
    z_mz(coprimes)
  end

  # return residue class group
  def residue_class_group
    z_mz(0...self)
  end

  private
  def z_mz(numbers)
    group = numbers.inject([]) do |result, i|
      result << numbers.inject([]) do |inner_result, j|
        inner_result << ((i * j) % self)
      end
    end

    # change behavior of to_s to multiple group with formatted spaces
    def group.to_s
      digit = self.flatten.max / 10 + 1
      self.inject('') do |result, array|
        result << array.inject('') do |inner_result, item|
          inner_result << ("%#{digit + 1}d" % item)
        end << "\n"
      end
    end

    group
  end
end

$ irb -r 'residue.rb'
irb(main):001:0> 12.coprimes
=> [1, 5, 7, 11]
irb(main):002:0> 12.coprime_with?(5)
=> true
irb(main):003:0> 12.coprime_with?(6)
=> false
irb(main):004:0> puts 12.residue_class_group.to_s
  0  0  0  0  0  0  0  0  0  0  0  0
  0  1  2  3  4  5  6  7  8  9 10 11
  0  2  4  6  8 10  0  2  4  6  8 10
  0  3  6  9  0  3  6  9  0  3  6  9
  0  4  8  0  4  8  0  4  8  0  4  8
  0  5 10  3  8  1  6 11  4  9  2  7
  0  6  0  6  0  6  0  6  0  6  0  6
  0  7  2  9  4 11  6  1  8  3 10  5
  0  8  4  0  8  4  0  8  4  0  8  4
  0  9  6  3  0  9  6  3  0  9  6  3
  0 10  8  6  4  2  0 10  8  6  4  2
  0 11 10  9  8  7  6  5  4  3  2  1
=> nil
irb(main):005:0> puts 12.reduced_residue_class_group.to_s
  1  5  7 11
  5  1 11  7
  7 11  1  5
 11  7  5  1
=> nil

Monday, February 8, 2010

Installing MariaDB on openSUSE 11.2

In the first day of this month, the first stable version of MariaDB was released. MariaDB is the OSS relational database forked from MySQL. On this download page, there sources for Linux and Solaris and binary packages for Ubuntu. openSUSE users of course can build from this sources. But if you install from binary RPMs, read the instructions below:

Friday, February 5, 2010

Oracle will keep on technologies of NetBeans only, but others are not!?

One week ago, as you know, Oracle had completed the acquisition of Sun Microsystems, and started to integrate both all technologies. In Japanese news source, OpenOffice.org goes independent GBU of Oracle, but NetBeans and Glassfish will be kept on only technologies, but others (product and its name and so on) will be integrated to "Oracle Fushion" series.

Tuesday, February 2, 2010

Pan WebView

I add a sample program to my graphics-dojo clone repository - Pan WebView. Almost issues of this program are similar to ones of phosphorescence: Flickable color list, but there is new issue and easy solution.

It is cursor setting. Original C++ program set the Constant Qt::OpenHandCursor, but QtRuby must set like below:
Qt::Application::override_cursor = Qt::Cursor.new(Qt::OpenHandCursor)

Full code is here and execution result is below: