Monday, November 7, 2011

Android Kitchen - Setting Up Eclipse and Android SDK

Actually following the official android setup guide should work already:
http://developer.android.com/sdk/installing.html


But we found several issues during the workshop:



1. Android SDK Path inside eclipse


Double check, make sure the Android SDK path inside eclipse is pointing to the correctly directory.



2. Use eclipse's Android manager plugin but not command line

In step 4, please use the ADT plugin to open the Android SDK and AVD Manager
From within Eclipse, select Window > Android SDK and AVD Manager.


there are problems, when not using the eclipse plugin, that even some SDK are downloaded, they cannot not be selected as Build Target inside eclipse. (We were using Indigo)



3. Always Clean and Re-build


Sometimes, an error message popup when we start the application saying "Force Close".

Very likely, it is because some generated files are cached which are not updated after changing the xml files (probably a bug in the Android plugin). For example, after changing the Android layout file (i.e. main.xml).

What you have to do is to "Project -> Clean...". This function clean up all the generated files.

If you have the "Project -> Build Automatically" option selected, Eclipse will compile all the files again. If not, click "Project -> Build Project".



4.if you use Java 1.7


We were using Java 1.7, and found out an error when we override (using @Override annotation) the onClick method of OnClickListener.

With Java 1.7, you can no longer override an interface method.

View.OnClickListener is an interface. Overriding an interface method still works in 1.6, but no longer valid in 1.7. So, "No Need to use @Override for onClick(View view) method".

Monday, October 24, 2011

Download Youtube clip, Convert to MP4 and OGG for HTML 5 video tag

I am working with Mac. One of my tasks was ... "36613, put this youtube video on our website !! using latest fancy portable HTML 5 !!"


"Yes. My Lord! " ... HTML 5 is not really being supported by all latest browser yet. and some of them only support some particular encoding schemes. So, what I had to do for this task was ...

  1. Download the video from youtube
  2. Convert the video to .mp4
  3. Convert the video to .ogg
  4. Write little HTML(5) code

I am going to talk about the freeware converters I used on Mac only. They are all real free, no watermark, no limited functions, no trial expiry date.

If you want to write a video tag that support all browsers, visit the following post: http://henriksjokvist.net/archive/2009/2/using-the-html5-video-tag-with-a-flash-fallback. It talked about including .mp4, .ogg and also .flv in order to support all browsers.



1. Download the .flv video from youtube

"Firefox" and Firefox Add-on "Ant Video Downloader": https://addons.mozilla.org/en-US/firefox/addon/video-downloader-player/

Usage:
  1. Use Firefox, go to the youtube video page you want to download.
  2. click the Ant video button next to the address bar.
  3. select the video name in the dropdown list.


2. Convert the .flv to .mp4

MPEG Streamclip: http://www.squared5.com/

Usage:
  1. Open the downloaded .flv file using MPEG Streamclip
  2. Choose Export to MPEG-4 in the menu
  3. Select the resolutions you want (usually defaults are alright).


3. Convert the .flv to .ogg

ffmpeg2theora: http://v2v.cc/~j/ffmpeg2theora

Usage:
  1. run the following command to convert the .flv file:
  2. ffmpeg2theora DownloadedYoutubeVideo.flv

Wednesday, September 21, 2011

Using javascript to solve mobile browser position:fixed; issue

One of the website I am working on is using Clearbox to generate the lightbox effect. But because most of the mobile browsers does not work with position:fixed, so, when user browse the website from iPad or Android, the dialog box always popup at the top of the page (outside the current viewport). The same issue happens to every javascript library using position:fixed property.

There is no easy workaround yet.

So, I have to run the following script after every scroll event in order to update the "top" style of the popup window (keep updating even before the user click the lightbox link).

(include this script right before the </head>)

Friday, September 16, 2011

Using Keynote for presentation slides

Keynote has a really nice feature to share the slides online in iwork.com, but it requires Safari browser to see all the animations and transitions.

http://public.iwork.com/document/?d=WebScraping.key&a=p1074597799

This sharing is about writing Web Scraper, the audience are HKUST students in Social Media course.

Friday, September 9, 2011

am visiting HKUST occasionally ... sitting lessons

Was visiting HKUST occasionally, and attended a random class. It is really tempted to sit more lessons for free ! I think one day I will keep attending university classes when I don't have full time job.

Here is the list of course pages:
http://www.cse.ust.hk/pg/courses

Here is the class schedule search application to check the class date time and room number:
http://tinyurl.com/425oygn



Some interesting ones ... (not all of them available this semester):


COMP 5211     Advanced Artificial Intelligence     [3-0-0:3]
[Previous Course Code(s): COMP 521] This advanced AI course will cover advanced concepts and techniques in AI. The major topics will be: problem solving, knowledge and reasoning, planning, uncertain knowledge and reasoning, learning, and robotics.


COMP 5531     Green Computing     [3-0-0:3]
[Co-List with ENEG 5450] This course will exam "Green Computing" from a system perspective, meanwhile, students will study issues related to energy saving form multiple disciplines such as mechanical engineering, industrial ecology, and economics. We will explore energy efficient system designs ranging from datacenters to embed devices, such as sensor networks and RFID devices. We will perform Life Cycle Analysis on some of these systems, evaluating the carbon footprint of manufacturing, use, and disposal of each design. Exclusion(s): ENEG 5450


COMP 5711     Introduction to Advanced Algorithmic Techniques     [3-0-0:3]
[Previous Course Code(s): COMP 570] This is an introductory graduate course in algorithmic techniques. Topics include: advanced data structures; graph algorithms; amortization; approximation algorithms; on-line algorithms; randomized and probabilistic analysis. Background: COMP 3711, COMP 3721


COMP 5712     Introduction to Combinatorial Optimization     [3-0-0:3]
[Previous Course Code(s): COMP 572] An introduction to the basic tools of combinatorial optimization, including network flow and the max-flow min-cut theorem, linear programming, matching, spanning trees and matroids, dynamic programming, algorithms and data structures, graph algorithms. Background: COMP 3711 or equivalent, linear algebra


COMP 6211     Advanced Topics in Artificial Intelligence     [3-0-0:3]
[Previous Course Code(s): COMP 621] Advanced topics in artificial intelligence including neural networks, natural language processing, logic programming, image understanding, robotics and others. Background: An appropriate 500-level course.


COMP 6511     Topics in Computer Systems Analysis     [3-0-0:3]
[Previous Course Code(s): COMP 651] Advanced topics in computer systems analysis; issues in the development and solution of system models; model parametrization, verification and validation; recent developments in techniques and tools for system evaluation.


COMP 6611     Topics in Computer and Communication Networks     [3-0-0:3]
[Previous Course Code(s): COMP 660] Advanced topics in communication networks, including issues in high speed networking, ATM, multimedia communication, network interconnection, network management, and protocol verification and testing.


