Archive for the ‘Tech Stuff’ Category

How to Test ActionMailer in Ruby on Rails

Tuesday, March 14th, 2006

Updated: Johan pointed me in the right direction when it comes to testing ActionMailer in rails.

The previous way I was attempting to test ActionMailer was to actually verify word for word that the emails matched a previously-extracted notification. It’s better just to check that the email contains a few choice words/etc. (see below)

def setup
    @user = users(:myfixtureuser)
    ActionMailer::Base.deliveries = []
  end

  def test_welcome_mail
    MyMailer.deliver_welcome_email
    assert !ActionMailer::Base.deliveries.empty?

    sent = ActionMailer::Base.deliveries.first
    assert_equal [@user.email], sent.to
    assert_equal "expected subject", sent.subject
    assert sent.body =~ /^Welcome to my App/
    assert sent.body =~ /^Username: #{@user.login}$/
    assert sent.body =~ /^Password: [a-z0-9]{10}$/i
  end

Some helpful links on testing Ruby on Rails’ ActionMailer module:
[1] Testing ActionMailer and ActionController Interaction in Rails (integration tests in 1.1 will help out with this, too)
[2] How To Test ActionMailers And Controllers on the Rails wiki

Do you like taking tests?  Have you ever taken an online career test?  No matter what you are interested in, online career testing will give you an insight as to what field you might excel in!  The internet is full of tests; from online math tests to IQ tests, you will be certain to find a test that suits your interest.  Want to find love?  Take an online love test!

Rails State Machines

Saturday, March 11th, 2006

We’re doing some interesting things with state machines and the excellent acts_as_state_machine plugin (created by Scott Barron).

We’re using state machines in Mailroom over at Sprout. It’s really handy for keeping track of things like conversation states, such as: new | closed | junk | etc.

More state machine links: an example and a more concrete example.

Ruby on Rails’ Rake Task Not Re-creating PostgreSQL Test Database

Saturday, March 11th, 2006

This problem was driving me crazy, and it took a little googling to finally hunt down the answer. I hope this helps someone else out there too!

Note: I’m running Edge Rails revision 3476 and PostgreSQL 8.1.0.

Symptoms

Running ‘rake’, ‘rake test_units’, ‘rake test_functional’ gives you about an infinity number of errors. Every test has an error. You investigate a little further, and it turns out your <whatever>_test database has been dropped, but not re-created.

First of all, they must’ve started adding the drop & re-create in at some point in Edge Rails because it did not used to do this.

It’s a handy feature, as long as it works!

Well, in this case, it wasn’t. Luckily I stumbled upon this thread on the Rails mailing list.

A Simple Fix to the Rescue

You can read all the gory details on his fix here: Ruby on Rails and Postgres Schemas

Fortunately, all you really have to do is this part:

Googling around, it seems that one should use “template0″ instead of “template1″ when using createdb to create a new database in Postgres. In typical “So I’ll remove the cause. But not the symptom” fashion, I found “vendor/rails/railities/lib/task/databases.rake” and changed line 109 to read:

`createdb #{enc_option} -U “#{abcs["test"]["username"]}” -T template0 #{abcs["test"]["database"]}`

Just adding that “-T template0″ did the trick. Apparently you’re not always supposed to use the magical template0 in Postgres, but… there doesn’t seem to be any harm in this case.

The Best Thing About Web Apps

Thursday, March 9th, 2006

Charles Jolley has a great post over on The Big Act (SproutIt.com’s weblog).

He talks about the shrink-wrap software development lifecycle. It’s not uncommon, as he describes, to only release a new update every quarter.

Can you imagine … a bug in GMail or some really popular web app … and Waiting. Three. Months.

Now, Charles on web apps, such as Mailroom:

The other night I happened to be working when someone reported a bug they found Mailroom. I immediately knew how to solve the issue, so I fixed the problem and emailed the person back within maybe 10 minutes of their report.

Three months to deliver a fix down to 10 minutes. That’s service! Think about that the next time you find some nasty bug in the software you use for your business and you have to wait for the next release to have it fixed.

This is one of the things Joel is really going to have to grok soon, if not already, following the release of Fog Creek Copilot.

Of course, Paul Graham understood this way back in the day, when he created one of the world’s first web apps. (the first, he claims. :))

What is a *REAL* Programming Language?

