New Lines to Paragraph Tags (nl2p)

Problem: Emails from your site go out in a good looking HTML format, but some of the content you want to inject in those emails are plain text while others are already formatted with HTML. The email content of the plain text emails which are only plain text now appear as one big block of text with no line breaks.

Let's look at this problem specifically in the context of a Drupal website.

All the emails such as welcome, password recover, etc... are plain text by default. Now you want to add a nice email template utilizing a module like mimemail.

MySQL: Restore a DB From the Command Line

This is a pretty basic tip today, but I noticed someone going through awkward measures to re-import a database over an existing database the other day. I thought I'd just make a note of how you can restore a db in a couple commands.

Scenerio: You have a development environment setup and you want to restore a fresh copy of the production MySQL database.

- The database on the development system is named: "mydb"

- You are using the command line in a directory that has the sql file you want to install: "mydb.sql"

Installing Drush without PEAR

Here's an easy way to install drush without PEAR.

Note, replace the wget argument with a current version of drush. http://drupal.org/project/drush

# cd /usr/local/share/
# wget http://ftp.drupal.org/files/projects/drush-x.x-x.x.tar.gz
# tar -zxvf drush-7.x-5.7.tar.gz 
# rm tar -zxvf drush-7.x-5.7.tar.gz
# chmod a+x drush/drush
# ln -s /usr/local/share/drush/drush /usr/local/bin/drush

When you want to update drush, simply replace the drush directory in /usr/local/share.

CyberSource is Extremely Developer Friendly!

I recently worked on a project that required payment profile management/purchasing and refund functionality for an ecommerce site.

CyberSource was the gateway I was to work with. I wasn't quite sure what to expect going into it, but I have ended up with a very high respect for the company and their support staff.

The documentation is thorough, but somewhat fragmented. I got most of the information I needed from the docs, but I was left scratching my head a few times when I could not find the details I needed.

Drupal 7 Ubercart - Programmatically Capture Pre-Authorized Payments from Authorize.net

I'm working with Drupal 7, Ubercart, and the Authorize.net payment gateway.

The goal here is to pre-authorize the payment at check-out, and capture the payment once the items have been shipped. I'm using order status to trigger when that happens, but I wanted to just show an example of how to capture that pre-authorized transaction.

    Important notes:

How to Read Line Number x of a Large File with Awk

The Situation: You have a 600 GB database dump that produces an error on line 7500 when you attempt to import it.

This size is generally too large to work with in vi. Emacs will generally handle large files like this OK, but maybe it isn't available or your emacs fu isn't quite there.

You can easily achieve the solution with Awk, which is usually available by default on most Linux systems.

awk NR==7500 mysql-dump-file.sql

Bash: Command Line Shortcuts

Here's a few shortcuts that may increase your productivity in the command line.

Navigate around the current command

ctrl+a -- Go to the beginning of the line.
ctrl+e -- Go to the end of the line.
ctrl+w -- Delete last word.
ctrl+k -- Delete everything after the cursor.
esc+f -- Move cursor forward one word.
esc+b -- Move cursor back one word.

Recall the last command with !!

Twisted, Long Polling, & JSONP

I recently decided to use Twisted as the framework for a new project. In short, this app listens to and parses incoming events from multiple servers, as well as issues commands back to them.

Once I had Python doing its job managing the data, the next step was to expose the data in memory from the Twisted app to an existing PHP/Drupal UI. Twisted makes it pretty simple to attach an HTTP server to your app, so I did just that.

Why JSONP?