Ruben's blog

Nothing to say

Sublime Text 2 RVM and RSpec

| Comments

Found out about Sublime Text 2 from the Ruby Rogues podcast, and I’m loving it. Although is has been a little problematic to set it up to honor my .rvmrc files and to run RSpec files from it.

First to get it to honor the .rvmrc project file you need to follow the instructions at this post . To make it easier for you I copied the instructions here: you must create a $HOME/bin/sublime_rvm.rb with the following content:

and make it executable with chmod +x ~/bin/sublime_rvm.rb then update your ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Ruby/Ruby.sublime-build to look like this:

After this you should be able to run a ruby file from Sublime Text 2 using Cmd-B and it will use whatever ruby version is specified in the .rvmrc for that project.

Having done that I created a ~/bin/sublime_rpec.rb file with the following content

and then I used Package Control to install RubyTest and modified ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/RubyTest/RubyTest.sublime-settings like this:

Of course you should point to your sublime_rspec.rb path which will differ from mine. And now when I press Cmd-Shift-R, Sublime Text will run the file with RSpec. Well in my case I prefer to run the RSpec test with the the bundled version of RSpec for the project, that’s why I use bundle exec rspec #{file} in the script. If you want to use the RSpec gem installed in your rvm gemset remove the bundle exec part.

Running a Custom TestRunner From Rake

| Comments

I was surprised when I searched in Google for ways of running a custom TestRunner in a Rake::TestTask and I couldn’t find anything directly.

So after figuring out myself how it’s done I decided to share it here:

Let’s say that you have the following TestRunner (learn how to write your custom TestRunner)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Usage:
#   ruby -rstat_runner [test] --runner=stat
# http://endofline.wordpress.com/2008/02/11/a-custom-testrunner-to-scratch-an-itch/require 'test/unit'
require 'test/unit/ui/console/testrunner'
class StatRunner < Test::Unit::UI::Console::TestRunner
  def finished(elapsed_time)
    nl
    output("="*72)
    output("|"+"Finished in #{elapsed_time} seconds.".center(70)+"|")
    output("="*72)
    nl
    output(@result)
  end
end

Test::Unit::AutoRunner::RUNNERS[:stat] = proc do |r|
  StatRunner
end

This new StatRunner is very simple and the only customization is that it prints the result line wrapped in a box.

Now imagine that this StatRunner is defined in the test/stat_runner.rb file. The rake task in the rakefile would look like:

1
2
3
4
5
6
7
8
9
# http://rake.rubyforge.org/classes/Rake/TestTask.html
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
  test.libs << 'lib' << 'test'  # test dir is in, so we can do -rstat_runner
  test.ruby_opts=['-rstat_runner'] # require stat_runner.rb in spawned ruby process  
  test.pattern = 'test/**/test_*.rb'
  test.verbose = true
  test.options="--runner=stat" #force to use the new runner called stat (has to be in RUNNERS)
end

That’s it. Now if you run your rakefile you’ll get

  Started

  ========================================================================
  |                    Finished in 0.000103 seconds.                     |
  ========================================================================

  1 tests, 1 assertions, 0 failures, 0 errors

Compiling OpenChronos in Windows

| Comments

I got the EZ430 Chronos some days ago and after play around a little with the Code Composer Studio v4 that comes with it (the free code size limited version) I got the TI firmware compiled and uploaded to the watch. Then I realized that what I compiled it was a stripped down version of the firmware called Limited as the code-size-limited CCSv4 cannot be used to compiled the Unrestricted firmware.

So now to get a decent firmware in the EZ430 I need either the full CCSv4 or another toolchain for the MSP430 MCUs with specific support for CC430F6137 which is the processor present in the eZ430-Chronos . CCSv4 is quite expensive: ~500USD so I started looking for other toolchains.

I tried mspgcc but it didn’t really work for me. I was getting compilation errors, and I didn’t feel like investigating those. Then I turn into OpenChronos which seems to be the TI firmware but just modified enough to be able to compile using the mspgcc4 toolchain so I started exploring that path.

