Long-term Benefits from RailsAdmin
Sometimes setting up an admin tool with user authorization at the onset of a new Rails project can take a bit of work, and it’s not until later that long-term benefits of this framework can be realized. This came up recently when I was asked to write an export method to allow website admins to export customer and order data (for a specific date range) on a platform that was already using RailsAdmin in combination with CanCan for user authorization.
A normal Rails development process for this (from scratch) might look like this:
- Create controller.
- Create route to map to controller.
- Create method in controller to render initial view and send data.
- Create view which allows user to select date range.
- Add user authorization to allow specific users to access functionality.
This isn’t that much work, but here’s how the same functionality was built using RailsAdmin:
RailsAdmin Action
First, I create Rails Admin action, which inherits from RailsAdmin::Config::Actions. Inheriting from RailsAdmin::Config::Actions includes many class methods such as defining the actions http_methods (get, post, etc.), defining if the action is applicable to a single instance or a set of instances (which …
rails
Perl PostgreSQL driver DBD::Pg 3.0.0 released
I am happy to announce that version 3.0.0 of DBD::Pg, the Perl interface to Postgres, was released on February 3, 2014. This represents a major release, mostly due to the way it now handles UTF-8. I will try to blog soon with more details about that and some other major changes in this version.
The new version is available from CPAN. Please make sure that this is the latest version, as new versions may have come out since this post was written.
Checksums for 3.0.0:
58c2613bcb241279aca4c111ba16db48 DBD-Pg-3.0.0.tar.gz
03ded628d453718cbceaea906da3412df5a7137a DBD-Pg-3.0.0.tar.gz
The complete list of changes is below. Thank you to everyone who sent in patches, helped debug, wrote bug reports, and helped me get this version out the door!
Version 3.0.0 Released February 3, 2014 (git commit 9725314f27a8d65fc05bdeda3da8ce9c251f79bd)
- Major change in UTF-8 handling. If client_encoding is set to UTF-8,
always mark returned Perl strings as utf8. See the pg_enable_utf8 docs
for more information.
[Greg Sabino Mullane, David E. Wheeler, David Christensen]
- Bump DBI requirement to 1.614
- Bump Perl requirement to 5.8.1
- …
dbdpg perl postgres
Rails ActiveRecord with Database Column Defaults
I had an interaction with a coworker recently that made me take stock of what occasions and situations I use database column defaults. I realized that far and away my primary use is for booleans. I commonly set a default on my boolean columns when I’m defining a new migration. I do this primarily to minimize the potential for three states—true, false, and null—when I usually want a boolean to be limited to either true or false.
Alongside the distillation down to the classically defined values, another perk of defaults in general is that Rails uses the table’s definition within the database to pre-fill attributes that are not included in the initialization params for an object. For example, a table with columns defined as follows:
create_table :my_objects do |t|
t.string :column_one, default: 'foo'
t.string :column_two
end
Will result in:
$> m = MyObject.new
=> #<MyObject id: nil, column_one: "foo", column_two: nil>
Note that column_two has no default and so is initialized to nil. But column_one is set to “foo” because no other value was supplied. This behavior can be quite handy for boolean attributes such as :published or :unread. …
database rails
The more the merrier? Not always...
Recently we were working on an image manipulation function for a customer that used ImageMagick’s convert command. We had spent tons of time working on the program and the associated system that was going to use it. Everything was working fine. The whole system was nice and snappy. Great job everyone!
Until we moved it into production where the page load times were 8 to 10 times slower than in our camps development system …
We all sprang into action to try to figure out why the page load times were so slow now. We reviewed system settings, configuration files for the database and application, and anything else we could think of. We made sure the OS packages, ImageMagick version, and various other things were the same, and everything looked right. The production hardware has twice the RAM and 4 times the number of processors as development does. So what the heck is going on?
To distract ourselves and hope for more insight, we tried to optimize the code a bit and while making it a bit better we were still 6 to 8 times slower than in development. We deactivated the section of the site overnight so we could sleep on it. Luckily this was a new product line so it wasn’t tragic to …
camps imagemagick performance
HTML Doctypes Make A Difference
If you are like me you may not have given much thought to an HTML doctype other than “yes, it needs to be there” and “there are a few different types, but I don’t really understand the differences between them”. Well if you are like me then you also recently discovered why doctypes matter and how they actually affect your web page.
For those that are not familiar with an HTML doctype, they are the very first line of an HTML document and look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">
As I mentioned before, there are a few different document types. The reason for this is because each one corresponds to a different rule set of HTML syntax for the web browser to follow, like: HTML 4.0, HTML 4.01, XHTML 1.0, or XHTML 1.1.
“The HTML syntax requires a doctype to be specified to ensure that the browser renders the page in standards mode. The doctype has no other purpose.” [1]
When you specify an official doctype, your web browser should follow the standard behavior for rendering that specific rule set for the given HTML syntax. Thus you should get expected results when it renders your web page. There …
browsers html
phpMemcachedAdmin: Graphical/Web Administration for memcached
Memcached is an awesome tool, though it doesn’t offer the best interactive administration experience out there, with its command manually run via a telnet/nc connection.
Well luckily enough there’s an alternative to all that pain and its name is phpMemcachedAdmin
While the development stopped in the end of 2012 (if we don’t consider minor forks) the features offered are quite interesting.
Quoting directly from the main site:
[…]
This program allows to see in real-time (top-like) or from the start of the server, stats for get, set, delete, increment, decrement, evictions, reclaimed, cas command, as well as server stats (network, items, server version) with googlecharts and server internal configuration
You can go further to see each server slabs, occupation, memory wasted and items (key & value).
Another part can execute commands to any memcached server : get, set, delete, flush_all, as well as execute any commands (like stats) with telnet
[…]
Which is incredible news, even more considering the complete lack of similar features from the native Memcached code.
Since all the code basically revolves around a PHP file, the setup phase is just a matter of creating a new …
apache linux php sysadmin
WebP images experiment on End Point website
WebP is an image format for RGB images on the web that supports both lossless (like PNG) and lossy (like JPEG) compression. It was released by Google in September 2010 with open source reference software available under the BSD license, accompanied by a royalty-free public patent license, making it clear that they want it to be widely adopted by any and all without any encumbrances.
Its main attraction is smaller file size at similar quality level. It also supports an alpha channel (transparency) and animation for both lossless and lossy images. Thus it is the first image format that offers the transparency of PNG in lossy images at much smaller file size, and animation only available in the archaic limited-color GIF format.
Comparing quality & size
While considering WebP for an experiment on our own website, we were very impressed by its file size to quality ratio. In our tests it was even better than generally claimed. Here are a few side-by-side examples from our site. You’ll only see the WebP version if your browser supports it:
![]() 13,420 bytes JPEG |
![]() 2776 bytes WebP |
![]() 14,734 bytes JPEG |
![]() 3386 bytes WebP |
The original PNG images were converted by ImageMagick to JPEG, and by …
browsers graphics nginx compression optimization
Mobile Emulation in Chrome DevTools
I have been doing some mobile development lately and wanted to share the new Mobile Emulation feature in Chrome Canary with y’all. Chrome Canary is a development build of Chrome which gets updated daily and gives you the chance to use the latest and greatest features in Chrome. I’ve been using it as my primary browser for the past year or so and it’s been fairly stable. What’s great is that you can run Chrome Canary side-by-side with the stable release version of Chrome. For the odd time I do have issues with stability etc., I can just use the latest stable Chrome and be on my way. If you need more convincing, Paul Irish’s Chrome Canary for Developers post might be helpful.
I should mention that Chrome Canary is only available for OS X and Windows at this point. I tested Dev channel Chromium on Ubuntu 13.10 this afternoon and the new mobile emulation stuff is not ready there yet. It should not be long though.
Mobile Emulation in Chrome Dev Tools

Once enabled, the Emulation panel shows up in the Dev Tools console drawer. It gives you the option of emulating a variety devices (many are listed in the drop-down) and you also have the ability to fine tuning the settings à la carte. If …
browsers design environment html javascript tips tools