Tuesday, April 3, 2012

How to replace WEBrick with Thin for Windows development

WEBrick still seems awful slow on Windows. Last time I played with Rails, Mongrel was the goto replacement for WEBrick. Alas, Mongrel's no longer supported. So then I learned Thin is the new Mongrel. Here's how to get it working on Windows:

First, you might have to do this to install thin on Windows:
gem install eventmachine --pre
gem install thin


thanks to frogz
Then add the line gem 'thin' to your Gemfile to make Thin the default server when you run rails s, et voila:
=> Booting Thin 
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

Monday, April 2, 2012

Rails: How to kill WEBrick 1.3.1 on Windows 7

This worked for me, using RailsInstaller on Windows 7 - launch the WEBrick process into a separate command window by using the start command:

C:\Sites\myapp>start "rails" rails s


This will open a new command window entitled "rails - rails s", running the WEBrick process, leaving the original command window available for use. 

When you're ready to kill WEBrick, just close the "rails" command window. Brutal, but effective. 

Is Node.js the next Big Next Thing?

Andrew Chen explains that Node.js might be poised to be the next Big Next Thing for web apps. He asserts that "Rails, PHP and Visual Basic were all successful because they made it easy to build form-based applications," and if the Node.js community can make something as easy as How to build a blog engine in 15 min with Rails, then it may pick up real traction.

Or it may become just a footnote in web history - anyone remember ColdFusion?


1949 torus for fusion experiments, Clarendon Laboratory, Oxford courtesy Robin Stevens

Wednesday, March 28, 2012

Rats in the attic

Sometimes you have to deal with the rats in the attic.

A coworker dropped by to brainstorm a perplexing problem he noticed in the report he was working on. The report is a PDF document generated from XML using XSLT and Apache FOP. An index table appears on the last page of the report, listing the name and page number of each section in the report. All of the sections were listed with the correct page number, except the section output on page 2 of the report, which the index showed as starting on page 1.

After tracing through the legacy XSLT code for a couple of minutes, we realized that the section start was flagged in the XSL-FO code in an "invisible" table that happened to come out at the very bottom of page 1, forcing the "visible" table over to page 2. Thus the table of contents correctly but deceptively showed the section starting on page 1. The code base that generates this report is several years old, and it has gone through multiple hands, as such code often does, so we had no idea why the original designers chose to output the section start flag in this way.

We came up with a couple of possible fixes he could to try, like eliminating the "invisible" table and moving the flag into the visible table, or if the invisible table was really necessary, apply a "keep with next" attribute so it would always stick to its corresponding section.

My coworker then said the problem reminded him of a scene from Bad Boys 2 (caution, link is not PG or SFW!), wherein Cuban drug lord Johnny Tapia, crawling through the attic where he stashed a mountain of stolen cash, discovers a nest of huge rats gnawing through the piles of loot. After blasting the rats with a cannon-sized revolver, Tapia exclaims to his henchman, "Carlos, this is a stupid f****ing problem to have, but, it is a problem, nonetheless!"

Wednesday, February 15, 2012

A Fundamental Law of the Universe

...the primary rule of IT support: whoever touched it last owns it.
Remy Porter for WTF!

Wednesday, January 11, 2012

How to write regexs matches that span multiple lines in Visual Studio search

Visual Studio has its own weird syntax for searching with regular expressions. Here's how to make a match across multiple lines. Given the sample XSL blocks below
<xsl:apply-templates select="Alph" mode="frobit"/>
<xsl:apply-templates select="Bob" mode="zap"/>
<xsl:apply-templates select="Cam"/>
I want to match the two statements with the mode="frobit", even though the first one has a carriage return in the middle. In VS, you'd use this regex statement to match just the first and last lines, skipping Bob with mode="zap":

select.*\n@.*mode="frobit"

The first bit, select.*\n, is standard Perlish for "match from the word select to the end of line character, \n."

The at sign @ is VS's way of asking "please can you find zero or more carriage returns, but only as few as needed." The alternative is the "greedy" match, using an asterisk *, which says "find as many lines as you can ending in carriage returns before you hit mode="frobit", so the match in this case would make one giant match, including all of the text from select="Alph" all the way to the last "frobit" on Cam, capturing poor Bob in the middle along the way.

Friday, January 6, 2012

How to clean up Windows Media Player

If you've relocated or removed a media directory but its contents are still showing up in WMP's libraries list, try deleting the contents of C:\Users\[username]\AppData\Local\Microsoft\Media Player. That should clear out phantoms!