COMP 6612     Topics in Computer Engineering     [3-0-0:3]
[Previous Course Code(s): COMP 680] Selected topics in computer engineering of current interest to the Department and not covered by existing courses.


COMP 6613     Topics in Applications of Computer Science and Engineering     [3-0-0:3]
[Previous Course Code(s): COMP 685] Selected topics in applications of computer science not covered by existing course. Credits earned by taking this course can only be used to satisfy the breath requirement of the research area of Software and Applications.


COMP 6711     Topics in Theoretical Computer Science     [3-0-0:3]
[Previous Course Code(s): COMP 670] Selected topics in theoretical computer science not covered by existing courses, including, but not limited to, computational complexities and computability, graph algorithms and combinatorial optimization.

Monday, September 5, 2011

Wednesday, August 31, 2011

Solving (Workaround) ruby_core_source.rb:57 'initialize': not in gzip format (Zlib::GzipFile::Error)


saw this error when one of my colleagues could not bundle install nor gem install linecache19:

ruby_core_source.rb:57 'initialize': not in gzip format

We are all using the same Gemfile to do bundle install, and it only happens to his laptop. After trying everything we found in google / stackoverflow, it still not working. Most of the suggestion were about cleaning the cache files in the rvm directories.


After digging into the source code of ruby_core_source.rb, I found out that the code did a gunzip and then tar extract on a tar file. So, that's the problem of the package storing on the ftp server: (ruby_core_source.rb:50)

uri_path = "http://ftp.ruby-lang.org/pub/ruby/1.9/" + ruby_dir + ".tar.gz"


I am not sure why the .gz file on the server is not gzip-ed.

But then the workaround is obvious. Go to gem directory and modify the source. my ruby_core_source.rb is here: ~/.rvm/gems/ruby-1.9.2-p180@not_gzip_format_error/gems/ruby_core_source.gem/lib/ruby_core_source.rb



More coding details here: https://gist.github.com/1183048


Note: this is a different issue from tar_input.rb 'initialize': not in gzip format (Zlib::GzipFile::Error)


Friday, August 5, 2011

Code Jam at boot.hk

Yeah ~ organizing our first code jam. We have total 13 ppl confirmed coming ! We have different expertises: Drupal, UX, RubyOnRails, Java, etc. Must be fun !!


Although the project is mainly PHP and Drupal, there are many areas non-PHP coders could help. Infrastructure, UI, online marketing, user experience, pair programming, etc.


To make Hong Kong a better place to develop technology products, Code Jam is really an important part. Knowledge and skills are exchanged. Stronger linkage between several coder communities is built. People will be more confident about investing money on local talents and the creative technology industry. I am sure we will have more and more Code Jam coming ~


More info about the Code Jam:


Wednesday, August 3, 2011

Aug 2011 Codeaholics on Mozart Oz and Haskell

http://codeaholics.hk


We had 2 sharing tonight focusing on programming languages: Haskell and Mozart Oz. There were a lots to take (little bit too much to me), but I found them inspiring.


Mozart Oz allows one to define a program with the paradigms you need, e.g. object-oriented, functional, or constraint logic programming. Another interesting feature is that the implementation could be transparent. You can send a message to a class, and the receiver may be not staying in the same memory as yours, e.g. perhaps it is another machine on the network. Really look forward to see some real life examples after Stewart's sharing.


William ended his Haskell tour by showing how to use Monad to build the JSON parser. The previous talks focus more on syntax and function definition of Haskell. I finally see the power of Haskell when William showed us the JSON parser. It was awesome, simple and highly readable. It was little bit brain-fucked when I tried to follow all the syntax, pattern matching and type classes thingy. However, it is really amazing when you see the neat final product. After seeing the JSON parser, everything makes sense to me now.


Thanks William spent so much time to prepare the Haskell tour, it has been 3 4 months since the Haskell Tour Part I. His presentation style is so attractive and entertaining, the content is well-prepared and inspiring, and Haskell is sexy.

map to Boot HK

  1. Start from Wan Chai MTR station A3 exit
  2. Go across the tram road (Johnston Road)
  3. Get into the street full of hawker (Tai Yuen Street)
  4. When you arrive Queen's Road East, locate the starbucks
  5. Entrance of the building is opposite to starbucks








Tuesday, August 2, 2011

Busy coder week

Codeaholics HK Meetup

http://www.facebook.com/event.php?eid=235908043109490

This time we have speakers talking about Haskell, Mozart OZ and Objective-C. Codeaholics is a programming language agnostic coder meetup. Open for public, free of charge, welcome everyone to attend.


Code Jam: Peer Patent

http://www.facebook.com/event.php?eid=179909352075514

We talked about organizing a Code Jam for local coders 1000 times (literally 1000 times). finally we managed to do once. We are developing a system for Peer Patent.

Sunday, July 31, 2011

Reuse gettext gem to parse .po file

I am working on a translation service which requires translating .po file (ruby gettext gem). Spent hours to understand the rake tasks it provides and looked for methods to extract all String inside .po file. Finally found the parser and the method to do my job:


require 'gettext/tools/poparser'
require 'gettext/tools/rmsgmerge'

parser = GetText::PoParser.new
result = parser.parse_file("...../my_rails_project/po/en/text_domain.po", GetText::RMsgMerge::PoData.new, false)

the object representing the data structure is assigned to result.


In case you are also extending gettext library, check the gettext/tools directory. Most of the useful methods are located there.

Friday, July 29, 2011

Support website video in every browser

to make sure your video clip is running in every browser, read this:
http://diveintohtml5.org/video​.html


start from beginning if you want to know everything, or else start from "what about IE?". sample code provided at the end.

Introduction to Maven

Maven is a build tool which handles project dependencies and job automation. In most of my java and scala projects, I use Maven.


Especially in a team working environment, you need build tool like maven to synchronize version of modules and libraries between each developer workspace. So, one coder specifies what he needs for his module, commit the maven configuration file (pom.xml) to source code version control. Another developer pull down the latest pom.xml file from version control and then his local workspace knows that the module requires a new external library.


The next magic thing maven provided is the centralized library repository. So following the previous example, when the second developer builds the project, maven will automatically access the repository, which exists somewhere in the internet, and download the libraries. It saves everybody so much time to handle libraries versioning in each machine. There is a library search online: http://mvnrepository.com. Instruction to update your pom.xml is also included there.


Another magic thing you frequently use with maven is continuous integration. Maven handles dependencies and also able to run unit tests, packaging, deployment, code quality reporting, etc. So that developer can solely focus on coding instead of managing all those repeating mundane stuff.


Check out maven if you have never used it before. Google mvn archetype:generate, and then you will find some useful stuff to follow. Enjoy !