I got into a bit of a pissing match back at my old company, because one of my fellow developers decided that scripting languages (you know, powering many if not most of the new innovative web apps coming out these days), are not real programming languages.

Only compiled languages like C++, Java, and … wait for it …. C# are real programming languages.

Do we all remember COBOL? Mainframes?

What do we think hardcore, diehard C++ programmers will be like in 8-10 years? Hmmmm….

Hoarding Knowledge in the Era of Blogs, Wikis, Open Source and Distributed Web Collaboration

Monday, January 9th, 2006

Backstory: As part of a recent system administration task I needed help with, one of my requirements was that the individual document how they performed the task. Nothing simple, just a few key steps or especially complicated compilation strings, whatever.

Enough for someone moderately skilled in *nix administration to repeat the task w/o reinvinting the wheel.

I do this all the time on my own system, say, when I’m compiling php or apache. Or even simple one-liners like Subversion checkout/import/etc. commands.

First I’ll type the commands into a notes.txt file, run them, fix any errors, and keep the notes.txt up to date with how I performed the task so its there as an easy reference in the future. It adds maybe 15-20% of time to the process but saves an incredible amount of time in the long run.

For tasks that other people I’m working with might have to use… I’ll post them to a wiki like Backpack. (Here’s an example that I wrote for a buddy new to Rails: Rails Newbie Getting Started Guide)

So, I was a bit taken aback when I got this response back from a system administrator:

I have done the easyapache thing and had compiled so. But if you are asking for a step by step description of how to go about compiling, then I guess no sys-admin will be willing to give you the details.

This frankly boggles my mind.

I know there are people in Office Space environments who hoard their knowledge and try to build up their fiefdoms.

But for those of us lucky to work (or also work) in Web 2.0 environments … this kind of attitude is unacceptable.

Welcome, knowledge hoarders, to the era of blogs, wikis, open source and distributed web collaboration –
     Your value to my organization is inversely proportional to the amount of knowledge you hoard, not the other way around. Goodbye.

Tagging, Bagging and Renaming Your Mp3 Collection with Jaikoz

Saturday, January 7th, 2006

Had some free time tonight (or is 3am technically ‘morning’) to organize my mp3 collection.

There’s the joke that women say they have to stay home and wash their hair, when they don’t want to go out with a guy.

Well, I stay home and tag my mp3 collection! No, really.

For organizing your legacy (non-tagged, crappily named) mp3s, I highly recommend Jaikoz for OS X. It’s written in Java though so it also has XP and Linux versions. (haven’t tried those yet)

I’ve been using the tagging functionality (via acoustical fingerprinting and musicbrainz.org), then using its rename-based-on-tags functionality to make them all “Artist - Song Title” or whatever.

Since it is written in Java, it can be kinda slow at times. But it’s definitely worth a look, even ~ $18 for a registered copy in my case!

In unrelated news… I’m also now up 2 Gigs in mp3s in the last two gigs after ripping my extensive audiobook collection. w00t!

Linux Media Server Redux

Wednesday, January 4th, 2006

A few updates to my How to Setup and Configure a Linux Media Server post.

Mental note: don’t start posting random how-tos at 4am and then go over to digg and submit them, before you’ve even finished testing out your setup!

There was one huge flaw with the default Fedora Core 4 setup — Samba shares don’t work properly with OS X. A pretty huge problem for a ‘media server’ to have if you are rockin’ the mac anywhere in your household.

Uh oh, Browsing the Samba Share Doesn’t Work on My OS X Box!

I thought it was too good to be true!

The Samba version installed with Fedora Core 4 is not the very latest.

You’ll need to download and install the latest version of Samba if you need to access your linux media server from OS X. (unless you’re lucky and you can mount your share from OSX without a problem - maybe Apple’s fixed this bug in the latest build)

But if it isn’t working for ya, there are also configuration settings you’ll need to setup on OSX, and even possibly a simple AppleScript startup launcher which will perform the mount of the network share upon startup each time. (this should work in OS X but is broken on some systems, including mine)

If you’re having OS X samba connection woes, I’ll just have to point you to this thread at macworld.com. It contains most of the information needed to configure your new Linux Samba installation (this was the trickiest part), as well as a few minor settings you need to configure in your OS X “/etc/smb.conf” file.

Next, you may have problems getting your network share to auto-mount under OS X at startup time. Never fear, here’s a recipe for ya:

