Posted by Jorge Bernal June 25, 2007
For what I’ve seen, it seems some of you also have photography as a hobby. Some days ago I found a review for Understanding exposure
at Understanding Exposure by Brian Peterson - a Reader Review
Easy to read and straight-forward, Understanding Exposure offers the basics of aperture, lighting and shutter speed, photography’s basic triumvirate, to beginning and intermediate photographers. The book is divided into these three topics, as well defining exposure, special techniques, and a discussion of film vs. digital. This is not a highly technical book and any technical points are well-written and easy to understand.
My question now is if any of you have this book and recommend it. Should I get it or it has nothing I can’t found reading photography blogs and forums?
Posted in Photography | 4 Comments »
Posted by Jorge Bernal June 15, 2007
One of the basic advantages of using open source software is having the ability to change its behaviour to suit your needs. That’s awesome, but what happens when it’s a web application like trac? Sure you could change it, but if it’s your company trac you might be the only one wanting fo change a specific behaviour.

One of the things that most annoys me is having to use the mouse to create a ticket. If I fill the fields using only the keyboard (the day I learned to use the Tab key to switch between fields was a major breakthrough in my digital life) and hit Enter to submit the ticket, trac does a preview instead of creating it. I’m not sure if you can override this behaviour using some special attribute, but the button used with Enter is the first one to appear in the HTML. So I had to turn it into this:

I’ve used Greasemonkey for this. Greasemonkey is a Firefox extension which lets you write JavaScript code to modify the pages you visit, so I did a quite simple user script to switch the buttons order in any trac ticket page.
If you find this interesting, download the script:
[switchtracpreview.user.js]

Posted in Uncategorized | 3 Comments »
Posted by Jorge Bernal June 14, 2007
From Urban Dictionary’s word of the day:
“Laughing quietly to myself.” A more accurate representation of the human response to funny things seen on the interweb.
When people type lol, rarely are they laughing aloud for the whole world to hear, but merely smiling and laughing quietly to themselves.
Posted in Quotes | 3 Comments »
Posted by Jorge Bernal June 14, 2007
Let’s say when you have to run a batch process monthly, you can survive with times like 10 minutes. I can imagine a lot of seasoned DBAs right now ROFL about my insignificant 10 minutes. The point here is I was developing this process and some test cases, so my usual trial/error methodology doesn’t scale very well with 10 minute offsets.
So I borrowed an idea from a colleague: why not moving all the database to memory? It’s not so big and I have 2G of ram. But, could I change all tables (~20) to MEMORY in one line or so?
Since this was a Ruby on Rails project, I used the rails console to be able to mix SQL and Ruby. My first try:
conn.tables.each do |t|
conn.execute "ALTER TABLE #{t} ENGINE=MEMORY"
end
First error: foreign keys couldn’t be migrated from InnoDB to MEMORY
Maybe there is a more MySQL-esque way of dropping all the foreign keys on a database but this one worked quite well:
>> res = conn.execute "SELECT TABLE_NAME, CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE K
WHERE table_schema = 'app_development'
AND REFERENCED_TABLE_NAME IS NOT NULL"
>> res.each_hash do |h|
conn.execute "ALTER TABLE #{h['TABLE_NAME']}
DROP FOREIGN KEY #{h['CONSTRAINT_NAME']}"
end
>> conn.tables.each do |t|
conn.execute "ALTER TABLE #{t} ENGINE=MEMORY" rescue nil
end
Still I had some problems with a few tables using BLOBs, but they were not used on the process/tests so I ignored them. That’s what the rescue nil is for.

