Fred Wu

@fredwu
Legendary
CTO by day, freelancing software consultant by night. Founder of Persumi.
@fredwu 14 years ago in Tech | 1 min read | no comments
jQuery Endless Scroll has now been updated to work with any DOM elements, not just $(document). Click here for the project page (with usage examples). Click here for a simple demo. Enjoy!
@fredwu 14 years ago in Tech | 1 min read | no comments
Sometimes we would want to throttle certain application actions. For instance, a user should only be allowed to send x amount of emails to other members of the site in order to reduce the spam risk. Since this is a quite common task, I thought I might as well make it as a Rails plugin for better code reusability. I am now releasing Action Throttler, an easy to use Rails plugin to quickly throttle application actions based on configurable duration and limit. Go check out the code now! :) There ...
@fredwu 14 years ago in Tech | 1 min read | no comments
Yesterday we have launched the new design of Creattica. It runs well during the testing and staging phase, unfortunately the server quickly became overloaded and unresponsive after the relaunch was made public. The site was running fine with its old design, but because the new design has many added features such as search filters, followers and more, system resources were very quickly drained. After some optimisation of the database (which itself has increased the site performance by up to 300%...
@fredwu 14 years ago in Tech | 1 min read | no comments
[] Busy at work…
@fredwu 14 years ago in Tech | 1 min read | no comments
A simple Google search will reveal that there are a number of different App_Config plugins for Rails. After comparing them side by side, I have decided to use the one by Christopher J. Bottaro. It features: - simple YAML config files - config files support ERB - config files support inheritance - access config information via convenient object member notation I just fixed a bug last night (which was pulled in to the main repository) where it could throw errors when used as a Rails plug...
@fredwu 14 years ago in Tech | 1 min read | no comments
So you were wondering why some of your model attributes weren’t updating properly? Well, it is perhaps because the db schema has changed but the changed schema has not been passed onto ActiveRecord, as is often the case in DB migration. Taken from the ActiveRecord documentation: Resets all the cached information about columns, which will cause them to be reloaded on the next request. The most common usage pattern for this method is probably in a migration, when just after creating a table you ...
@fredwu 14 years ago in Tech | 1 min read | no comments
When you are getting an HTML string from an external source (e.g. from an AJAX get result) and you want to rip out a certain part of the HTML source, you need to make sure that the ‘certain part’ is not at the top level of the HTML source. For example, we have the following HTML string: Hello World If we want to get the first paragraph element by using: // data is the HTML source $('span#first', data) The above code won’t work, because the p tags are at the top level. Instead...
@fredwu 14 years ago in Tech | 1 min read | no comments
It was confirmed that DataMapper is incorrectly setting table names in SQL JOINs. So for instance, the following code would generate an SQL error: type.jobs.all(:"country.name".like => "%#{params[:location]}%") There is a workaround, however the workaround requires manual looping of the dataset thus produces N+1 queries. type.jobs.all.reject do |job| ! job.country.name.downcase.include?(params[:location].downcase) end But at least it works. ;)
@fredwu 14 years ago in Tech | 1 min read | no comments
It has been confirmed by DataMapper’s core developer Martin Gamsjaeger (snusnu) that it is a bug. In short, created_[at|on] can be manually overridden, but updated_[at|on] cannot. The workaround is simple, do it in two steps, for example: job = Job.create( title: "Web Developer", created_at: Time.now - 2 ) job.update!(updated_at: Time.now - 1) Please check the bug ticket to see when it’s getting fixed.
@fredwu 14 years ago in Tech | 1 min read | no comments
If you are using rake spec to run the specs. Try using spec spec instead! It avoids doing some preliminary tasks and therefore is quicker to execute. You can verify the difference using Unix’s time command, i.e. time spec spec and time rake spec.