Mar 19, 2009 1
Decemberists <3 Bon Jovi?
Is it just me or does the guitar riff in the song “Margaret in Captivity” on the Decemberists’ new album “The Hazards of Love” sound almost exactly like the guitar riff from Bon Jovi’s “Wanted Dead or Alive?”
Mar 19, 2009 1
Is it just me or does the guitar riff in the song “Margaret in Captivity” on the Decemberists’ new album “The Hazards of Love” sound almost exactly like the guitar riff from Bon Jovi’s “Wanted Dead or Alive?”
Mar 2, 2009 0
I recently found the need to provide UUIDs for ActiveRecord models in a service that I’m developing. I wasn’t able to find a suitable soution, so, I rolled my own. Enter acts_as_universally_unique. The plugin simply adds a (customizabe) UUID field to all ActiveRecord models that act_as_universally_unique. I will be adding additional methods (and test cases) to it shortly.
Feb 26, 2009 1
According to the XML-RPC specification a XML_RPC request may only contain scalar <value>s or non-scalar <struct>s. The specification unfortunately does not provide any standard for encoding the type of data encoded in the <struct>s. This has the side effect of not being able to support polymorphism in service method parameters as it leaves the sever no choice but to rely on the method signature in the API declaration when trying to determine what to instantiate for a given <struct> in the XML-RPC request.
Let’s say you have the following declarations:
class SubscriptionsApi < ActionWebService::API::Base
api_method(
:create_subscription,
:expects => [
{ :customer => Logical::Customer },
{ :payment_method => Logical::PaymentMethod }
]
)
end
module Logical
class PaymentMethod < ActionWebService::Struct
end
class CreditCard < PaymentMethod
member :card_number, :string
# ...
end
class PayPal < PaymentMethod
member :login, :string
# ...
end
end
Now you want to make a call to the service method and pass either a CreditCard or a PayPal. XML-RPC will encode the request like so:
<methodCall> <methodName>create_subscription</methodName> <param> <struct> <member> <name>card_number</name> <value>4111-1111-1111-1111</value> </member> </struct> </param> </methodCall>
This provides no type information to the server so the server will attempt to instantiate a Logical::PaymentMethod which will of course not have a card_number member as it’s specific to the CreditCard subclass. SOAP, on the other hand, does encode the parameter types allowing you to utilize this type of polymorphism in your service parameters. Here’s the same request encoded in SOAP.
<?xml version="1.0" encoding="utf-8" ?> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <env:Body> <n1:CreateSubscription xmlns:n1="urn:ActionWebService" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <payment_method xmlns:n2="http://www.ruby-lang.org/xmlns/ruby/type/custom" xsi:type="n2:Logical..CreditCard"> <card_number xsi:type="xsd:string">1</card_number> </payment_method> </n1:CreateSubscription> </env:Body> </env:Envelope>
The current implementation of ActionWebService resurrected by datanoise did not support this type of polymorphism in SOAP requests. However, I submitted a patch recently which provides for this functionality. Hopefully it’s accepted.
Feb 11, 2009 0
I recently came across an annoying bug in MySQL v5.1 (also in 6.0 apparently) that bit me hard, so, I thought I’d post on it in case you are being bitten by the same bug.
If you attempt to update a column that does not allow NULL to NULL, MySQL will set the column’s value to the default value for that column’s data type. This is true only when you are not running MySQL strict mode. Here’s an example to illustrate.
mysql> create table null_test (id int not null unique(id), name varchar(25) null default null); Query OK, 0 rows affected (0.01 sec) mysql> show create table null_test; +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | null_test | CREATE TABLE `null_test` ( `id` int(11) NOT NULL, `name` varchar(25) default NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> insert into null_test (id, name) values (1, 'Jane'); Query OK, 1 row affected (0.00 sec) mysql> update null_test set id = null; Query OK, 0 rows affected (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> select * from null_test where name = 'Jane'; +----+------+ | id | name | +----+------+ | 0 | Jane | +----+------+ 1 row in set (0.00 sec)
More information about this bug can be found in the bug report submitted Janurary 4, 2008.
Feb 5, 2009 0
Unfortunately, MySQL does not support check constraints out of the box. This makes the task of enforcing business logic in the database layer difficult, but not impossible. I recently found this approach to implementing check constraints in MySQL. It’s not as pretty and clean as I’d like, but, it’s the best approach that I’ve found so far.
Now. why would you want to encode business logic in the database? Can’t you make due with your ActiveRecord::Validations?
Well, have you ever updated the database directly? Have you ever called update_attribute on an object? How about save_with_validation(false)? Yeah, I thought so. Read more about why you should treat your database as a fortress in Dan Chak’s recently released book, Enterprise Rails (review coming soon).
Feb 2, 2009 0
Your RDBMS will usually rewrite your sub-selects behind the scenes as joins. However, there are times where you’ll want to do this yourself. For example, past versions of MySQL did not play well with sub-selects. Here are a couple examples of how to rewrite sub-selects as joins.
select * from table_a where id not in (select a_id from table_b); -- can be rewritten as... select * from table_a left outer join table_b on table_a.id = table_b.a_id where table_b.a_id is null; select * from table_a where id in (select a_id from table_b); -- can be rewritten as... select * from table_a left outer join table_b on table_a.id = table_b.a_id where table_b.a_id is not null;
Jan 29, 2009 0
Awesome hi-resolution image of the inside of the space shuttle’s cockpit. As my desktop background on my 23″Apple Cinema Display I feel like I’m behind the wheel of the Millennium Falcon. NASA rocks!
Jan 23, 2009 0

These are sooooo cool! My wonderful girlfriend got me one of these for Christmas this year. They are called Mikro Men and according to their website, “are a brand of miniature fold out metal sculptures created by Sam Buxton.” And I love them!
Mikro Men come in a sleek looking, black, fold-out cardboard package kept closed with a magnet. The Mikro man is shipped flat and is stamped out of a single thin piece of stainless steel. You use your fingers to bend the metal at the “fold lines” or a pair of tweezers for the smaller pieces like the trash can in the Office Man above (this is the one I have). After a few fun minutes you have a totally awesome piece of art for your desk. My Mikro Man lives on my desk on the base of my Apple Cinema display.
Jan 22, 2009 0



I received my pair of DOTS gloves just the other day. The gloves are special because they enable you to operate touch screen devices, such as the iPhone, without removing your gloves. They accomplish this by attaching button-like, metal “dots” to the index and thumb finger on each glove as you can kind of see in the picture. DOTS come in two models: wool ($20) and knit ($15) in sizes medium and large. I opted for the wool model in size “medium” (more like a small in reality). So far I’m not 100% sold on them.
Over the past few days I’ve worn them while walking around frigid, windy downtown Albany, under my mittens while snowboarding, and in my car. I’ve found that gloves, while made from wool, are not very warm. You will especially suffer on windy days as the wind seems to pass right through them. I’ve also found the “dots” in the fingers to be kind of annoying when trying to operate anything besides the iPhone such as the buttons on the dash or steering wheel in my car.
The other downside to these gloves is that they are slippery, really, really slippery. Anything with a smooth surface, like that pricey touch screen device you bought these for, will slide right out of your hands with surprising ease. The same goes for car key fobs, credit cards, thermoses, you name it; if it’s smooth you are going to drop it. If you have a case for your iPhone you’ll probably be fine but if you opt to go all-naturale as I do you better hold on tight! I think the DOTS guys could fix this problem by adding some grippy rubber strips to the palms and fingers. Perhaps we’ll see this in DOTS 2.0.
On the plus side they work as advertised. However, it can take a little getting used to and accuracy can be a problem as the “dot” sometimes becomes a moving target as your glove shifts around your fingers. Once you find that sweet spot, though, you’ll be whizzing around your device with great precision. Surprisingly, I found that the gloves especially excel with typing. I found myself wishing I had retractable dots on my fingers as I often times fat finger the keys while typing on the iPhone. The dot gives you a great precise “tip” (they are actually rounded) to tap with almost like a stylus, that is, when you can line the glove up right with your finger.
Overall, I’m not impressed. The wool is also starting to unravel a bit and it’s only been a few days. :-/ The NorthFace makes a similar glove, though, I think I like their approach better. They opted to sew silver into the finger tips of the gloves to allow for conductivity. The NorthFace model also has a rubbery grip on the palm and fingers. I think I might try them out. The two downsides are the price 2x what I paid for the DOTS and the graphics they added to brand the gloves as “hi-tech.” Lame, IMHO.