Strip Generator October 21, 2007

Posted by Predrag in : Resources and Links, Web Design , 1 comment so far

While working on re-wamp of one of our old projects, I stumbled on one entry describing Strip Generator website. I am amazed with this website.

It is for creating one-line strips for free, with predefined characters and objects - so easy to use! For all this time I spent working as a Web Designer I met so bizzare people and dealt with so many different situations… and I think this is the best way to present them. These guys made a hell of an effort to make this work and furthermore - this looks fantastic.

Here is what I created in 10 minutes.
Dealing with clients.

Don’t mind me saying - but I created my own strip blog as well. :)
Try and enjoy!

Use Rails logger in tests October 5, 2007

Posted by Slobodan Kovacevic in : Resources and Links, Ruby & Rails , add a comment

For some debugging in Rails test we wanted to be able to log data via Rails logger. Unfortunately, as it turns out you cannot directly access logger from tests (which is strange). Since we needed to add information to test.log we used this small piece of code (added to test_helper.rb):

def logger
RAILS_DEFAULT_LOGGER
end

and just use it in tests like this:

logger.info(’performing test now’)

[via Robby on Rails]

New Free 1280×800 wallpaper August 26, 2007

Posted by Predrag in : 1280x800 Wallpapers , 3 comments

Finally I’ve found some creativity inside :) With temperatures over 35C I just couldn’t do it. This one is calm, maybe too green and dark, but it fits with my current mood. I have some brighter variations in mind, so I’ll keep you notified once I add it.

In order to see the point of this wallpaper, turn your laptop upside down :) If you have a desktop, it’ll be a bit tricky.

Anyway, here it is and let me know what you think.
Hot Shot Designer

You can find more free 1280×800 widescreen wallpapers on this page.

Nested :include ActiveRecord option June 23, 2007

Posted by Slobodan Kovacevic in : Programming, Ruby & Rails , add a comment

While working on a site I had User, Order, OrderItems and Product models and they were related like this:

Order belongs_to User
Order has_many OrderItems
OrderItem belongs_to Product

So, when displaying an order I found myself doing accessing product through order_item, i.e. @order.order_items.product.name.

Although this worked problem was that even though I have told Rails using :include to eager load order_items it didn’t load products, so whenever I accessed a product it executed a separate SQL query. In other words, to display order with 10 products it required 11 SQL queries - hardly optimized.

Rails API documentation doesn’t say anything about eager loading “second” level, but after some searching I found that you can do that you can do nested :includes, like this:

