2010年3月21日 星期日

migration

2010年3月10日 星期三

rjs page

page['foo']['style']
# => $('foo').style;
page['foo']['style']['color']
# => $('blank_slate').style.color;
page['foo']['style']['color'] = 'red'
# => $('blank_slate').style.color = 'red';
page['foo']['style'].color = 'red'
# => $('blank_slate').style.color = 'red';

respond_to jsonp

respond_to recognizes • JSON.
render :json => @person.to_json automatically sets the content type and takes a :callback option to specify a client-side function to call using the rendered JSON as an argument. #4185 [Scott Raymond, eventualbuddha]

Bootstrap Initializer

Bootstrap Initializer
The files in config/initializers are loaded after Rails' environment is loaded (including environment.rb). However, there's a pre-environment
hook provided for you should you need to do things prior to Rails' environment getting in the mix: just create a config/preinitializer.rb file.

This file is loaded after the Rails classes are loaded but before the environment file and the environment configuration.

2010年3月9日 星期二

rescue_from Exception Handlers

rescue_from Exception Handlers

2010年3月5日 星期五

Top 8 SQL Best Practices

Top 8 SQL Best Practices

1) Always use explicit joins. If I mean INNER JOIN, then I use INNER JOIN. No use of just plain "JOIN". Never, ever, ever use a comma join -- I consider that a mistake. If I explicitly state "CROSS JOIN" then I know I have consciously made that decision. Also, keep join conditions in an ON or USING clause; they should not go in the WHERE clause. I also put my join conditions in parentheses; for whatever reason, I find:
ON (foo=bar AND baz=bop) WHERE a=b
is easier to see that the join condition contains 2 conditions than
ON foo=bar AND baz=bop WHERE a=b

SQL Server TSQL Coding Conventions, Best Practices, and Programming Guidelines

SQL Server TSQL Coding Conventions, Best Practices, and Programming Guidelines

Try to avoid wildcard characters at the beginning of a word while searching using the LIKE keyword, as that results in an index scan, which defeats the purpose of an index. The following statement results in an index scan, while the second statement results in an index seek:

SELECT LocationID FROM Locations WHERE Specialities LIKE '%pples'
SELECT LocationID FROM Locations WHERE Specialities LIKE 'A%s'

Also avoid searching using not equals operators (<> and NOT) as they result in table and index scans.






Use 'Derived tables' wherever possible, as they perform better. Consider the following query to find the second highest salary from the Employees table:

SELECT MIN(Salary)
FROM Employees
WHERE EmpID IN
(
SELECT TOP 2 EmpID
FROM Employees
ORDER BY Salary Desc
)

The same query can be re-written using a derived table, as shown below, and it performs twice as fast as the above query:

SELECT MIN(Salary)
FROM
(
SELECT TOP 2 Salary
FROM Employees
ORDER BY Salary DESC
) AS A

This is just an example, and your results might differ in different scenarios depending on the database design, indexes, volume of data, etc. So, test all the possible ways a query could be written and go with the most efficient one.





While designing your database, design it keeping "performance" in mind. You can't really tune performance later, when your database is in production, as it involves rebuilding tables andindexes, re-writing queries, etc. Use the graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or SHOWPLAN_ALL commands to analyze your queries. Make sure your queries do an "Index seek" instead of an "Index scan" or a "Table scan." A table scan or an index scan is a very bad thing and should be avoided where possible. Choose the right indexes on the right columns.





Use the more readable ANSI-Standard Join clauses instead of the old style joins. With ANSI joins, the WHERE clause is used only for filtering data. Where as with older style joins, the WHERE clause handles both the join condition and filtering data. The first of the following two queries shows the old style join, while the second one shows the new ANSI join syntax:

SELECT a.au_id, t.title
FROM titles t, authors a, titleauthor ta
WHERE
a.au_id = ta.au_id AND
ta.title_id = t.title_id AND
t.title LIKE '%Computer%'

SELECT a.au_id, t.title
FROM authors a
INNER JOIN
titleauthor ta
ON
a.au_id = ta.au_id
INNER JOIN
titles t
ON
ta.title_id = t.title_id
WHERE t.title LIKE '%Computer%'

rails performance memo

2010年3月3日 星期三

That’s Not a Memory Leak, It’s Bloat; refactor

That’s Not a Memory Leak, It’s Bloat

respond_to

Restful memo

2010年3月2日 星期二

Rails Best Practices

Rails Best Practices

2010年3月1日 星期一

Advanced Active Record Techniques: Best Practice Refactoring

Advanced Active Record Techniques: Best Practice Refactoring

Rails Code Review PDF

http://peepcode.com/products/rails-code-review-pdf