Why is my code in a loop?
Today, I wrote some code that looked a little bit like this:
class Model < ActiveRecord::Base
...
def update
RAILS_DEFAULT_LOGGER.info "Update Called"
# Read some data from wherever
# Set some properties on my object
save!
end
endImagine my surprise when my log output was a long stream of Update Called lines.
What happened here is that save is implemented as a call to update when the object already exists.
Inadvertently picking a method name that is the same as an important Rails method can be hard to track down. I already had my logging in there, so I wasn’t left wondering why the call never completed.
Start the weekend with a boat rescue!
Lisa and I just had a ‘Joe and Petunia’ moment.
I noticed a small boat in trouble just off shore from the Kirkland marina today. The boat just stopped and they started waving an orange flag – they also started bailing. Lisa called 911.
Before the rescue boat arrived, the boat in trouble drifted into the docks at the North end of Marina Park and the two gentlemen rescued themselves.
Living on the lake provides so much entertainment.
View your Divx videos on your Xbox 360
I just installed TVersity to do on the fly transcoding of Divx videos for my XBox 360. The key is to have the correct versions of all the other software. Here is a post about how to do this
This is way easier to setup than the Media Connect software that Microsoft ships.
My server is a dual core 2.8 GHz monster machine (from 18 months ago!). TVersity uses 100% of both cores to transcode my videos.
The videos I’ve watched so far actually look really good – not Hi Def, but pretty good. Certainly not good enough to be confused with HD
Low memory spam reduction using Greylisting
In my search for reducing memory usage on my OpenVZ VPS, I took a look at my email server configuration. I originally used the configuration instructions from Howto Forge to setup my server. Even with adjusting the configuration, the memory used by all the mail components, especially the protection system – Spamassassin, ClamAV and the pieces necessary to run them – was over 100MB.
However, if I remove this protection, bad stuff will get through!
What about greylisting, I thought.
In summary, a server that performs greylisting denies the first incoming mail request. Any regular SMTP server will retry the request later, and this request will be allowed through. Spammers use custom software that usually doesn’t retry, they just move on to the next email in their list. Regular mail gets through with a delay the first time and spam is effectively blocked.
I uninstalled all the postfix add-ons I’d added-on, and used apt-get install postgrey to add greylisting to Postfix on my server.
Some spam still gets through, but 90% is gone. I use Thunderbird to access my email account here, and this detects the junk mail very well (actually better than my install of Spamassassin did).
Greylisting works better than I thought it would, and the best part is that the server uses less than 12MB of my precious OpenVZ memory allocation
acts_as_taggable is dead, long live has_many_polymorphs
Evan Weaver has just posted about how to replace all the different acts_as_taggable implementations with his has_many_polymorphs plugin.
Since the current owners of the acts_as_taggable gem seem to have abandoned it, and DHH’s identically named acts_as_taggable plugin also seems dead, this is probably the best way forward if your writing new code or planning changes to old code in the near future.
I haven’t checked this out yet, but my tag cloud code should be able to work with has_many_polymorphs with little to no modification.
Karma sucks when you lose your hard disk!
I’ve been giving Ben grief most of the week because his Mac laptop was in the shop (and is now on its 3rd motherboard).
2pm Friday, my laptop hard disk just stops working! Not readable in any way.
Karma!
Some things lost, but the main hassle is installing everything from scratch.
Migrate your Typo blog to Wordpress
There are some scripts available, but I never found a step-by-step set of instructions for how to migrate my Typo 4.0 blog to Wordpress 2.0. This post documents what I did to transfer my blog from one platform to the other.
Install Wordpress
I am now running my Wordpress blog on Dreamhost. I used my own instructions on how to set this up with Capistrano
I took this opportunity to switch themes too!
Add the Ultimate Tag Warrior plugin
To get tag functionality in Wordpress, I added the Ultimate Tag Warrior plugin I still need to add code to show the tags in posts, but the underlying data is there.
Save the Typo database
On my Typo server dumped the MySQL database using mysqldump.
Import the Typo database into Wordpress database
On my Dreamhost account, this is as simple as running mysql -u [user] -p < typo-dump-file
Run the migration script
Stuart Johnson has a Typo to Wordpress migration script that almost worked for me. I had a problem with the post content not showing up. I simplified the SQL for this step, as I didn’t have the pre-generated HTML or the extended pieces. I just copied the existing content field directly over to Wordpress.
This script sets up the permalinks for the posts in the database.
In Admin, save the permalink configuration
To activate the permalink structure, you need to go to the Wordpress options > permalinks and just click Save. This updates the .htaccess file with the redirects.
Approve all the comments
All the comments seem to come into Wordpress needing moderation. In lieu of changing the migration script, I just approved them all and dealt with an email for each going to my mailbox!
Note: It looks like the Typo 2.6 comment text isn’t being imported correctly.
Install Textile wrapper plugin
I use Textile for my Typo posts, so I needed this Wordpress plugin
Install GeSHi wrapper plugin
From the same place as the textile plugin, I installed the GeSHi wrapper to do my code tags. Note that, as of this writing, I still need to go through the DB and change my typo:code tags to the appropriate code tag.
Add the /articles/tags/foo rewrite to .htaccess
I’m trying to setup the rewrite rules to allow the /articles/tags/foo urls to work, but this has been problematic so far!
Update DNS or switch out the directories
Since I switched servers, I updated my DNS to point at the new location and waited until my site was switched.
Update Feedburner
I use Steve Smith’s Feedburner plugin. Feedburner will fail to change its configuration if the new url doesn’t exist, so you have to wait for the DNS changes to propogate before you can update your Feedburner configuration.
Cleanup the database
The Wordpress database is left with a bunch of unused Typo tables that need to be deleted. Dreamhost has phpMyAdmin that helps with this. Anything without a wp_ prefix should be removable.
Update!
Forgot to mention this, but I changed the upload directory for Wordpress from wp-content/uploads to files to match Typo and moved the files over from the Typo server.
Blog moved again!
Following up on my post about memory usage with OpenVZ, I’ve moved my blog from Typo to Wordpress. This saves me about 150MB of memory on my VPS host, which translates directly to $10/month.
With the low level of traffic I receive, 150MB is a little overkill. Rails isn’t the best framework for very low traffic sites.
Resize is in the wild
I just received an email from Fabio Trezzi that he has used my resize code in a site he’s just released.
Go check out http://www.stickyshare.com
OpenVZ redefines RAM
My new hosting location is an OpenVZ VPS at Quantact. This is working out pretty well, except for one thing – Ram usage.
One of the things a VPS provides as part of the package is Ram. The usual definition of Ram is real memory, the sticks of chips you buy to put into a machine. OpenVZ defines Ram as something different. To OpenVZ, Ram is actually virtual memory.
This is a big deal, as a bunch of the things I want to run use very little real memory, but do take up a bunch of virtual memory. Here’s some examples:
MySQL (using a small configuration!):
- Resident memory for my application: 10MB
- Virtual memory applied to my account: 80MB
Monit:
- Resident memory: 2MB
- Virtual memory: 45MB
These two applications put me at 130MB of Ram used before I start writing code. Since I’m writing Rails code, I need all the memory I can get. Two Mongrel processes running Typo can easily be 60MB each, putting us at 250MB for my blog!
There are all sorts of posts around the web about this issue, and the OpenVZ guys try to defend what they are doing, but the big problem is that they are using the wrong terminology for memory, and this will eventually make people grumpy. If you’re measuring virtual memory, tell people that the limits are for virtual memory, not ‘Ram’.
I think they do this to help make VPS hosting costs very competetive with Xen based systems. You only find out later that you actually need to buy twice as much memory as you thought you needed.
How about setting up some swap space, I hear you ask. Well, OpenVZ doesn’t allow swap space in the guest OS space. Swap is managed globally, so you have no control over this. This is an artifact of the virtualization technology used by OpenVZ. Xen does allow swap space, so doesn’t need as much Ram as an equivalent OpenVZ configuration.
The takeaway here is that, if you are looking at an OpenVZ VPS host, you should budget for more Ram than you think you need, as you will probably need it.
Tim of Quantact has put up a wiki page explaining a little about the OpenVZ Ram usage
Note: I believe Virtuozzo is the same basic code as OpenVZ, so the same issue applies.