Playing video on website with all desktop and mobile browser supported

Once you started putting video on your website, you will soon find out that you cannot make every browser happy... IE, desktop browser, iPad tablet browser, iOS mobile browser, etc.


The usual solution is to use something like 'Video For Everybody'. but you still need some extension to handle Android one.


Here is the website which talks about the issues in each browser and provides a sample solution for that: http://diveintohtml5.org/video.html


If you are interested in knowing everything, read from the start. or else start from "what about IE?"

Friday, July 22, 2011

Upgraded my Mac Book Pro to SSD Drive and 8G RAM

this is really fast, booting the mac book is like waking up from sleep mode. awesome ~ I didn't measure the time difference, but I am sure you can find lots of proof from youtube. this post is just to reference the compatible SSD drive.


this is my Mac Book Pro model:
Model Name: MacBook Pro
Model Identifier: MacBookPro5,5
Processor Name: Intel Core 2 Duo
Processor Speed: 2.53 GHz

this is my new SSD drive:
PLEXTOR  PX-128M2S


please be aware that this one is SATA 3. I tried another Intel SATA 3 before which did not work on my Mac Book pro.

My Mac Book pro does not support SATA 3, so it will run as if it is SATA 2. However, I can still use it for my next machine. not bad.

Wednesday, July 13, 2011

Agile In Thought Sauce (slides by Jekyll and Hyde, at github pages)

Another Jekyll and Hyde presentation, this time I deploy to github pages directly.
http://thought-sauce.github.com/agile_in_thought_sauce.


The sharing is about Agile planning and Agile development in Thought Sauce. Will go to Octopus Cards tomorrow to share our experience.

Thursday, June 30, 2011

Google Sites with mobile template. Codeaholics HK website

we just finished one meetup last night. enjoyed it so much. try my best to promote it to more coders in Hong Kong ~


to get some more web presence for Codeaholics HK meetup, I created a Google Sites with the mobile template:
https://sites.google.com/site/codeaholicshk/

Friday, June 17, 2011

Hong Kong IT Event Calendar update

I help maintaining the Hong Kong Web and Tech Meetup calendar. http://tinyurl.com/hkitcal

If you are organizing or attending any tech events in Hong Kong, email me and I will update the calendar asap. tatonlto [at] gmail.com

Notes when using Eager Loading on Polymorphic relationship

Eager Loading on Polymorphic calls
After checking the Rails API, it is confirmed that eager loading on polymorphic column works. "Eager loading is supported with polymorphic associations." Rails API

My eager loading is a deep hierarchy of associations (people -> reference -> source). so my scope is something like this:
@people = People.includes([:comments, {:reference => :source}])

Problem 1
However, when I use the @people in the view some of them work as expected but some of them throws EagerLoadPolymorphicError:
ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :reference

To solve this, usually a loading trigger before the method call would solve it. For example, calling #first, #last or #any


Problem 2
After finish the each loop on @people in the view, I call a function which is a scoped summation function, e.g. #self.total_membership_fees. And this line throws the EagerLoadPolymorphicError !
the loop works fine but the scoped class function does not.

It is like the @people active record relationship is an immutable object which has to preload in every scope.


To solve this, I could do self.any? before self.sum(&:membership_fee). but I simply use another scoped object for calculating the total, before my total_x method does not requires the polymorphic relationships.


Hope it helps clarifying your problem too.

ssh ForwardAgent yes not working (SOLVED!)

I am using MacOS.
I was able to use ssh with id_rsa public key authentication and do something in remote server with "ForwardAgent yes".

But then I setup my new machine, I regenerate keys, copied over to remote server, it doesn't work. I can still authenticate into the server successfully, just that I could not see the behavior of ForwardAgent. the path of the config file is correct, content exactly the same.

After few tests, found out that I should have passphrase for the ssh key pairs, so that the "ForwardAgent yes" would work as expected.

I could not find this requirement for ForwardAgent usage on the internet after few google search. Please redirect me to the documentation, in case any of you found it.

Wednesday, June 15, 2011

Codeaholics June 2011 Meetup

http://www.facebook.com/event.php?eid=230262926999715



coding knowledge sharing meetup. Open to public, *FREE* of charge.


* * * * * * * * * Speakers * * * * * * * * *
= William Taysom
= An Introduction to Haskell - Part 2

= Shravan Gurrala
= iOS and Objective C

= Matthew Rudy
= "Javascript Web Applications"


* * * * * * * * * Sponsors * * * * * * * * *

= Venue by boot.hk
= 19/f, Hang Wai Commercial Building, 231-233 Queen's Road East, Wan Chai

= Beer by Thought Sauce
= http://thought-sauce.com/

Friday, June 10, 2011

灣仔Mac Book 維修整機非常掂。旺角Pxxxxxx完全唔掂

上星期拎左部MAC BOOK PRO去旺角電腦中心一樓Pxxxxxx整,過左幾日打去問都話唔知咩事。日日打去問都話師父未番,師父話唔知咩事,遲D打番俾你啦(無覆過電話)。我等左個幾星期(10日)之後就叫佢SHIP番黎,唔駛佢整。

今日LUNCH拎去灣仔298三樓,講完症狀,師父已經估到CABLE有事。二十分鐘(連吹水同處理四五個客戶查詢)唔駛就攪掂。

強列推薦香港灣仔298三樓347店(O係最入最角落位置)GreenMac SIMON

Hope Google Group Mailing List supports +1 (PLUS ONE)

sometimes I saw some funny jokes in google group mailing list, I really want to support/push by facebook "like" or google "+1"

so bad that it is not open source and I could not plug my idea into it. Socializing public group discussion sounds fun.

Wednesday, June 1, 2011

Looking for funding and VC in Hong Kong

We are looking for funding to support our product research and development. Because we don't have a large amount of cash to bootstrap for long.

 

Besides seeking advices from friends, experts from startup hong kong community (Special thanks to Vincent@Primitus and Jonathan@boot.hk), I tried the gov consultation service SUCCESS: https://www.success.tid.gov.hk/tid/tcchi/bas/bas.jsp

 

It is an online helpdesk. I sent a question to them regarding gov funding and the issue of shortage of bootstrapping cash. Their representative replied me within hours on the phone. Some information provided which I think it may be useful to you all.

 

In General

Most of the government funding only support 50% of your cost. It is very good already, because you can purchase equipment and recruit engineers by investing 50%.

If you cannot afford even the 50% of your running cost, the remaining option is low-rate business loan or even no-rate business loan.

If you still think loan is not suitable, or the max. amount they fund is not enough for your project, you can look for investors.

 

Available services

SERAP

SME Fund

SME Low-Rates Loan

Youth Business Hong Kong Loan

HKVCA

 