I couldn’t get the Win32 port of mspgcc4 to work properly (seems to me that the Win32 has been updated in a while). So at the end I had to use it from Cygwin . These are the steps that I took:

  1. Install wget, patch, gcc 4 , make, python and perl in Cygwin
  2. Download the source distribution of mspgcc4
  3. Unpack it inside a Cygwin bash shell
    1
    2
    
    cd tmp
    tar xvjf /cygdrive/c/Users/xxxx/Downloads/mspgcc4-20110130.tar.bz2

  4. Build mspgcc
    1
    2
    
    cd mspgcc4-20110130
    ./buildgcc.pl

    Select gcc-4.4.5, no gdb, no insight, ti_20110130, and the rest of the defaults.
  5. After a long compile mspgcc4 should be installed in /opt/msp430-gcc-4.4.5/
  6. Add export PATH=$PATH:/opt/msp430-gcc-4.4.5/bin to ~/.bashrc
  7. Download OpenChronos
    1
    2
    3
    4
    5
    6
    7
    8
    
    cd ~
     git clone git://github.com/poelzi/OpenChronos.git
     Cloning into OpenChronos...
     remote: Counting objects: 1485, done.
     remote: Compressing objects: 100% (550/550), done.
     remote: Total 1485 (delta 972), reused 1364 (delta 877)Receiving objects  93%
     Receiving objects: 100% (1485/1485), 666.11 KiB | 411 KiB/s, done.
     Resolving deltas: 100% (972/972), done.
  8. Configure the build
    cd OpenChronos
    make config
  9. Select the proper frequency (868Mhz if you are in Europe) and save
  10. Run make
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    make
      Assembling even_in_range in one step for MSP430...
      msp430-gcc -D_GNU_ASSEMBLER_ -x assembler-with-cpp -c even_in_range.s -o even_in_range.o
      Compiling main for MSP430...
      msp430-gcc -mmcu=cc430x6137 -Os -Wall -fomit-frame-pointer -fno-force-addr -finline-limit=1 -fno-schedule-insns  -Wl,-Map=output.map -o build/eZChronos.elf logi
      ... 
      ...
      ... 
      ronos.o gcc/intrinsics.o  even_in_range.o
      Convert to TI Hex file
      python tools/memory.py -i build/eZChronos.elf -o build/eZChronos.txt
      ELF section .text at 0x8000 32224 bytes
      ELF section .data at 0xfde0 150 bytes
      ELF section .vectors at 0xff80 128 bytes
      convert to TI Hex
  11. Upload the new compiled firmware build/eZChronos.txt using the Wireless update feature of Chronos Control Center (you have to have the USB access point connected, of course)
    1. Select the firmware file c:/cygwin/home/xxxxxx/OpenCronos/build/eZChronos.txt
    2. Click on Update Chronos Watch button
    3. In the watch, navigate to rFbSL (using the # button) and start it (by holding #). If everything goes at it should the download will start and you will see the percentage of firmware tranferred so far in the watch screen (also in Chronos Control Center).

If you think that there is something missing or not clear, leave a comment.

Training a Specific Opening With Rybka Aquarium

| Comments

I recently bought the Rybka 4 Aquarium + Chess Assistant 11 combo from ChessOK and I was trying to figure out how to practice openings with it.

DISCLAIMER: If you know of any other better way to do this or you think something is not clear, please leave a comment!

In Chapter 11:Trees of the Aquarium manual they mention how “discarded moves” trees can be used for making Aquarium play certain openings over others:

[…] After you have created an opening book you can use the discarded moves tree to create a “mask” for it to play or not play certain moves or openings. You can have one opening book and as many “discarded moves” trees as you like. This means that if you store your whole opening repertoire in a single opening book you can, for instance, define the following “discarded moves” trees:
1) One that only plays the gambit openings in your opening book
2) One that never plays the Sicilian
3) One that only plays queen pawn openings as white.
4) One that whenever possible plays the Sicilian Dragon as black.

But it doesn’t exactly explain how (Shame on them! :). So I tried to figure out myself how to do it with the help of the rybkaforums.net (Thanks to Felix Kling, ppipper and buffos). After reading several times the manual, this , this and this I think I understand how to do it. Let me explain it.

First, some background…

Tree configurations

To understand better tree configurations_ read the ChessCafe: Introduction to Tree Configurations and buffos i-book about tree configurations. I will try to describe tree configuration briefly here but it’s worth reading those two documents.

A tree configuration is a set of “regular” trees containing precomputed informations about the board positions plus a maintree and discarded tree. The “regular” trees are positional trees, graphs where the nodes are board positions and edges are the moves that connect one position to another. Attached to each board position there is some information, for example an engine evaluation for the position, success ratio statistics, textual annotations, etc. A tree configuration “merges” at runtime those trees and computes some other attributes (columns) derived from the info in those trees. These trees are considered read-only from Aquarium point of view.

Then there are two special “trees” in each tree configuration. The maintree and the discarded tree. These trees you can modify from the Aquarium GUI. When you mark a move as good/interesting/bad etc in the tree that information is stored in the maintree. If you mark a move as discarded or set the playing probability of a move by hand that information will be stored in the discarded tree.