Posted in Uncategorized | 6 Comments »
Posted by Jorge Bernal June 12, 2007
This is my second article about hacking MySQL. If you are interested in this topic, you may want to read my previous Hacking MySQL: SIGNAL support (I)
The problem
If I tell you there is a function called TRUNCATE, what do you think it does? which are its arguments?
For me, the obvious behaviour would be something like:
mysql> SELECT TRUNCATE(123.45);
+--------------------+
| TRUNCATE(123.45) |
+--------------------+
| 123 |
+--------------------+
1 row in set (0.08 sec)
But the actual behaviour is this:
mysql> SELECT TRUNCATE(123.45);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
This is because TRUNCATE requires a second argument. The syntax, according to the manual, is:
TRUNCATE(X,D)
Returns the number X, truncated to D decimal places. If D is 0, the result has no decimal point or fractional part. D can be negative to cause D digits left of the decimal point of the value X to become zero.
Wouldn’t be cool if the default value for D were 0 if we don’t specify otherwise?
The solution
This time we only have to touch the parser (sql/sql_yacc.yy). The code for this is quite simple, although you might find some problems on type conversion.
--- mysql-5.1/sql/sql_yacc.yy 2007-05-08 12:25:51.000000000 +0200
+++ mysql-5.1-truncate/sql/sql_yacc.yy 2007-05-08 15:55:42.000000000 +0200
@@ -6741,6 +6741,13 @@
{ $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
| TRUNCATE_SYM '(' expr ',' expr ')'
{ $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
+ | TRUNCATE_SYM '(' expr ')'
+ {
+ THD *thd= YYTHD;
+ Item *i1= new (thd->mem_root) Item_int((char*) “0″,(int32) 0,1);
+
+ $$= new (thd->mem_root) Item_func_round($3,i1,1);
+ }
| WEEK_SYM ‘(’ expr ‘)’
{
THD *thd= YYTHD;
Get the patch: [28304-truncate_default_value.diff]
Like I said, the hardest part was to go through sql/item*.h trying to guess the expected type for Item_func_round and how to cast that type correctly. I should learn how to better debug the MySQL server.
Conclusion
Unfortunately, the bug (#28304) has been marked as to be fixed later but, at least, this helped me on my way to understand MySQL internals.

Posted in Uncategorized | No Comments »
Posted by Jorge Bernal June 11, 2007
It seems I’m a ruby guy after all:
$ history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c | sort -rn | head -10
111 svn
61 cd
44 rake
36 l
32 hg
18 ./script/console
14 rm
12 screen
12 history
12 ./script/server
Posted in Personal, Technology | 9 Comments »
Posted by Jorge Bernal June 06, 2007
It’s been almost a year and a half since I got my first DSLR camera, a Nikon D50. It’s a nice camera and I’ve managed to take a bunch of cool pictures with it, but the kit lens (Nikkor 18-55 3.5/5.6G) is sometimes not enough. Since I take most of my pictures indoors at conferences, parties, concerts,… I needed a more appropriate lens for this.
So, after my last trip I went to eBay and got this awesome lens:

Some good features:
- It’s really fast focusing
- It’s very sharp (see example)
- It’s small and lightweight, perfect for travelling
Also, the fact that it’s not a zoom forces you to move around subjects and experiment, helping you to improve your creativity.
You can check my 50mm test set on flickr.
Posted in Photography | 5 Comments »
Posted by Jorge Bernal June 05, 2007
I know this is a bit old, but I’ve been trying to catch up with all the new stories after a conference, vacation, broken laptop and loads of work.
RedHat Enterprise Linux 5 (RHEL 5) was launched some months ago. I’ve never been a big fan of RedHat in terms of technology. I guess is quite good now, but RPMs scared me years ago and I’m not over it yet.
One of the things I liked is that RedHat proved that the KISS principle doesn’t only apply to software development, but to marketing and sales too. This is their new SLA (service level agreement). Can’t be simpler.

That reminds me of MySQL and their all-you-can-eat support package (MySQL Enterprise Unlimited), easy to understand and with a catchy slogan:
For the price of a single CPU of Oracle Enterprise Edition ($40,000 per CPU), you can deploy an unlimited number of MySQL Enterprise Servers, with full 24×7 production support
It seems open source businesses are not only innovating on the technical side, but also disrupting the industry.

Posted in Business | 6 Comments »