HKVCA

I haven't looked into the details yet, but I think the hkvca matching corner could help me a bit: http://hkvca.com.hk/hkvcpea/matching.html

It provides a place for teams to look for venture capital. You specify your project status and funding target, then let the investors to approach you.

 

Anything better ?

I personally expect a more interactive way to look for venture capitals in Hong Kong. It is good if there is a pool of investors that I could talk to and show my products or services to. Some open demo events with group of potential investors attending would be good. But still, venture capital is still not that popular and open in Hong Kong yet. sigh ...

After gathering all the information and advises, the best way I can think of is to build the prototype after office hours, and save money from my day time job salary. My target is to have enough money to off work for around 6 months and fully focus on developing several products. And then look for ways to sustain the financial expenses. Hope that this 6 months could happen earlier and then do the real startup earlier.

Thursday, May 26, 2011

Codeaholics HK Lightning Talk: Web Scraping with Ruby

High Level Synopsis

Interesting Data on the internet

some works I did on scraping were scraping information Hong Kong government and using another way to present them. One of them was greenhk: http://greenhk.heroku.com

There are lots of interesting data on Gov website that you can also try: Census and Statistics, Environmental Statistics

 

Did a life demo on scraping openrice restaurant name

  1. Use Firebug to locate the information I want to scrape
  2. Open up Ruby console:
irb
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get("http://www.openrice.com/restaurant/sr1.htm?s=1&district_id=&inputcategory=cname&inputstrrest=")
page.search(".resttitle").count
name_link = page.search(".resttitle").search("a").first
name_link.attribute("href").value

 

Sample program

then I showed the source code of my resumable web scrapers on github

 

One Issue for discussion

I raised one question that people always asked me: "Is it illegal?". My answer was that "grey area, depends on how you use the data".

Because I did present on penetration testing before, and I did mention I played some hacking games too, coders there seems interpreting my hacker/coder image as cracker ... sigh ...

I did performance testing or penetration testing only with authorization. I said "It may be illegal if you use it for commercial activities."

But after the sharing, I think a better answer would be ... the data is published for public usage. You can certainly take contact info like those on openrice and call the restaurant. But I think you would be crossing the line, if you use that data as if you are owning the data and use it for evil things.

Surely this statement is not precise enough, but this is the abstract way for me to determine if something is bad or not.

Wednesday, May 25, 2011

"Who The Hell Made This Change !"

I have a very good team mate now, so I seldom say it recently. But sometimes (especially when I was in my previous companies), you know, everyone is possible to introduce bugs. Sometimes not tracing source of bugs, but cause of the changes. So you need something to trace and find out who (the hell) changed that particular line of code. That's where git blame could help

Here is what you can see with git blame:

git blame menu.css

Name of the author who last-touch that line of code is marked next to the code. Line number is also displayed for you to trouble shoot.

Web Scraper in Ruby

Just written a simple Web Scraper in Ruby for sharing.

It uses MongoDB to store data, use Mechanize to crawl and parse, use Parallel to do multi-threading and then export the results into CSV file.

You can read the source code here: https://github.com/3dd13/web_scrapers_ruby

Coder Presentation Tricks

My favourite trick I like to do during presentation is ...

  1. When we touch something about size of data or scalability
  2. Fire up ruby console
  3. irb
  4. Calculate binary to integer conversion
  5. 2 << 10

Invert Black/White in Mac

I always use my Mac book to play, surf and code, and I prefer lighter background with dark text.

Once I went to a presentation which was inside a small room and people prefer lights-off during presentation. My content was so bright that hurt eyes. Even worse, the text in black was unreadable. During moment like these, a quick and nice solution is to invert the screen colour (White to Black and Black to White).

Of course, you can either go to projector settings or System Preference to do that, but that is too lamb. So, here is the shortcut key to invert the colour:

[Ctrl] + [Alt] + [Mac] + [8]

Being Cool and familiar with your friends (techie tools) is extremely important to attract your audience focus. Prepare some useful shortcuts or coding tricks to stun ~

Tuesday, May 24, 2011

Gov Funding Available in Hong Kong

Gov Fundings Available in Hong Kong

I started with this list (few years old already) http://www.itc.gov.hk/en/doc/download/BK-Benefit_from_TF_Scheme_200704.pdf

Then I targeted 2 of them which are suitable for my tech startup: SERAP and Science Park Incubation Programme.

SERAP

SERAP Guide

http://www.itf.gov.hk/l-eng/Forms/itf-serap-guide_2010_07.pdf

ITF Guide

http://www.itf.gov.hk/l-tc/ITSP.asp

SERAP and ITF Application Form

http://www.itf.gov.hk/l-eng/forms.asp

Science Park Incubation Programme

Overview and Funding area

http://www.hkstp.org/HKSTPC/download/annualReport/HKSTP_Bronchure201101Jan20110317165143.pdf

Criteria

http://www.hkstp.org/HKSTPC/en_html/en_full7_2.jsp

Application Form

http://www.hkstp.org/HKSTPC/download/applicationForm/BDTS_TBI_IA_WF_APP_001_Rev113_Application%20Form20110428170309.pdf

Comments

SME fund looks good too. It funds standalone projects and oversea development/ learning events. But it focus more on helping developed business to expand. So, that's not exactly what benefits me at the moment. You can read the details here.

Science Park one offers office space, some basic facilities and covers marketing promotion cost. However, the funding does not include salary, books, travelling expenses. So, at the same time, I would apply for SERAP to support my R&D expenses too. And then later when my business get more mature, and if I have more standalone projects extended, I will go for SME fund.

Wednesday, May 18, 2011

Codeaholics Meetup | 25May2011 | Boot HK


code@holics:~/meetups/2011/may$ date

Wed May 25 19:00:00 HKT 2011

code@holics:~/meetups/2011/may$ whereis venue

Boot HK,
19/F Hang Wai Commercial Building,
231-233 Queen's Road East,
Wanchai, Hong Kong

code@holics:~/meetups/2011/may$ _

Tuesday, May 10, 2011

推介好睇漫畫俾其他人

剛新加了一些簡單的功能及改進一些CSS。網頁目的很簡單, 就是讓大家分享大家喜歡的漫畫。

如果你GOOGLE"好睇 漫畫", 你會見到很多人都苦惱下一部應該看的漫畫。漫畫數量太多, 而且好睇既漫畫不容易遇見。看一看不同關鍵字的Google Trend作引證吧:

"介紹"及"漫畫"

"好"及"漫畫"

"推介"及"漫畫"

你也開始用Comics Crowd尋找好睇漫畫吧。

Running complicate mongo query without map / reduce

Such query is actually provided in mongo documentation, but I find it useful. Many of my friends are afraid of using MongoDB. They know that MongoDB is faster, but they have no ideas how to do mongo administration and extract information they want.