So by creating different tree configurations with different maintrees and discarded trees you can use as opening books you can make rybka to play different opening moves. We’ll see how to do it right now…

Examples: One that only plays the gambit openings in your opening book

Let’s begin by going to the tree configurations dialog (Sandbox mode ⇒ Tree ⇒ Options) and create a new tree configuration (see chesscafe article for details) from the NarrowBook tree configuration.

and name it “gambits” for example. Then change the “Main tree path” to gambits_maintree and “Discarded tree path” to gambits_discarded. This will create an empty maintree and empty discarded tree, new trees that are not shared by any other tree configuration, this is important because you don’t want the changes in gambit tree configuration affect any other tree configuration.

Now we can proceed to set the Play% (playing probability) of the moves from the Aquarium GUI.

You can influence the Play% of the moves in two ways (that I know of):

First you can just set the playing probability by clicking on “Enter percents…” (or using the faster keyboard shortcut “+”). This is what I recommend

Or you can mark the move as good/interesting/dubious/bad/discarded. If you mark it as good you will prioritize the move, if you mark it as bad or discarded it won’t be played. For details about how the prioritizations actually works take a look at the following i-book (pay special attention to the Bonus system chapter).

Obviously the first gives you fine tuned control over the playing probability and that’s the method that I’ll be using here.

So let’s make this tree configuration to play only 1.e4 or 1.d4 when playing as white by using “+” key to set both to 50%.

So far, so good. By using this opening book “gambits” rybka will always play e4 or d4 as first move. Now we are going to force to always play the King’s gambit if black plays 1...e5.

On the tree select 1.e4 and press right arrow (→). Then it will present the black alternatives to 1.e4 among those 1...e6 , 1...e5, etc. Locate and select 1...e5 (using the up ↑ and down ↓ arrows to navigate between options) and right arrow → to go into move 1...e5, we don’t need to set the play probability for 1...e5 because we are not interested on rybka playing 1...e5 (we want to practice these openings with the human player playing black). Then go down until you see 2.f4 and press + to set 100% play probability. Using the keyboard to modify the tree is way faster than using the mouse so learn the keyboar shortcuts.

Let’s also program this opening book to play the Queen’s gambit whenever is possible.

Navigate in the tree window from 1.d41...d5 → and select 2.c4 and set playing probability to 100% with the “+” key.

Now you can go to Play mode and let Rybka play the white (make sure you select “gambits” opening book) and you will see that white always plays the King’s gambit or the Queen’s gambit.

Example: One that whenever possible plays the Sicilian Dragon as black

Now let’s create a new tree configuration that plays Sicilian Dragon whenever is possible. This time we will use the Rybka Opening book as base and keep the good move/bad move coloring did by Jiri Dufek

Ok, first go to Sandbox mode ⇒ Tree ⇒ Options and select Rybka4_book from the list of configurations. Click on New ⇒ Copy current configuration (Rybka4_book) ⇒ Next and name it “sicilian_dragon_black”.

Leave the Main tree path as “Rybka4book\rybka4_Jiri_Dufek” and replace Discarded tree path with “discarded_sicilian_dragon_black”. You will end up with the following:

So now let’s force Rybka to play Sicilian Dragon . Select 1.e4 and right arrow →, select 1...c5 press “+” and set 100%. Press right arrow → to go the next move (white), select 2.Nf3 right arrow → and select 2...d6 and set it to 100%, do the same for 3...cxd4, 4...Nf6 and 5...g6. And that’s it:

Links

From Textdrive to Joyent Shared Accelerator

| Comments

After delaying it for long, long time I finally moved from Textdrive to Joyent Shared Accelerator. The improvement has been considerable. The response time has halved (blue line), and after a few days I switched to jekyll for the blog platform and the improvements has been event bigger!

Fixing Disqus

| Comments

I was checking the Disqus threads for my site in the Disqus web page and I noticed that there was something wrong. Some threads had the wrong url, pointing to http://localhost:4000 and some had the wrong title (instead of the title the url was showing). I came to the conclusion that this was due to the fact that I’ve been using disqus_developer=1 to test locally after migrating to Disqus and the threads that I visited for the first time locally got the local url (localhost) and the because disqus couldn’t get the title from that url (since it was a local url) it assigned a title based on the (local) url.

So I decided to fix it using the Disqus API and I wrote the following script

that uses a slightly modified version of the disqus ruby. I had to modify the disqus ruby because the original version can only iterate over the first 25 threads.

DiffMerge/WinMerge for Cygwin Git

| Comments

After reading several blogs and pages I got SourceGear DiffMerge and WinMerge working with Cygwin’s Git.

