Set Netbeans user Interface language

November 26th, 2008

From Tao’s blog

1. Temporary Solution

Add “–locale en:US” at the end of Netbeans startup command.

“C:\Program Files\NetBeans 6.0.1\bin\netbeans.exe” –locale en:US

2. Permanent Solution

Go to Netbeans installation directory, for example,

C:\Program Files\NetBeans 6.0.1\etc

Open “netbeans.conf” and find netbeans default option line

netbeans_default_options=”-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true”

Add “-J-Duser.language=en -J-Duser.region=US” to the end of this line

netbeans_default_options=”-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true -J-Duser.language=en -J-Duser.region=US”

Install fast debugger in Netbeans 6.5

November 23rd, 2008

Netbeans 6.5 is out and I gave it a try today, it runs much faster than 6.1 and code complete runs much smoother than before and do not block you from writting code anymore(that’s why I turned it off before).

Just one thing left, the Netbeans 6.5 needs ruby-debug-ide 0.3.x to be installed, so you need one command to run before starting debug:

sudo gem install ruby-debug-ide -v 0.3.1

Then, enjoy Netbeans!

VIM is really cool

September 27th, 2008

Github on windows

September 18th, 2008

Although Github provided the docs on how to add private/public keys for SSH connection, most of the windows users might be confused by the doc cause some very important steps are missed in the doc.

The most useful doc for windows user is:
http://groups.google.com/group/github/browse_thread/thread/fcfcfb3c5b446a34/52a203456ef27edf?lnk=gst&q=Git+does+seem+to+use+the#52a203456ef27edf

and

http://groups.google.com/group/github/browse_thread/thread/21fd06fb8c3f43bd/f5c44b2197d1be15

Here is what I did

1.Download PuTTYgen here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

2. Generate key pair use PuTTYgen
notes: do not use the saved public key, copy public key from the upper of the PuTTYgen window.

3. Register system variable
Name: GIT_SSH
Value: D:\Program Files\PuTTY\plink.exe

4. Add github fingerprint
Most weired thing is you can’t accept the github fingerprint in the command window, you must use Putty to do that:
Open Putty with
Host Name: github.com
Connection type: SSH
then click open button and select yes when prompt, and there you go, the github fingerprint is added, in a weired way!

Then you are OK with github now.

Happy Mid-Autumn Festival

September 14th, 2008

More about the Mid-Autumn Festival, see here

Ruby file processing, make life a little easier

September 12th, 2008

Today I have to edit 26 xml files, each of the file have several lines like this:

<SQL>select * form xxx where id=?</SQL>

and I have to change it to this:

<whereSQL>id=?</whereSQL>

Damn boring job, huh?

Here ruby comes for rescue

Dir["path_to_config_files/*.xml"].each do |f|
  content = File.read(f)  #read
  content.gsub!(/<SQL>.*where\s/,"<whereSQL>")  #modify
  content.gsub!(/<\/SQL>/,"</whereSQL>")  #modify
  File.open(f,"w") {|fw| fw << content} #write
end

Let’ see how many line has bee processed:

total = 0
Dir["E:/exconfigs/*.xml"].each do |f|
  content = File.read(f)  #read
  count = content.scan(/whereSQL/).length/2
  total += count
  puts f + ":" + "(" + count.to_s + ")"
end
puts total

The total number is 120, seems we saved some efforts :)

Generate PDF with Prawn(for Ruby) and Prawnto(for Rails)

August 22nd, 2008

Use Prawn in Ruby

Install

sudo gem install prawn

Usage:

require "rubygems"
require "prawn"
 
Prawn::Document.generate "test.pdf" do
#  must set font first, you can use the fonts prawn comes with
#  or the font dir on your system(/usr/share/fonts on ubuntu)
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
text "hello world!"
end

More Examples:
http://cracklabs.com/prawnto/demos

Use Prawnto with Rails

Project Home
http://cracklabs.com/prawnto

Install

script/plugin install git://github.com/thorny-sun/prawnto.git

Usage

1. add configuration in environment.rb

config.gem "prawn"

2. generate a pdf controller with an attachment action

class PdfController &lt; ApplicationController
  def attachment
    @prawn_document_options = {:filename=&gt;'test.pdf', :attachment=&gt;;true}
  end
end