Map/Reduce and javascript function can do almost everything as SQL database do. But when I say the "you can do this in Map/Reduce, no one find it comfortable. No one thinks "writing map/reduce" is programmer-friendly. When I see their faces, it feels like I am cheating them that Mongo DB is easy to use. But be frank ... Very often, a multi join-ed group by having SQL query looks simple.

So... here is one query that I think most programmer do find it readable and useful to query things in Mongo DB.

db.myCollection.find( { is_active: true, $where: "this.credits - this.debits < 0" } );

It is one of the server-side query you can do. You can pass in javascript function into the where part to do something complicated. In this case, it find all active record and compared the condition of two fields.

More examples in mongo db page.

Yes, there are lots of differences doing things in NoSQL from relational SQL DB, however, provided the capability, I do recommend every programmer to try out one of them, and I would suggest Mongo DB to be the first test bed. Quite mature, large community user base, many articles sharing how to transit from SQL ecology.

Monday, May 9, 2011

use adjacent sibling selectors for Web Scraping

I was using one CSS selector which is less commonly used in my last scraping task. It is called Adjacent Sibling Selector.

The information I needed was hotel links inside the page hotel.hk.

There was no id or class specified for that link and there are tons of link inside the same row, and I did not want to scrape the whole page and then take out that single html. The only specify information I know is that the link is always the next tag element immediately after the span having CSS class "title".

The usage of the selector is like this:

span.title + a

My program is something like this to extract the url in the href attribute:

detail_page_urls = []

page.search("span.title + a") do |title_link|
  detail_page_urls += title_link.attribute("href").value
end

I am using Ruby and Mechanize gem.

Wednesday, May 4, 2011

Domain Name Generator using dictionary service

My team are focusing on prototyping our ideas (we have a really long list of to-prototype-list). So we always bother with project naming and website naming. Random domain name generators do not really work well for us. So, suddenly, I wonder if I can do dynamic search in online dictionary.

The basic requirement is finding words ending with certain top level domain:


Word.all.select{|word| word.end_with?(target_domain)}

That's why I found http://www.onelook.com

It support something like this:


*me:crazy
It should returns english word that ends with 'me' which has meaning related to 'crazy'

Thursday, April 28, 2011

Rubyist should be nice to environment

Jason Ong mentioned about the rubbish bin not easy to find in reddotrubyconf venue: http://jasonong.tumblr.com/post/4977431136/reddotrubyconf-2011-review

On top of that, I suggest spliting recyclable materials. So many cans dropped into rubbish bin. I tried to put some cans together into a paper box. but people thought that paper box was also rubbish bin ... sigh

As a rubyist, we have to be smart in our life and being nice to everything (not only everyone) around us.

Wednesday, April 27, 2011

Using git as engine

Another amazing talk in reddotrubyconf. Tom Preston Werner shared about application utilizing the git capability, i.e. versioning, branches, tag, link files by commit. For example, gollum is a wiki engine use git as storage. Another one is bup using git packfile format to implement the backup system

Video for the same talk can be found here: http://sea.ucar.edu/event/unlocking-secrets-git

Developer codes <-> Author writes

Developer implementing ideas into software pieces is like author writing ideas into books.

Keep writing things you want to tell the world. Some of them may touched someone's heart. (Some may touch no one's heart, though) Some of them may help changing the world. Some of them may just stayed in the book store, looking long for someone to pick it up.

And then one day, all of them will be gathered inside author's Bio, describing the author himself.

Tuesday, April 26, 2011

Another idea prototyping for comic fans: Comics Crowd

I created an application to share fav comic book list: http://comics-crowd.heroku.com/

it is great if you can recommend good comic books to me (and to other people)

need your feedback to improve the website too ~

^___^

Cheers

Written in Ruby On Rails

Open Source at github: http://github.com/3dd13/comics-crowd

Deployed to heroku

Hong Kong Coder, if you are interested in CTF hacking game

VXRL will play the Defcon CTF hacking game in June and we are holding a briefing session for new comers. (most likely taking place in Hong Kong PolyU)

if you are interested, please email Dark Floyd: darkfloyd@vxrl.org

Saturday, April 23, 2011

Red Dot Ruby Conf 2011

Few things I think of after RedDotRubyConf day 1 event:

  • Rubyist =~ Agilist
  • I wish that people having 3G tethering, could form a Wifi access point cluster and share to attendee
  • Singapore's food and drinks are more expensive than 4 years ago
  • Today's talk keep remind me not to be lazy developer
  • Looking forward to RiteVM, to write mobile application in ruby
  • Pivotal Labs has plenty of talented developers

Friday, April 15, 2011

Control application by mind

Saw this company name Neurosky when i visited Hong Kong Science Park. http://www.neurosky.com/

Wonder what happens if i think of "some" websites when I do presentation in front of client. Will it open the website automatically ?! haha

http://3dd13.me - personal website in jQuery and CSS3

There are just too many online profile and resume website, so i take this chance to build my own website describing myself. Applied many jQuery navigation / menu plugins. Enjoy ~

http://3dd13.me

Tuesday, April 12, 2011

Cannot verify Web Master Tools using Google Analytics

Google Web Master Tools provided an option to verify the website ownership with Google Analytics. So, after you placed the javascript provided by Google Analytics, verified successfully by Google Analytics, the Web Master Tools should be verified in few more clicks.

However, after I selected "Link to your Google Analytics account", it keeps saying not able to verified. It turns out that Web Master Tools not able to verify the code snippet that is placed outside head. (the common practice is placing at the bottom of the page, before the end of body ?!).

Therefore, placing the javascript snippet inside your < head >... < /head > will solve this problem.

Saturday, April 9, 2011

Looking forward to new anobii

I wanted to integrate with anobii and found their API really too simple. Their API currently only supports one simple bookshelf query. What I need at the moment is to query my own bookshelf with filters by tags.

I really love anobii and I offered my effort to help integrate their API for free. The reply is that .... they are currently working on the new API !! so excited !! Looking forward to their new API and Good Luck ~

Friday, April 8, 2011

Maven error in ubuntu

One of our projects are using scala with maven. Not sure which dependency was added and then when we did mvn install the com.sun:tools:jar missing error is thrown.

Java is in the class path. Usual guess is JDK versus JRE setup. Tried out few environment variable settings, and we end up solved it by installing the sun java and get rid of the default ubuntu java.

Here are the command from http://yoodey.com/removing-openjdk-jre-ubuntu-1010-ec2-amazon-and-install-sun-java-6-jre-jdk. Thanks !


1. Update Ubuntu Repository
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
sudo apt-get update
sudo apt-get remove openjdk-6-jre-headless
sudo apt-get install sun-java6-jdk sun-java6-jre
sudo apt-get autoremove