Order.find(id, :include => [{:order_items, :product}, :user]

This will eager load User and OrderItems, but it will also eager load Products under each OrderItem. This decreased my number of queries from 11 for 10 product order to only one (big one).

You can read more (for example, it appears that you can nest multiple :includes) about this undocumented feature in ‘The beauty of a nested ‘:include’ option’.

LocalizationSimplified April 26, 2007

Posted by Slobodan Kovacevic in : Ruby & Rails , 4 comments

Rails is excellent in handling almost everything if you are building a site in English. Unfortunately, when it comes to localization (sites in other languages, UTF-8 support, etc.) Rails is not very well equipped to handle it.

There are localization plugins that make life easier, but most of them are rather complex, hard to use and have significant overhead (i.e. takes time to setup, learn, etc.). Fortunately, plugin called Localization Simplified aims to simplify localization as much as possible:

Fast and easy localization of one-language applications. Adds UTF-8 support for Ruby + database. Modifies ActiveRecord errors + html error helpers, Date/Time helpers, locale time formats, to_currency, to_sentence

It’s easy to use mainly because it only overrides existing Rails methods, so you don’t have to do anything special to use it.

Localization Simplified is a great plugin which you can download from Ruby Forge.

1280×800 Widescreen Wallpapers March 26, 2007

Posted by Predrag in : Resources and Links, 1280x800 Wallpapers , add a comment

small_wallpapers.jpg

In order to keep all our wallpapers in one place, we decided to create a separate page for all of them. So, if you wish to check them out, go to this page, or follow the link below.

Much more to come very soon!

View All 1280×800 Widescreen Wallpapers

Rails Source Code Annotations March 4, 2007

Posted by Slobodan Kovacevic in : Ruby & Rails , 1 comment so far

Ruby On Rails
I’ve been catching up on my blog reading and I’ve stumbled upon an article describing a great new feature in Edge Rails that lets you add annotations to your code. You can use TODO, OPTIMIZE and FIXME to mark parts of your code. Then you can use rake notes to list annotations - which is great since you won’t miss any of the notes you made.

The only problem is that this is still in only in Edge Rails, i.e. it’s not yet in stable Rails release. But there’s a really simple way to add source code annotations rake task to non-Edge Rails app:

svn export http://svn.rubyonrails.org/rails/trunk/railties/lib/tasks/annotations.rake \
 lib/tasks/annotations.rake

For more information about Rails source code annotations see Ryan’s blog.

MySQL insert a new row or update old one February 16, 2007

Posted by Slobodan Kovacevic in : Programming, Resources and Links , add a comment

Today I stumbled upon a newish MySQL feature that can often be very useful. Since MySQL 4.1 there’s a non-standard feature (i.e. it’s an extension of SQL standard and won’t work on other databases) that lets you insert a new row, but if it happens that a row with same primary/unique key already exists it will just update that row.

Insert query syntax looks like this:

INSERT INTO table (primarykeycol,col1,col2) VALUES (1,2,3) ON DUPLICATE KEY UPDATE col1=0, col2=col2+1

If there is already a row with primarykeycol set to 1 this query is equal to:

UPDATE table SET col1=0, col2=col2+1 WHERE primarykeycol = 1

Ordinarily to achieve the same result you would have to issue an UPDATE query, then check if there were affected rows and if not issue an INSERT query. This way, you can do everything in one step - first try insert and then update if insert fails.

One situation for which this type of syntax is perfect is when you work with daily counters. For example, you might have a table with PostID, Date and Count columns. Each day you’d have to check if you already created an entry for that day and if so increase the count column - and this can be easily substituted with one INSERT … ON DUPLICATE KEY UPDATE query.

Unfortunately there are some caveats. One being that when you have multiple unique indexes it will act as if you had an OR condition in WHERE clause of UPDATE query. This means that multiple rows should be update, but INSERT … ON DUPLICATE KEY UPDATE will update only one row.

For more information you should read article in MySQL manual: INSERT … ON DUPLICATE KEY UPDATE Syntax

Free Web based color scheme creator February 3, 2007

Posted by Predrag in : Resources and Links, Web Design , 2 comments

I simply enjoy this kind of stuff. Specially if client doesn’t have any specific color scheme request. This color cycle is easy to use and you can generate great color schemes, if you know where to click.

Color cycle

First, click on the buttons below the cycle and choose from (Mono, Contrast, Triad, Tetrad and Analogic). Then, play around with colors and see what you’ll get. Use variations to set the colors perfectly. There is also a simple preview where you’ll be able to see how colors fit. I prefer dark and light pastels myself.

Here is the link to Color Scheme Creator. Enjoy.

Niceforms 1.0 - final version January 31, 2007

Posted by Slobodan Kovacevic in : Programming, Resources and Links , 2 comments

Niceforms 1.0Over a year ago I wrote about an excellent script called Niceforms and little fix I wrote (see NiceForms with even nicer select). Now a final version has been released - Niceforms 1.0 which solves a lot of problems from previous version.

I still haven’t had chance to look at the new improvements but it seems that Niceforms now supports keyboard only navigation, scalable buttons, increased browser support, etc.

Unfortunately it still has some of the problems I tried to fix more than a year ago. Granted they tried to fix it, but it still has problems. For example, when you click on a select element if you move over some options and then move out it will immediately close the drop down. On the other hand if you open select element and don’t move over to any options (i.e. click on down arrow), but you move the mouse away from it - the select will remain open, which can again lead to strange effect where you can have a lot of open drop downs.

Perhaps that can be fixed in future versions - or at least I will try to make a patch for it.

If you want to get Niceforms 1.0 you can from author’s site.