Posted by chetan
on February 23, 2010
For some reason, I had a relatively hard time finding this info all in one spot, so here it is:
Using MySQL with JRuby is actually pretty easy (and no annoying arch issues on OS X! :-)
Install GEMs (DBI, JDBC driver, DBI adapter):
$ jgem install dbi jdbc-mysql dbd-jdbc
Then use it!
require 'dbi'
require 'jdbc/mysql'
dbh = DBI.connect('dbi:jdbc:mysql://localhost:3306/test', 'root', '',
{ "driver" => "com.mysql.jdbc.Driver" } )
Posted by chetan
on February 10, 2010
I’ve spent the last few days since joining Better Advertising working on a new feature for a Firefox extension called Ghostery. We’ll be announcing the new feature soon, but until then I thought I’d share some of what I’ve learned so far.
I’ve never worked on an extension before but as it turns out, it’s really quite easy to pick up; some fairly simple XML (aka XUL) for composing the UI and JavaScript for the rest. One of the trickier bits has to do with scope. After doing some testing I figured out that the entry point into an extension is via the browser window; that is, your extension code will be executed each time you open a new window and that means that all your code is basically scoped to a single window.
In developing the new Ghostery feature I needed a way to run some code when the user quits Firefox. Luckily, the extension architecture is extremely flexible (if poorly documented at times) and I didn’t have to jump through any hoops to do it. Almost anything, it seems can be either chained or hooked in some way. In this case, the nsIObserverService gives us access to the necessary shutdown event to which we can attach an observer using a simple interface.
The problem, then, was that since our code is run every time a new window is created, I needed a way to register the hook only once to avoid firing multiple times on exit. My first thought was to try to register the hook outside of the window scope (e.g. using a different chrome overlay) but that appeared to be a dead end. Using a globally scoped variable as a lock was also a dead end. In the end I settled on something I already knew how to use: preferences. Essentially, I created a simple lock around a preference variable which, while I don’t need to store it between sessions, is in fact a global storage area that can be accessed from different windows.
Check out the code below for an example implementation. I left out the actual preferences code since it’s not crucial to understanding the solution.
Posted by chetan
on December 31, 2009

This year was something of an anomaly for me: I only went to five shows. Two of those shows, however, were music festivals and easily made up for the otherwise quiet concert calendar — Lollapalooza with a staggering 35 shows in three days and the Newport Folk Festival with another 6.
I also went to 3 free shows at Madison Square Park: Jonatha Brooke, Raul Malo, and the John Scofield Trio. I’m a huge fan of Raul Malo and the Mavericks so we ended up braving some of the worst rain of the summer to see him. It rained through most of his shortened set, but it was still worth it.
Continue reading…
Posted by chetan
on December 31, 2009
I’ve been procrastinating publishing this latest post for several weeks now. I’ve had ample time to write it; that’s not the problem at all. No, I simply find it painfully, frustratingly difficult to narrow my collection down to only a handful of records, especially in a year with so many fantastic releases to choose from.
Continue reading…
Posted by chetan
on December 16, 2009
tl;dr- Yes, you can add a 2nd GPU; OS X will ignore it; Windows will use it. Make sure to disable the card in the 1st slot to use it for gaming.
Apple makes great hardware, there’s no doubt about it. However, occasionally they make decisions that not only boggle the mind but are completely infuriating. Like putting non-standard ports on a laptop and charging twenty bucks for the proper adapter cable!
A similar problem I ran into recently is the issue of the graphics card in the Mac Pro: only specially branded “Mac-compatible” GPUs will work in OS X. What’s the problem with that you ask? Availability and pricing.
Continue reading…
Posted by chetan
on July 23, 2009
Just fixed another longstanding pet peeve of mine: I finally added classmates.com and cmates.com to my email server’s blacklist. How these guys have managed to stay in business for so long is beyond. They don’t even try to hide the fact that they’re spammers. They even sign all their messages with a valid domain keys signature!
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; d=classmates.com;
s=prod20081009.key.pem; t=1248374724; bh=PH2W8/WWF0Eq5UeHS7xrebJL9l
g=; h=Date:from:to:Subject:Mime-Version:Content-Type:Message-Id;
b=IMICZJvpMfW9pEWFSGX9gnScTOsQb0sI3edRgw7jHekqAK8OuJoFkmGBYcLC8IhpD
mnoepYufrgbzzCEUWiYwpqCNSJ7PkqiyDs5n9upo4qtyEa29vgv6rXb39vQ+FjymKV+
E39Tuzsm2MuXTTO+e0C7LlOozzqnSfh30yovIOI=
Gotta love the sheer audacity of it..
Posted by chetan
on July 23, 2009
After years of being annoyed by the fact that SquirrelMail, an otherwise fine product, doesn’t include the date and name of the sender when replying to emails like just about every other email client on the planet, I finally broke down and fixed it. Below is the simple 1 line patch against SquirrelMail 1.4.19. It will most likely work on older 1.4.x versions as well.
Download patch (squirrelmail-1.4.19-reply_body.patch)
--- squirrelmail-1.4.19/src/compose.php 2009-05-14 06:26:29.000000000 +0000
+++ squirrelmail/src/compose.php 2009-07-23 16:09:59.000000000 +0000
@@ -856,7 +856,7 @@
$rewrap_body = explode("\n", $body);
$from = (is_array($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
sqUnWordWrap($body);
- $body = '';
+ $body = "\n\n\nOn " . getLongDateString( $orig_header->date, $orig_header->date_unparsed ) . " {$send_to} wrote:\n"; // MOD BY chetan
$cnt = count($rewrap_body);
for ($i=0;$i<$cnt;$i++) {
sqWordWrap($rewrap_body[$i], $editor_size, $default_charset);
Posted by chetan
on July 14, 2009
If you’re looking to install Google Gears on OS X, installation order can be somewhat important. The Safari version installs as a standard OS X browser plugin and will be picked up by all the browsers on your system. Sounds good, except that the Firefox version is actually a standard Firefox XPI extension and the two will conflict — you actually won’t be able to install the XPI unless you first disable the plugin via the Tools > Add-ons > Plugins menu option.
Posted by chetan
on June 29, 2009
I recently needed to script some tasks for a Spring-based app at work so we could shove it into a crontab. It proved to be much easier than I thought.
You can use your spring.xml config file for wiring up your beans as usual, but rather than deal with various property files you can easily override properties on the fly using system properties. See the following example:
In your spring.xml make sure you have this line:
1
2
3
4
5
6
7
8
9
| <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- Allow properties to be overriden via
system properties -->
<property name="systemPropertiesMode" value="2" />
<property name="locations">
<list> [...snip...] </list>
</property>
</bean> |
Then you can override your aliases either using standard java properties (-Djdbc.url=”mysql://…”) or via your program’s own command line arguments, which is the route I ended up going.
CommandLineParser parser = new GnuParser();
Options options = new Options();
Option brokerOption = new Option("b", "broker", true, "broker uri");
brokerOption.setRequired(true);
options.addOption(brokerOption);
CommandLine line = parser.parse(options, args);
System.setProperty("jms.broker.url", line.getOptionValue("b"));
Posted by chetan
on May 31, 2009
And furthermore, Peachtree sucks. Last weekend I battled this error thrown by the Peachtree 2008 installer and this weekend I had the great pleasure of upgrading to Peachtree 2010 and being greeted by the very same error.
The fix in both cases? Simply copy the contents of the CD to the local harddisk (a network share works just as well) and then run setup.exe from there. Don’t be fooled by the suggested “solutions” from Microsoft or Installshield like I was.