2. Set what kind of Java we used in Ubuntu Linux
sudo update-alternatives --config java

You can pick up what kind of Java you need to use.

Thursday, April 7, 2011

Stackoverflow Hong Kong Meetup April 2011

It was great fun last night ~ each of us talked about what we were up to. Beers and pizza@pizzabox

(it is really difficult to find their menu, we have hacked up a simple app to solve this problem: Menu Web Hong Kong )

Btw, I was the only local Hong Kong coder attending. Where are the other hackers ?!

here is a quick meetup summary:

Individuals

Jonathan

He talked about his Makible and shared some concepts in encouraging global manufacturing.

General Sensing

They were doing pet products in Boston. Now they are in Hong Kong working on health care products in hospital.

Jeffery

HTML, CSS and Javascript coder. welcome for projects

Daniel

He restarted coding recently. Playing with rails.

Thought Sauce: Steve Holmes and me

We are delivering an internal financial product (written in Ruby On Rails) for a client. At the same time, we are doing side projects and developing their own web / mobile products.

William Taysom

As usual, William is solving some technically and algorithmic difficult problems. One of them is auction related algorithm optimization.

Other topics about Hong Kong

  • Difficult to recruit the right people in Hong Kong
  • Regular geeky meetup in Hong Kong
  • Why Singapore hackers are doing something that we are not?
  • Why Hong Kong not a good place for hackers and startups (talk about it in another post)
  • Hong Kong has so good positive GDP, but not much teams benefited from it
  • remote area Cyberport has cheaper parking and cinema tickets
  • Why company in Hong Kong use Microsoft?
  • Thoughtworks also not able to sustain their business in Hong Kong ?
  • There are many MIT talents doing interesting projects here

Thanks !

Jonathan, Thank you for offering boot hk as the meetup venue.

Thanks Steve and Thought Sauce, organizing this meetup and sponsored the drinks

Friday, March 18, 2011

Export PostgreSQL into CSV

Redirect console output

First simple way is to redirect the psql console output to file:

\o '/tmp/file.csv'
SELECT * FROM users;

All the result output is redirected to the /tmp/file.csv. and then you open the csv and select the | character as the delimiter.

The obvious problem with this approach is that you cannot have | character in your data. and you also get some other text you dont want, like the result row count: (x row)

Export data into CSV format with header

Postgres has one function called COPY:

COPY (SELECT * FROM users) TO '/tmp/file.csv' CSV HEADER;

In this way, you can have a nicely escaped data with a nice header.

Monday, March 14, 2011

uninitialized constant ActiveRecord::TestFixtures

I saw this uninitialized constant ActiveRecord::TestFixtures error when i run the rake test. I have checked all the environment configuration. I am sure i am using Mongoid without ActiveRecord.

after reading the fixture_support.rb source code, I found out that the error is thrown only if ActiveRecord was called somewhere in my code. and it turned out to be caused by the Transition suggested by krzysiek: http://dev.netizer.pl/transitions-state-machine-for-rails-3.html

So, I have to switch the state machine to another gem which is not using ActiveRecord stuff. that's why i found stateflow: https://github.com/ryanza/stateflow

My test can run happily ever after.

401 unauthorized error in Heroku

if you receive 401 unauthorized when you execute heroku tasks or rake task, most likely you missed the authentication details to execute some heroku actions which required charging money.

for example, if you use autoscaling gem in some classes. You may see this error when you execute the rake task which requires adding more background worker.

to solve it, just configure the heroku user and password. the following line is extracted from workless README page:

heroku config:add HEROKU_USER=<your username> HEROKU_PASSWORD=<your password>

Monday, March 7, 2011

APIGEE - interactive way to write API call

Everytime you write a web app with social network integrated, you need to read through their API and checkout the format. although most of them are RESTful, which is simple enough. However, it is hard to debug when something is not working. is it the URL ? or is it the parameter ? or is it the permission.

Glad that APIGEE provides an interactive API console. It shows available APIs with url format provided. You can also submit the call and review the response, see if that is what you expect.

For example, find out "what things i liked" using Facebook Graph API: https://apigee.com/console/facebook

It says I need authentication ...

it is really easy to do OAuth call thru APIGEE:

a bit freaking out when it asks for facebook permission ....

OK, try again after login with facebook. Yay ~ done!

Monday, February 28, 2011

Show seconds in datetime_select

By default the datetime_select only shows date, hour and minutes. But I do want to show the seconds for user to change. the default way of calling is like this:
<%= f.datetime_select :start_time %>
After I keep bundle open several gems, I found the option in active_pack, date_helper.rb:
@options[:discard_second] ||= true unless @options[:include_seconds] && !@options[:discard_minute]
OK, so :include_seconds can control this behavior, easy job then:
<%= f.datetime_select :start_time, :include_seconds => true %>

Sunday, February 27, 2011

String interpolation in en.yml

suppose we need to create a copyright statement which shows current year dynamically.

in the language text file (en.yml), we expect a variable current_year:

in the layout view, we provide this current_year as hash:

Saturday, February 26, 2011

Using Jekyll, Hyde and Heroku for presentation slides

I was sharing architecture of a RU05 program and performance tuning we did on with Mongo.
Codeaholics Feb Meetup


The slides i showed was actually a web page moving like a powerpoint slides.
The source code to generate the slides is available in github.


here I draft out high level steps giving you some rough ideas of the work required to create such webpage. you can find all the detail steps in jekyll, jekyll_and_hyde and rack-jekyll github page.


install required gems and create project:

gem install jekyll
gem install jekyll_and_hyde
gem install rack-jekyll
jh new codeaholics_hk_feb_2011
cd codeaholics_hk_feb_2011

To prepare deployment for the future, generate the static pages into another folder instead of default _site directory. i used "pages" folder in my case:

in the .gems file, include rack-jekyll
follow the github pages to setup _config.yml and config.ru

You can start creating your powerpoint, and read it at localhost:4000

jekyll --server pages
jh generate frontpage
... // generate your static pages
... // keep your jekyll server running until you finish. i explain why below

When you want to deploy to heroku:

git init
git add .
git commit -m ""
heroku create codeaholics_hk_feb_2011
git push heroku master

One issue i saw when generating post was that. I edited my posts markdown files after I stopped the jekyll server, and later when i started it again, no more static pages generated automatically. I guess the service could no longer recognizes which files was edited. I could not resolve this problem. So, i have to create another project and copy over my markdown files to continue.

Tuesday, February 22, 2011

Hong Kong Ruby Developer Job Market demands greater than supply

Recently, many teams in Hong Kong are recruiting Ruby On Rails developers. However, due to the nature of human laziness, not much people are willing to spare their own time learning Ruby On Rails.


