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.