Feb 21, 2009

Compile do_mysql on OS X(Mac)

I was trying to upgrade DM to the latest version the other day, but I failed miserable:


I also noticed that there is a plugin dm-constraints, I haven't check it out yet, but it seems like the same, here is the code from the plugin:


I filed an issue report on lighthouseapp.com.

UPDATE(Feb-21-2009): Just got the note from Dan Kubb( one of the core DM developers):
"The Collection#destroy! method is actually supposed to bypass all hooks. The way you're doing it by looping over the records and calling each Resource#destroy method is the proper approach to execute each Resources' hooks.
In dm-core 0.10.0 there will be a Collection#destroy method that wraps this up and essentially does the same thing."

This makes a lot of sense. Like always, I really appreciate the attitude of the developers from DM, that is one one the reason I am using DM.

Feb 7, 2009

Smart Sleep - Mac OS X

I can't remember since when Apple decided that when you sleep your laptop, it will write all the data in memory to the hard drive, then go to hibernate. It is a good thing if you are on road, and want to change the battery. Once you power it on, every thing just like before you swap the battery. But for me, I've had 4 apple laptops, I've never done this for a single time. Especially for my latest MacBook Pro, I have to wait it to dump 4GB memory on to hard drive every time. And most of the time, I found it is even faster if you just power off it. I would be more happier if it can go to sleep right away when I close the lid.

Now, you can do that - SmartSleep PrefPane. I've been looking for something like this for a while. Why I love it, you know, now, I can get home 5 mins earlier every day. :-)

Feb 1, 2009

Bigger system fonts on Mac

Maybe I am too old[I am not :)], or I am working with too many 'elder' people in office, I was frequently asked "How can I get bigger fonts on my screen?". Well, I am not talking about "CMD +". It is too easy, most of the situation, they want every thing if possible.

First, I found "Quartz Debug".

I must to say it is very interesting. You should try it out if you've not yet. You will get the bigger fonts as you want, menu, labels... But it may have some problem when rendering the mouse.(Here, on an iMac). All that said, I am supposing you know what you are doing...

Then I tried "TinkerTool".

It is a very nice app. Not only the fonts, it can do other stuff for you too. e.g, I am putting the dock on the left-bottom now. :-) I would like to recommend TinkerTool for changing the fonts.

Jan 25, 2009

PDF generation with Prawn in Merb

In my company, the customer service representatives asked me to generate a PDF file format of the price letter for our customers, because those are relative sensitive files, which was used to be in M$ word format.

I started using HTMLDOC at first, which is fine if you've already had the HTML version. Really, I like it. It is pretty simple to set up and running. You do not need to care about too much about the layout and format of the file, because it is relatively easy to do that in a html.erb file. But there is a catch on production servers, if you have, like me, several different types of environment, Red Hat, Ubuntu, OS X, you really have to be care of the PATH to the binary htmldoc command. Otherwise the Phusion Passenger will throw out very strange error message.

After I came back from Ruby Conf 2008(if you were there, you problaly knew Gregory Brown, he held a hack session with Prawn.), so I decide to give Prawn a try.

Here are the steps( of cause within Merb):

1. Add mime type in your config file

2. In the view file, the form for the PDF request:

Please notice the :format => 'pdf'
3. In controller, provides the pdf format:


From here, you have two ways to send the PDF file:
In the controller/action

Or, in a pdf.erb file

Now, you should be able to get a PDF file.

UPDATE(Feb-23-2009):
Someone asked what if you using 'GET' instead of post?
Well, it is pretty simple, you can just add the format like:
resource(:ordering, @price_letter, :print, :format => :pdf)
I am hoping this is helpful.

Jan 17, 2009

jQuery: unobtrusive javascript form submit with Ajax in Merb.

I was working on a project this week. There are several forms on one page, I want to submit any form without leaving the page. At first, this requirement really bothered me for a few minutes, after reading some documents from jQuery and Merb, it turns out pretty easy to implement:

1. View - file which have the forms you want to submit
In your form.html.erb file, you can create them like the normal forms.

2. Javascript(jQuery)
Here is the javascript to do the unobtrusive form submit.

3. Controller
In your controller's action, you have to specify provides :js

4. View - file which does the render
This is the good part I like Merb, you can mix Ruby code and javascript together to operate the DOM.


It is pretty easy and handy.