Even though companies are willing to train up new Rubyist, people still do not think being a fulltime Ruby programmer is a good career. All the big players in Hong Kong are using Java, .Net and iOS, it makes career development path for starting as a Ruby developer harder.


The conventional development path for IT worker is promoting to project management instead of development. Salary and job promotion will stop soon if you stay as a coder even though how great program you can write. That's how pathetic it is being a normal developer in Hong Kong. Being a Ruby developer is considered risky and has no future.


here are some of the local Hong Kong companies recruiting RoR developers:
http://thought-sauce.com/jobs.html
http://hk.jobsdb.com/HK/en/Search/JobAdSingleDetail?jobsIdList=100003000539835
http://groups.google.com/group/hkror/browse_thread/thread/b463024bfed4da2f?pli=1
http://groups.google.com/group/hkror/browse_thread/thread/e18d3d3e5338f76f
http://hk.jobsdb.com/HK/EN/Search/JobAdSingleDetail?jobsIdList=100003000529158&sr=1


Regularly, Rubyist are coming from all over the world. Very interesting though. They just give a shout at google group, talk to several people, then they will get the job, fly over and then work here. The supply here internally in Hong Kong is really far far under the demand.


Very often, they compare the advantages of working in Hong Kong with Singapore. Singapore's ruby community and business usage looks much better than that in Hong Kong. Hong Kong is totally in a bad place booting up the culture of applying the edge tools instead of using the popular tools. But that's would be another long story about geographical competitiveness.

Saturday, February 19, 2011

Solved Mac book Pro connecting external monitor

I solved mine !!
i tried diff adapters, update drivers, etc. also did not work.
and my Mac Book Pro does not have "Graphics: Higher Performance" option in my System Preference Display page.

then i tried cleaning the System Preference (Restart, Option + Command + P + R) and now i can use my external monitor!

my spec:
Model Name: MacBook Pro
Model Identifier: MacBookPro5,5
Processor Name: Intel Core 2 Duo
Processor Speed: 2.53 GHz

my symptom was:
- I can connect to my office external monitors (yes, it works with more than one)
- but i cannot connect to any other external monitors
- when i plug the cable, my Mac Book screen flash and then not detecting any external monitor


my references:
http://getsatisfaction.com/apple/topics/macbook_pro_external_monitor_black_out_problem
http://getsatisfaction.com/apple/topics/why_wont_my_macbook_detect_an_external_display

Friday, February 18, 2011

Overflow / page break examples in Prawn PDF generation

I have been using Prawn for a while. Here I gather several overflow / page break examples.


1. Text paragraph overflow

Having several lines of text and I want whole block of text stick together


Solution is using group to hold them together



2. Table rows overflow

Sometime there is no enough space for the last table row when it reaches the end of page, and Prawn does not move it to next page. That's why we have to manually add a page break:



More code snippets available at https://gist.github.com/3dd13

Thursday, February 10, 2011

Using an Asynchronous Controller in ASP.NET MVC

The following just sounds interesting to a dumb web developer!

From: http://msdn.microsoft.com/en-us/library/ee728598.aspx

How Requests Are Processed by the Thread Pool

On the Web server, the .NET Framework maintains a pool of threads that are used to service ASP.NET requests. When a request arrives, a thread from the pool is dispatched to process that request. If the request is processed synchronously, the thread that processes the request is blocked while the request is being processed, and that thread cannot service another request.

This might not be a problem, because the thread pool can be made large enough to accommodate many blocked threads. However, the number of threads in the thread pool is limited. In large applications that process multiple simultaneous long-running requests, all available threads might be blocked. This condition is known as thread starvation. When this condition is reached, the Web server queues requests. If the request queue becomes full, the Web server rejects requests with an HTTP 503 status (Server Too Busy).

Monday, February 7, 2011

nicer HTMLFormatter in RSpec 2.5.0

from http://blog.davidchelimsky.net/2011/02/06/rspec-250-is-released/

a simple but useful test case filtering checkbox is available. then you dont have to create your own custom RSpec::Core::Formatters::HtmlFormatter.

change Heroku timezone

I had one application hosted at Heroku. A bug was found that several date fields are incorrect. I thought it was something about date time formatting with strftime. but it turned out to be the timezone difference between my development machine and the Heroku instance. Time.now returns different values in these machines.

here is the command to update the Heroku timezone:
heroku config:set TZ=Asia/Hong_Kong

Thursday, February 3, 2011

Wednesday, February 2, 2011

Alternative to PuTTy

I've used PuTTY as SSH telnet client in windows for couple of years. It has been doing a great job so far, but now I do want a better one. At least, a new one could provide multiple tabs.

I find an alternative Poderosa.

Its look is quite nice, simple and now I can telnet with multiple tab session. One downside it trades is more configurations have to be done before you open a connection. And thus a bit slower in creating session.

Tuesday, February 1, 2011

Bring back your productivity with symbolic links and alias

Symbolic links


Everyday you go into dozen of different working directories for work, keep typing cd xxx/xxx/xxx/ just slow you down. Use symbolic links to gather shortcuts.


ln -s [target_directory] [name_of_the_link]

For example:

ln -s ~/projects/ru05/playground/menu_web ~/menu_web

then everytime you want to go somewhere, just execute

cd ~/menu_web

one shot, no pain
it's cool


Alias

I was working in a company which only gave development team a tiny harddisk space for UAT, and there were many applications deployed by different teams. Obviously, not everyone cares about housekeeping their own shit. So I frequently had to check the disk space ...

many people knows about du -sk to check spaced used, but I also want to sort the result. here comes the long command:

du -skc * | sort -rn

To keep my hands and finger healthy, I created alias to type less:

alias dusk='du -skc * | sort -rn'

Better save some time doing other meaningful stuff instead of repeatedly typing mundane commands.

LessTimeSpent - more natural way of time tracking and communication

My team is working in flexible hours and sometimes distributed in different locations (Home, Coffee Shop, Travelling). Many projects running in parallel which are charging by man hour. So recently, we are trying different ways of tracking our time spent on each project in a simple and less restrictive way. LessTimeSpent fits our purpose.


http://lesstimespent.com




It is simple. just start or stop the timer. then it will start accumulate your time towards the project. Total time spent by the team is displayed. Add a simple note next to the timer, then you can tell others what you are planning to do now. So, after a period of time, you can see the high level picture of effort spent on the project.


The expense feature is not useful to us, but i think some ppl would love to use that for simple accounting.


Every time i sit down at some places start working, put down what i would like to do, click start button. It is kind of like "Stand Up" in agile practices. Oh Right, perhaps it is a good idea to review yesterday's stand up too.

Thursday, January 27, 2011

Adding log purging job using Chef

Previous post talked about the linux command to purge old log files. Here is the way of doing the same thing, but with chef


