Locally served YUI3
For the vast majority of sites serving static JS and CSS files such as those required by YUI (or jQuery etc.) from a CDN makes great sense: improved performance through caching and geography, reduced load, improved uptime, leveraging some large corporations’ resources, etc.
Unfortunately as soon as you hit an SSL secured page you can’t use a CDN’s resources securely, a common thing with e-commerce sites and administration panels. In the YUI case that means doing at least a little bit of extra configuration and maintenance of an installed library base, an all-too-common task in typical server-side development that’s becoming more common as libraries are maintained for client-side usage as well.
Toss in “combo loading” and all of a sudden it feels like the software development cycle can’t just be discarded ’cause you are working on the web. Maybe this is really what they meant by Web 2.0. But I digress…
Since I’m familiar with and working on YUI3, here is how we have it working for non-CDN based serving for an administration panel developed for a newer generation of an Interchange site. Our custom application uses YUI3 (core), modules from the YUI3 Gallery, and a few modules …
javascript
Benchmarking in Perl: Map versus For Loop
Last week, I was coding in Perl for an Interchange project. I’ve been in and out of Perl and Ruby a lot lately. While I was working on the project, I came across the following bit of code and wanted to finally sit down and figure out how to use the map function in Perl on this bit of code.
my @options;
for my $obj (@$things) {
push @options, {
value => $obj->{a},
label => $obj->{b}
};
}
return \@options;I’m a big fan of Ruby’s inject method and in general a fan of the Enumerable Module, but I have a brain block when it comes to using the map method in both Perl and Ruby. I spent a little time investigating and working on a small local Perl script to test the implementation of the map method. I came up with the following:
return [ map {
{
value => $_->{a},
label => $_->{b}
}
} @$things ];After that, I wanted to make sure the code change was justified. The Interchange application that is the source of this code is built for performance, so I wanted to ensure this change didn’t hinder performance. It’s been a while since I’ve done benchmarking in Perl, so I also had to refresh my memory regarding using …
performance perl
NOTIFY vs Prepared Transactions in Postgres (the Bucardo solution)
We recently had a client use Bucardo to migrate their app from Postgres 8.2 to Postgres 9.0 with no downtime (which went great). They also were using Bucardo to replicate from the new 9.0 mater to a bunch of 9.0 slaves. This ran into problems the moment the application started, as we started seeing these messages in the logs:
ERROR: cannot PREPARE a transaction that has
executed LISTEN, UNLISTEN or NOTIFYThe problem is that the Postgres LISTEN/NOTIFY system cannot be used with prepared transactions. Bucardo uses a trigger on the source tables that issues a NOTIFY to let the main Bucardo daemon know that something has changed and needs to be replicated. However, their application was issuing a PREPARE TRANSACTION as an occasional part of its work. Thus, they would update the table, which would fire the trigger, which would send the NOTIFY. Then the application would issue the PREPARE TRANSACTION which produced the error given above. Bucardo is setup to deal with this situation; rather than using notify triggers, the Bucardo daemon can be set to look for any changes at a set interval. The steps to change Bucardo’s behavior for a given sync is simply:
$ bucardo_ctl update sync …bucardo database postgres
MySQL Integer Size Attributes
MySQL has those curious size attributes you can apply to integer data types. For example, when creating a table, you might see:
mysql> CREATE TABLE foo (
-> field_ti tinyint(1),
-> field_si smallint(2),
-> field_int int(4),
-> field_bi bigint(5)
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> desc foo;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| field_ti | tinyint(1) | YES | | NULL | |
| field_si | smallint(2) | YES | | NULL | |
| field_int | int(4) | YES | | NULL | |
| field_bi | bigint(5) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)
mysql>I had always assumed those size attributes were limiters, MySQL’s way of providing some sort of constraint on the integers allowed in the field. While doing some recent work for a MySQL client, I attempted to enforce the range of a tinyint according to that assumption. In reality, I only wanted a sign field, and would have liked to have …
database mysql
A Product Variant Code Challenge
A while ago, I came across a cute little Ruby challenge that looked interesting:
Given an array of arrays of possible values, enumerate all combinations that can occur, preserving order. For instance:
Given: [[1,2,3], [4,5,6], [7,8,9]], calculate the same result as the code below, but do so with an arbitrary size array:
combos = []
[1,2,3].each do |v1|
[4,5,6].each do |v2|
[7,8,9].each do |v3|
combos << [v1, v2, v3]
end
end
end
combosEntries can be written using one or more functions, and may optionally be written as a class extension (i.e. Array)….
And now some context to why I thought this was applicable to ecommerce: Let’s imagine you have a product. Then, let’s imagine that the product has variations, or variants. We’ll say we have an arbitrary size array of “option types”, each with an arbitrary number of items in the array. Here, we have option types of size, color, and printed logo, which yields multiple variations, variants or combinations of a single product:
| Size | Color | Logo |
|---|---|---|
Large |
|
|
Medium |
|
|
Small |
![]() |
|
![]() |
And let’s give a real-life example data model, this one from a previous article on Spree’s product …
ecommerce ruby
Three Liquid Galaxy Projects Accepted for Google Summer of Code 2011
Yesterday the student proposals accepted for the Google Summer of Code program were announced. The Liquid Galaxy Project, participating in the program for the first time, accepted three proposals. These projects will dramatically extend the functionality of the Liquid Galaxy system:
New Control Input Devices and Distributed GL Rendering — Paul Hunkin, mentored by Andrew Leahy
Paul is a PhD student and has been running Liquid Galaxy on his university display wall for some time now. This project will initially target Microsoft’s Kinect as an input device for Liquid Galaxy, and may also leverage ClusterGL for distributed GL Rendering of Google Earth and other OpenGL applications.
Network Sync in Irrlicht — Ben Wright, mentored by Ben Goldstein
Google Earth is certainly a “killer app” for the Liquid Galaxy platform, but there are many other applications that could be easily enhanced, coordinating multiple instances rendering portions of a panoramic view. This project will modify the 3D Open-Source graphics engine Irrlicht, enabling many 3D applications using this platform.
Android Phone Accelerometer as Liquid Galaxy Input Device — Reese Butler, mentored by Adam Vollrath
Currently, the …
visionport
Postgres query caching with DBIx::Cache
A few years back, I started working on a module named DBIx::Cache which would add a caching layer at the database driver level. The project that was driving it got put on hold indefinitely, so it’s been on my long-term todo list to release what I did have to the public in the hope that someone else may find it useful. Hence, I’ve just released version 1.0.1 of DBIx::Cache. Consider it the closest thing Postgres has at the moment for query caching. :) The canonical webpage:
http://bucardo.org/wiki/DBIx-CacheYou can also grab it via git, either directly:
git clone git://bucardo.org/dbixcache.git/or through the indispensable github:
https://github.com/bucardo/dbixcacheSo, what does it do exactly? Well, the idea is that certain queries that are either repeated often and/or are very expensive to run should be cached somewhere, such that the database does not have to redo all the same work, just to return the same results over and over to the client application. Currently, the best you can hope for with Postgres is that things are in RAM from being run recently. DBIx::Cache changes this by caching the results somewhere else. The default destination is memcached.
DBIx::Cache acts as …
database performance perl postgres
RHEL 5 SELinux initscripts problem
I ran into a strange problem updating Red Hat Enterprise Linux 5 a few months ago, and just ran into it again and this time better understood what went wrong.
The problem was serious: After a yum upgrade of a RHEL 5 x86_64 server with SELinux enforcing, it never came back after a reboot. Logging into the console I could see that it was stuck in single user mode because there were no init scripts! Investigation showed that indeed the initscripts package was completely missing.
I searched on bugzilla.redhat.com looking for any reported problems and didn’t find any. I reinstalled initscripts, rebooted, and the server was fine, but it was not happytimes to have that unexpected downtime.
Tonight I ran into the problem again, this time on a build server where downtime didn’t matter so I could investigate more leisurely.
The error from yum looked like this (the same problem affected the screen package as affected initscripts):
Downloading Packages:
screen-4.0.3-4.el5.i386.rpm | 559 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
groupadd: unable to open group file
error: …hosting linux redhat security selinux

Large