First you need to put some scripts in the path that serve as wrapper for invoking DiffMerge and WinMerge.

I created 2 wrapper scripts for DiffMerge diffmerge-diff.sh and diffmerge-merge.sh See the source code in the gist.

I also created two more scripts for WinMerge: winmerge-diff.sh and winmerge-merge.sh. You can find the source code for scripts in the same gist.

All four scripts rely on githelperfunction.sh to properly convert the path and set variables.

The scripts above take into account:

  • Conversion of cygwin paths to Windows path
  • Handle filenames with whitespace
  • Handle properly non-existing files. Sometimes a file doesn’t exist in one of the branches you are comparing and then git will provide /dev/null as filename for that one. These scripts take care of converting that to a proper empty file in Windows.
  • DiffMerge: Set the window title in DiffMerge to the filename. And set labels for each file window to LOCALFROM_VERSION, REMOTETO_VERSION and BASEMERGED
  • WinMerge: Set the file labels to LOCALFROM_VERSION.filename and REMOTETO_VERSION.filename.

After storing those script and make them accessible from your $PATH then you need to tell git how to use them.

You can use the following commands to tell git about this wrappers:

1
2
3
4
5
6
7
8
9
10
# for difftool
git config --global difftool.diffmerge.cmd "diffmerge-diff.sh \"\$LOCAL\" \"\$REMOTE\"" \"\$BASE\"" \"\$MERGED\""
git config --global difftool.winmerge.cmd "winmerge-diff.sh \"\$LOCAL\" \"\$REMOTE\"" \"\$BASE\"" \"\$MERGED\""
git config --global difftool.prompt false

# for mergetool
git config --global mergetool.diffmerge.cmd "diffmerge-merge.sh \"\$LOCAL\" \"\$REMOTE\"" \"\$BASE\"" \"\$MERGED\""
git config --global mergetool.diffmerge.trustExitCode false
git config --global mergetool.winmerge.cmd "winmerge-merge.sh \"\$LOCAL\" \"\$REMOTE\"" \"\$BASE\"" \"\$MERGED\""
git config --global mergetool.winmerge.trustExitCode false

And then you can invoke git difftool and git mergetool using -t <TOOL> to indicate which one you want to use:

1
2
3
4
git difftool -t diffmerge 
git difftool -t winmerge
git mergetool -t diffmerge
git mergetool -t winmerge

if you want to make any of those tools the default you can use git config to do so:

1
2
git config --global diff.tool winmerge
git config --global merge.tool diffmerge

Hope this helps

Migrating From Wordpress 3.0 to Jekyll

| Comments

I finally migrated from Wordpress to Jekyll. It wasn’t difficult but not easy either so I decided to write my experience in this blog.

I’m assuming that you setup a basic Jekyll site: _config.yml, _layouts, _posts, etc. A good start is to clone mojombo jekyll site and remove the _posts and images.

Although the Jekyll wiki describes how to use converters to migrate from Wordpress I didn’t follow that path because it requires direct access to the Mysql database.

So I found a migration script posted to Issue #20 that uses the Wordpress XML export as input. The script had a couple of problems, it didn’t handle international characters in the title, and it didn’t honor the original permalinks in WordPress.

So I modified it to fix those thing

To use it you need to have a wordpress.xml file in the same directory where you run the script and you need to modify the ORIGINAL_DOMAIN in the script to reflect your own. It will dump the published WordPress posts and comment as jekyll textile files in export/_posts.

The comments will be translate to a YAML file: export/_posts/comments.yml. If you want to import the comments to Disqus you can use the yamlcomments2disqus.rb script to import it.