cookbooks/housekeep/recipes/default.rb



# we need cron for scheduler
package cron do
  action :install
end

include_recipe "housekeep::clear_log"

cookbooks/housekeep/recipes/clear_log.rb



cron "housekeep application log files" do
  user "housekeeper"
  # mailto "your@example.com"
  
  # 00:01 every night
  hour "0"
  minute "1"

  # clean up logs older than 30 days
  command "/find ~/log/application-*.log.tar.gz -mtime +30 -exec rm {} \;"
end

Snippet available in gist:https://gist.github.com/798157

Linux searching for files order than X days

one of the frequently used commands for system maintenance is purging old files, e.g. log files, database backup, temporary files.


find ... -exec Command

In Linux, to search files older than 30 days:


find ~/log/application-*.log.tar.gz -mtime +30


to remove the files returned by find command, use option exec:


find ~/log/application-*.log.tar.gz -mtime +30 -exec rm {} \;


Adding a cron job

Edit the cron job list


crontab -e
Add the following lines:

# m h  dom mon dow   command
# MAILTO=your@example.com
0 1 * * * find ~/log/application-*.log.tar.gz -mtime +30 -exec rm {} \;
Note that the job is added to the cron job list of current login user. The find and rm command will also be executed as login user.

RabbitMQ Nameless Exchange

Not that sweet!

---
Nameless exchange

In previous parts of the tutorial we knew nothing about exchanges, but still were able to send messages to queues. That was possible because we were using a default "" empty string (nameless) exchange. Remember how publishing worked:

channel.basic_publish(exchange='',
routing_key='hello',
body=message)

The empty string exchange is special: messages are routed to the queue with the name specified by routing_key, if it exists.

Hello RabbitMQ

Conceptually, RabbitMQ is a message post office.

Casting
Broker is the physical post office.
Exchange is a named message box.
Queue is a queue.
Binding uses Routing Key to bind a Queue to an Exchange.
Producer delivers message to Exchange with a Routing Key.
Consumer consumes message from Queue.

Scenario
Broker: localhost
Exchange: StockMessageBox
Queue 1: 9OnQueue
Queue 2: 9SingQueue
Queue 3: 9BQueue
Binding 1: StockMessageBox => Price.700(Routing Key) => 9OnQueue
Binding 2: StockMessageBox => Price.716 => 9SingQueue
Binding 3: StockMessageBox => Price.# => 9BQueue
Producer: HKEX, which delivers stock price to StockMessageBox
Consumer: 9On, 9Sing, 9B, who consumes stock price from their queues

--
Now Producer HKEX publishes messages into StockMessageBox

JSON published: {Routing Key: Price.700, Close: 5.3}
Matched queues: 9OnQueue, 9BQueue

JSON published:{Routing Key: Price.716, Close: 3.2}
Matched queues: 9SingQueue, 9BQueue

JSON published:{Routing Key: Price.992, Close: 22.5}
Matched queues: 9BQueue

JSON published:{Routing Key: News.700, Info: "Profits increase 20%!"}
Matched queues: None
--

StockMessageBox(the Exchange) forward messages to queues by matching the Routing Key in the message and the Binding.13:19 27/01/2011

Wednesday, January 26, 2011

Timing your rake test cases in Rails 3: test_benchmark

i was overriding the setup and teardown of ActiveSupport::TestCase in test_helper to time my rake test cases. but in my current project, there are many test cases already overriding the setup method. So, if i still use this way of time tracking, I would have to change too many files.

so, after googling (oh, this google-ing form passes the checkspell ! ) site:github.com, i found test_benchmark. it is super easy to setup.


Include Gem and Rake

if you are using Rails 3, just

  1. add following line to Gemfile (better put it in group :test):
    gem "test_benchmark"
  2. run:
    bundle install
  3. run:
    bundle install
    (or rake test:units if you want to find slow model test cases)

then you can see the top 15 slowest test cases:


Turn it off

you dont want to see all this figures every time you rake test. to switch it off, provide
rake test BENCHMARK=false


Turn it off by default

this is cool gem and some options available to configure.
but actually, i want the other way round.
I want it off by default and turn it on ad-hoc

so i added one line in my test_helper.rb:
Test::Unit::UI::Console::TestRunner.set_test_benchmark_limits(0, 0) unless ENV["SHOW_TIME"]

so now the usage becomes
rake test SHOW_TIME=true



there are some more options there, check out the details at timocratic github:
https://github.com/timocratic/test_benchmark

Tuesday, January 25, 2011

Regular Expression Generator


PerlPHP Python Java Javascript ColdFusion C C++ Ruby VB VBScript J#.net C#.net C++.net VB.net


This is simple and brilliant idea !
http://txt2re.com/

it provides suggestion of string groups and possible data type,
you just need to click and select
it provides the code snippet for every programming language mentioned above too.

Saturday, January 22, 2011

Finding Intersection of streets using Google Geocoding API

after releasing the Green Hong Kong to public and open source it,
my next step is to improve the accuracy of Recycle Bins location.

my last release was just blindly submitting the whole address (not an exact address) string to Google Map API and asked for possible locations.
First, i submit the chinese address.
if no response for chinese address, then i submit again with english address.

Using this way i got almost 99% latitude and longitude back.
BUT, most of them are not accurate.


There are variety of recycle bin addresses Government website provided.
e.g. near the MTR exit, outside XXX Building, opposite to the Bank, near the XXX Lamp Pole, etc.
basically the text is clear ... to me, but not the computer.
so i need to enhance the intelligent in determine nearest latitude and longitude of the recycle bins.


First case i want to tackle is the intersection case.
Government website told me that some recycle bins are located at the intersection of 2 streets.
my first thought is using simple maths to draw 2 straight lines and calculate the intersection.
i look at the Google Geocoding API,  see if there is any concrete data about the street.
then i find out that there is a Address Component Type called "intersection".
which is actually what i needed.

alright, I am getting lazy, because Google did everything for me already.

Thursday, January 20, 2011

First time on Heroku

saw my colleagues using that for a while.
this is the first time i start using it from scratch.
http://greenhk.heroku.com


Besides the performance gain by this cloud hosting thing, the most surprising thing is the powerful toolset it comes with.

1)
Deployment is just a line of command

git push heroku master

then it will push your code to the git reportsitory, handle all the migrations and restart the rails application.

2)
It's like connecting to an application running on your local machine

Troubleshoot on the remote production server and tail the log is just a line of

heroku logs --tail

then it will send back the next block of log incremental changes.



and ... it is free !!
to me, i don't need big database thingy, so i can apply the free plan and just enjoy the performance and simplicity it provides !!



Pivotal Tracker no longer free ...

my company has been using it for a while.
it's time to re-evaluate the online story management application again ~