Auto-Mounting Your Network Share Under OS X on Startup

There isn’t really the concept of a “Mapped Network Drive” under OS X like there is in Windows (there’s mounted volumes, instead). However, you can do basically the same thing but it can be a bit tricky to do so w/o using some AppleScript-fu.

Open Script Editor and make a script like:

tell application "Finder"
	open location "smb://username:password@ipaddress/the/path"
end tell

For example, mine was:

tell application "Finder"
	open location "smb://sbraford@192.168.1.97/media"
end tell

From user Virtual1 on the thread:

Select to save as “Application”, and make sure “startup screen” and “stay running” are NOT checked.

Save the application script somewhere. Next open up your OS X User profiles / settings / configurations.

Click over to Startup Items, then drag your new auto-mounter AppleScript file onto it & make sure it’s enabled and that your settings get saved (may have to click on the Lock icon).

Next, logout and log back on to see if your new network share gets auto-mounted on startup! If so, w00t, you’re in business.

An update for those who prefer not to use FAT32 partitions on your *nix drives: You may want to format using Ext2, if FAT32 is not to your liking. The Ext2 filesystem is accessible under windows by adding some basic drivers. Thanks Pete and Blue Rowlf for the constructive feedback/comments!

And, last but not least… my version of ‘Media Server’ I guess differs greatly from other’s. Doh!

For me, the biggest thing a Media Server has to do is sit there and serve files. But for other people, it has to be a full-fledged PVR. So, here are my thoughts on adding additional functionality to your network file/media Linux server:

Regularly Scheduled Media Downloads

You have two options here. If you have cable/satellite television, you can use Myth TV as a PVR.

OR, if you only have one big fat Internet connection like yours truly, Broadcatching via RSS + BitTorrent is your answer.

Update: After playing with Azureus and its various RSS plugins for a while on Gnome/Linux, I was still unable to get it to even download torrents properly.

This could be a Linux/Firewall/Router issue, who knows. But debugging it was getting way beyond what I was trying to achieve for the common user (including myself).

Instead, the simplest approach was to mount the Linux Media Server share as a mapped network drive, and configure a Win32 BitTorrent client to do the downloading and just use the server as a file store. (not ideal, but does the job in a pinch.) uTorrent is an excellent C++ based BitTorrent client that has added RSS feed import support in its latest version.

One thing that might be cool as well in the future is setting up a web-based, ajax-powered streaming mp3 server like mp3act.

Hope these updates might appease some of the Digg playa haters out there. Though, despite the “no digg! all he did was mount a blah blah configure a blah blah shell script I can do that in my sleep” posts on digg, the article has been bookmarked 57 times on del.icio.us (at the time of this writing) at least, so hopefully lots of people found it useful!

Please let me know if you have any more tips / updates on setting up a Linux Media Server.

WhoLinksToMe.com Now Running on a New Dedicated Server

Tuesday, January 3rd, 2006

Update: There was a bug with Yahoo Results (the pear class ‘Services_Yahoo’ seemed to have not been loaded). Please let me know if you find any more bugs!

I’d like to thank Tom from Admin-ahead.com for helping out with some php5 migration fun on WHM/cPanel for the new WhoLinksToMe.com server.

I thought we would have to also use Apache2, but it turns out this is one thing cPanel servers do not get along well with at the moment.

However, Apache 1.x is a much better choice for us now anyway I do believe, as it mitigates any other problems that would have sprung up due to PHP5 and Apache 2.

Server History

For the past year and a half, WhoLinksToMe.com has been hosted on a server running over a DSL connection at my dad’s house in St. Louis.

I was able to remotely administer it via SSH, etc. Even VNC’ing into the local network there if ever a problem should arise.

Popdex was also scaled this way, growing to eventually 8,000+ daily pageviews / visitors before being migrated to a professional dedicated server.

Eventually I’d like to write a short guide on how you can start a small web-based business easily these days for $100 per month. Even less, if you’re so inclined.

Traffic Trajectory

Yearly traffic report for WhoLinksToMe.com (2005):

Traffic for the site averages about 1,400 daily unique visitors with over 3,000 daily pageviews.

It’s also been linked to:
- More than 81,000 times according to Google
- 267,853 times according to Yahoo
- 793, 676 times according to MSN Search