The only thing that you need is to create a file called API-KEY in the same directory as yamlcomments2disqus.rb and write there your Disqus API key. The script will automatically post all non-spam comments to Disqus using Disqus API. The comments thread for each post is identified by the original Wordpress <wp:post_id> so then you have to add the following <script> along with the disqus regular javascript code (you can find it in http://disqus.com/comments/universal/<your site>/) in your layout.

I include here my _layouts/default.html, _layouts/post.html, atom.xml and sitemap.xml for reference

Wordpress Migration: ” (Quotes) and ’ (Apostrophe) Being Replaced With “ and ’

| Comments

I migrated from TextDrive to a Joyent Shared Accelerator and in the process I had to migrate the Wordpress MySQL database as well. After the migration the " and ’ where showing as “ and ’ respectively. It was a charset problem. Apparently the problem was

that the data itself was already in UTF-8 within a Latin1 database (due to WP default charset).

So I did the backup again (like this)

1
2
mysqldump --user=$DB1USER --password=$DB1PASSWD \
  --default-character-set=latin1 $DB1NAME dump.sql

and then I imported the dump.sql file again into the Joyent utf8 mysql:

1
2
3
4
5
$ cat dump.sql |sed  -e 's/DEFAULT CHARSET=latin1;/DEFAULT CHARSET=utf8;/'>dp2.sql
$ mysqldump --user=$DB2USER --password=$DB2PASSWORD --add-drop-table \
--no-data $DB2NAME| grep ^DROP |mysql --user=$DB2NAME --password=$DB2PASSWORD \
$DB2NAME # to drop all existing tables
$ mysql --user=$DB2USER --password=$DB2PASSWORD $DB2NAME <dp2.sql

and the problem was solved!.

Then it got me thinking, how actually get a from “Japonés en viñetas” to “Japonés en viñetasâ€. So I tried to achieve the same result from the command line:

1
2
3
4
$ echo \“Japonés en viñetas\” 
“Japonés en viñetas”
$ echo \“Japonés en viñetas\” |iconv -f latin1 -t utf-8
“Japonés en viñetasâ

That’s not quite what I was expecting. Then I read the Wikipedia article on ISO-8859-1/Latin1 and I found that Latin-1 is confused with Windows-1253 and that “Many web browsers and e-mail clients will interpret ISO-8859-1 control codes as Windows-1252 characters in order to accommodate such mislabeling”

So I tried it

1
2
3
4
5
$ echo \“Japonés en viñetas\” 
“Japonés en viñetas”
$ echo \“Japonés en viñetas\” |iconv -f windows-1252 -t utf-8
“Japonés en viñetasâ€
iconv: (stdin):1:25: cannot convert

There it is the " becomes “. when it actually UTF-8 but misintepreted as Windows-1252

EN4J 1.0M2 Released - Evernote Java Client

| Comments

I finally decided to release the project I was working on the last year: A java desktop client for the Evernote service.

The distributions for Mac OS X, Linux and Windows can be found on the downloads page.

And the source code can be accesses and forked from the git repository on github.

The README for EN4J-1.0M2

                      EN4J
                      
                      
What is it?
-----------

EN4J is a client to the Evernote services written in Java. It designed to
become a replacement to the Evernote client for Windows & Mac. Although 
currently EN4J is a read-only client and cannot fully replace the 
official Evernote client. 

Features
--------
  * Fast search based on Lucene
  * Indexing of word documents, zip files, etc. All doc types supported by Apache Tika
  * Based on Netbeans Platform, runs on Windows, Mac OS X and Linux
  * Open source 

TO DO 
-----

  * Editable notes
  * tags
  * Keyring api
  * Rich-text clipboard copy
  * Ignore diacritical marks during search
  
Bugs
----

If you find any write a bug report on http://github.com/ecerulm/en4j/issues
  
How to build and install
------------------------

First, grab the source from github

git clone git://github.com/ecerulm/en4j.git

Then proceed to the main directory

cd en4j/NBPlatformApp

to build the windows zip distribution do

ant build-zip 

to build the mac os x distribution do 

ant build-mac

Then take the output file in NBPlatformApp/dist


Contribute
----------

Just fork the project from http://github.com/ecerulm/en4j

and send me a pull request with the changes.

Licensing
---------

Please see the file called LICENSE.

Credits
-------

Netbeans team for the Netbeans Plaform and Netbeans IDE

icons: Tango Icon Library http://tango.freedesktop.org/Tango_Icon_Library
icons: Nuvola http://www.icon-king.com/projects/nuvola/
icons: Crystal project http://www.everaldo.com/crystal/
icons: Addictive Flavour. Designed by Mirjami Manninen (http://www.mirkku.com). www.smashingmagazine.com
icons: Bunch of Cool Bluish ICONS http://mebaze.com/ 

GlazedLists: http://publicobject.com/glazedlists/
Apache Thrift: http://incubator.apache.org/thrift/
TimingFramework: https://timingframework.dev.java.net/
Flying Saucer: https://xhtmlrenderer.dev.java.net/
Apache Tika: http://tika.apache.org/
Apache Commons Collections: http://commons.apache.org/collections/
Apache Commons IO: http://commons.apache.org/io/
Apache Commons Math: http://commons.apache.org/math/
Evernote API: http://www.evernote.com/about/developer/api/
Joda Time library: http://joda-time.sourceforge.net/
NekoHTML: http://nekohtml.sourceforge.net/
renderpack: https://renderpack.dev.java.net/
SLF4J: http://www.slf4j.org
Woodstox: http://woodstox.codehaus.org/