3.add an attachment.pdf.prawn file in your views/pdf directory, you can treate it as an .erb file, and a pdf instance variable is accessable.

pdf.font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
pdf.text "#{@user.login}"
pdf.text "#{@user.email}"

4.go to http://localhost:3000/pdf/attachment/1.pdf
notice the .pdf extension in the url

That’s all.

AWS price range issue

July 1st, 2008

I tried to narrow the search results with the MaximumPrice and the MinimumPrice parameters today, but it does not work at all, then I found out it is an known issue of AWS Item Search, according to the release note here

The ItemSearch parameters, MaximumPrice and MinimumPrice, should limit the items returned according to the specified price range. Sometimes, items are returned whose prices fall outside of the specified range.

Hope the Amazon guys fix this soon.

The two ruby interfaces for AWS(Amazon WebService)

June 28th, 2008

Today I am looking for a ruby interface for Amazon WebService, and it turns out there are 2 of them with almost the same name, ruby-aws:

  1. The first one is ruby-aws, which is an official implemented, you can find it on rubyforge, the current version is 1.2.0;
  2. The second one is ruby/aws, which is on http://www.caliban.org/ruby/ruby-aws/, the current version is 0.3.3. BTW, there are also intersting ruby stuffs on http://www.caliban.org/ruby/

The last release of ruby/aws is at June 2008 and is newer than ruby-aws which is last released at Nov 2007. I tried the ruby/aws with its samples, the result is good, here is a snippet from the /example/example1, it tells well how

#!/usr/bin/ruby -w
#
# $Id: example1,v 1.4 2008/04/28 10:24:56 ianmacd Exp $
 
require 'amazon/aws'
require 'amazon/aws/search'
 
# We don't want to have to fully qualify identifiers.
#
include Amazon::AWS
include Amazon::AWS::Search
 
# If you don't have one of these, don't pass the second argument to
# Request.new.
#
ASSOCIATES_ID = "webservices-20"
 
# Your access key ID.
#
KEY_ID        = "0Y44V8FAFNM119C6PTR2"
 
request  = Request.new( KEY_ID, ASSOCIATES_ID )
 
# Create an item search object.
#
# is = ItemSearch.new( 'Books', { 'Keywords' =&gt; 'ruby programming' } )
is = ItemSearch.new( 'Books', { 'Title' =&gt; 'ruby programming' } )
 
# Create a response group object. Examples of response groups are 'Small',
# 'Medium' and 'Large'. 'Large' returns all data about an item.
#
rg = ResponseGroup.new( 'Large' )
 
# Search for the items, passing the result into a block.
#
nr_items = 0
page_nr = 0
response = request.search( is, rg, :ALL_PAGES ) do |page|
# page.item_search_response[0].items.each do |item_set|
#   item_set.item.each do |item|
#     puts 'Found a product:'
#     item.instance_variables.each do |iv|
#      printf( "%s = %s\n", iv, item.instance_variable_get( iv ) )
#     end
#   end
# end
printf( "Page %d had unique request ID %s.\n",
page_nr += 1,
page.item_search_response[0].operation_request[0].request_id )
printf( "Page %d contained %d result(s).\n",
page_nr,
page.item_search_response[0].items[0].item.size )
end
 
# You don't have to access the items through a block.
#
nr_items = 0
response.each do |page|
page.item_search_response[0].items.each do |item_set|
nr_items += item_set.item.size
end
end
printf( "Search returned %d items.\n", nr_items )
 
# The first item in the list.
#
items = response[0].item_search_response[0].items[0].item
product1 = items[0]
puts "\nProperties available for the first product returned:",
product1.properties.sort
puts
 
# There are three ways to retrieve the property of a product:
#
 
# Instance variable:
#
p product1.asin
p product1.item_attributes[0].title
 
# Feels more like a Hash:
#
p product1.item_attributes[0]['list_price'][0]['formatted_price']
 
# A variation on the hash theme:
#
p product1.item_attributes[0][:author]

Firefox download day!

June 18th, 2008

Today is firefox downlaod day, download it and make history by yourself!

China is red on the map, which means there are more than 100k downloadings today(152,468 till now), well done, guys!

I wrote this post with ff3, it’s really cool, most of the addons I used works well, including firebugs, hidemenu, etc.

Alos, today I changed the theme to Deep Blue, I like the name and look of the theme very much :P