Many sites put the link in their template so the link is counted multiple times per site, but still… not bad for a couple of long weekends worth of work back in October ‘04.

How-to Setup and Configure a Linux Media Server

Tuesday, January 3rd, 2006

If you are a total Linux power user, this article is not for you. It is for total Linux newbs who’d like to setup a spare box to serve mp3s, videos, etc.

I don’t subscribe to cable TV so that’s why there’s no PVR/MythTV details.

TODO: add how-tos for broadcatching via RSS + BitTorrent to download your favorite shows auto-magically.

Now, back to the regularly scheduled broadcasting…

This is a guide explaining what was involved in setting up a Linux box to be used as a shared network media server, although I also include my experiences in trying to setup Windows XP. (I didn’t get very far on the XP front)

The Box

So, the girlfriend hooked me up recently with an old Dell P4 2.0Ghz box that she got from work. (I’m gonna help her out w/ a laptop for her new pad up in N. Scottsdale)

The Tools

Tools:
- an old PC you have lying around somewhere
- one or two large hard-drives (newegg.com rocks for this)
- Fedora Core 4 installation disks (torrents available here)

The Operating Systems

1) Windows XP Professional SP2

2) Red Hat Fedora Core 4 Linux

My XP Experience

I figured everything would be peachy with the XP install. Hardly. It didn’t detect a video card or monitor. The display looked like crap. 8 colors, maybe 16. Very pixelated and ugly. From my experience w/ Red Hat, I knew this wouldn’t be a problem on the other side of the fence.

Then, lo and behold, I go to configure networking under the XP install. Looky looky, no network card identified! It’s an onboard Dell ethernet card! How can you not find the drivers for that?! There are probably millions of these babies out in the wild and the boys from MS can’t figure out how to detect it!

My Red Hat Linux Experience

Within a minute or two, Red Hat’s anaconda installer program had already identified my onboard video card *and* monitor!

It booted up a nice GUI that looked awesome. I knew good things were to come. :)

Next, it easily detected my network card. The only problem I ran into (user error) was not manually configuring the partitions.

I would *highly* recommend this. For some reason, the auto-partitioning feature didn’t work quite right since the previous dell OS install had left some nasties in the partition table.

Here’s all you need to know
/boot - 100mb
a swap partition - 2x your RAM
/ - the rest

Easy!

Two programs came in handy on the linux box for configuring new media server drives. I had installed a new 250 GB hard drive that I wanted to configure as FAT32. This would make it easier to transfer to a new media server, regardless of OS. (FAT32 is supported by win98, XP, linux, most of the *nixes I believe)

Update: You may want to format using Ext2, if FAT32 is not to your liking. The Ext2 filesystem is accessible under windows by adding some basic drivers. Thanks Pete and Blue Rowlf for the constructive feedback/comments!

Configuring a New FAT32 Drive Under Linux

The mkdosfs command came in handy. But first, be sure to format the new drive using Fdisk or a similar utility.

Steps to configure a brand-spankin’ new drive as FAT32 under Fedora Core 4 (and probably most linuxes):

1. Partition the drive using Fdsik. I recommend creating one big monster partition for the whole drive.

2. Format the new drive as FAT32 using mkdosfs.

Command to list your drives/partitions:

> fdisk -l

Command to format your new drive (assuming its at /dev/hdd1):

> mkdosfs -v -F 32 -n media /dev/hdd1

3. Make a new directory for the mount location

For example, if you want to mount your new drive at “/mnt/media”, do the following:

> mkdir /mnt/media

4. Edit your fstab file so the drive always gets mounted at boot-time.

> vi /etc/fstab

Add the following line to the end of the file and save:

/dev/hdd1   /mnt/media  vfat    users,owner,rw,umask=000    0   0

Mount all the drives (as directed by the fstab config file, I believe):

> mount -a

Your new drive should now be accessible at /mnt/media!

Try copying a few files over and make sure it works alright. Next, configure Samba and you’ve got yourself a new media server. w00t!

Configuring Samba on Fedora Core 4 (Without OS X Samba Client Support)

This guide goes over the process in detail.

There is a caveat in the title of this section because the version of Samba bundled with Fedora Core 4 does not work with Finder (out of the box) on many OSX setups. See this thread for details.

But all in all, setting up Samba was a snap if you just want to access the drive from your PC.

I cruised over to my regular windows box, browsed the network, entered my credentials, and bam! I was copying over files to my new media server!

Uh oh, Browsing the Samba Share Doesn’t Work on My OS X Box!

I thought it was too good to be true!

The Samba version installed with Fedora Core 4 is not the very latest.

You’ll need to download and install the latest version of Samba if you need to access your linux media server from OS X. (unless you’re lucky and you can mount your share from OSX without a problem - maybe Apple’s fixed this bug in the latest build)

But if it isn’t working for ya, there are also configuration settings you’ll need to setup on OSX, and even possibly a simple AppleScript startup launcher which will perform the mount of the network share upon startup each time. (this should work in OS X but is broken on some systems, including mine)

If you’re having OS X samba connection woes, I’ll just have to point you to this thread at macworld.com. It contains most of the information needed to configure your new Linux Samba installation (this was the trickiest part), as well as a few minor settings you need to configure in your OS X “/etc/smb.conf” file.

Auto-Mounting Your Network Share Under OS X on Startup

There isn’t really the concept of a “Mapped Network Drive” under OS X like there is in Windows (there’s mounted volumes, instead). However, you can do basically the same thing but it can be a bit tricky to do so w/o using some AppleScript kung fu.

Open Script Editor and make a script like:

	tell application "Finder"
		open location "smb://myusername:mypassword@myserveraddress/the/path"
	end tell

For example, mine was:

	tell application "Finder"
		open location "smb://sbraford@192.168.1.97/media"
	end tell

From user ‘Virtual1′ on the thread:

Select to save as “Application”, and make sure “startup screen” and “stay running” are NOT checked.

Save the application script somewhere. Next open up your OS X User profiles / settings / configurations.

Click over to Startup Items, then drag your new auto-mounter AppleScript file onto it & make sure it’s enabled and that your settings get saved (may have to click on the Lock icon).

Next, logout and log back on to see if your new network share gets auto-mounted on startup! If so, w00t, you’re in business.

Regularly Scheduled Media Downloads

You have two options here. If you have cable/satellite television, you can use Myth TV as a PVR.

OR, if you only have one big fat Internet connection like yours truly, Broadcatching via RSS + BitTorrent is your answer.

Update: After playing with Azureus and its various RSS plugins for a while, I was still unable to get it to download torrents properly.

Instead, the simplest approach was to mount the Linux Media Server share as a mapped network drive, and configure a Win32 BitTorrent client to do the downloading and just use the server as a file store. (not ideal, but does the job in a pinch.) uTorrent is an excellent C++ based BitTorrent client that has added RSS feed import support in its latest version.

In Part Deux of this guide, I hope to more fully flush out this ‘media server’ setup to include the RSS + BitTorrent auto-downloading feature of your favorite shows.

Recommended Links

Personal Fedora Core 4 Installation Guide
Fedora Project
How to Skip Product Activation in XP (if your OS will not even detect your video card, monitor, network card, etc. etc…. it doesn’t make much sense to buy a full license just to take it for a test drive.)
mkdosfs info
How to Configure a REAL Media Server on FC4
Broadcatching via RSS + BitTorrent

If you use linux, you obviously need a dedicated hosting for your website needs.  If you spend a lot of time online, consider getting a Exchange Server Hosting that will meet all of your requirements!  If you want a credibility in hosting, make sure you do your research.  No matter what type of computer web hosting you need, there is a host to meet your requirements!

Fun with PHP5

Sunday, January 1st, 2006

So, my little baby wholinkstome (well, now that Gabe has helped out with the design its ‘our’ little baby), has reached the point where she needs a new server.

We’ve got some decent ad sales going on there, enough to afford a dedicated server at least.

But, lo and behold… she requires good ol’ PHP 5 due to some libraries / etc. we’re using.

That wouldn’t be such a problem, except that we went ahead and loaded WHM/cPanel on the server to make it easier to manage multiple domains/hosts on the server.

Of course, WHM/cPanel uses Apache 1.x and PHP 4 by default.

If you know of a good ’server guy’ who might be able to help us upgrade our cPanel to use PHP5, plz give a holler.

We can pay by the job, as the box is a totally unmanaged server, hosted by the fine folks at Layered Tech.


You are currently browsing the Shanti's Dispatches weblog archives for the 'Tech Stuff' category.

Shanti A. Braford blogs here.

If you really want to know, just read this.



  

Powered by FeedBlitz