Submitted by Caleb Thorne on Wed, 2012-06-13 07:14
Many languages support a control structure called the switch statement that is an alternative for if/else-if. Python, however, has no switch statement. Does that mean we must always resort to using a sequence of if/elif? Not necessarily! Python uses one of the most efficient hashing algorithms for it's dictionary type. We can use a dictionary to create a type of switch statement that is both efficient and very elegant.
Consider the following sequence of if/elif to find a holiday for a given month.
Submitted by Caleb Thorne on Fri, 2012-06-08 07:49
Sometimes it is necessary to remove all (or some subset of) xml style tags (eg. <p></p>) from a string. If you're familiar with PHP, then you probably already know about the strip_tags() function. Here is a simple equivalent to strip_tags() for Python.
Submitted by Caleb Thorne on Thu, 2012-06-07 09:20
Recently, while writing some automated tests for Examiner.com, I ran into some issues with CKEditor. We use CKEditor as the default wysiwyg editor on the site. When you configure CKEditor you attach it to a normal textarea element that is then hidden and replaced by the CKEditor field. In this post I will demonstrate how I implemented an custom element class to interact with CKEditor as if it were any other field.
Submitted by Caleb Thorne on Sat, 2012-06-02 07:12
By default Drupal sends a mail as soon as you make a call drupal_mail(). For relatively small sites this may never be a problem. However, if you run a large site with many users, then you need to develop a stratagy for controling how much mail gets sent at a given time. Imagine that you have a site where users can subscribe to be notified by email everytime you post a piece of content. When you have thousands of users subscribed, a ton of mails will be sent immediatly and php may time out as Drupal tries to process all of the subscriptions at once.
Submitted by Caleb Thorne on Fri, 2012-06-01 12:43
Understanding Drupal's hook_mail() implementation is essential if you want your custom modules to send emails. It is, however, one of the strangest hook implementations you will find in Drupal. But have no fear! In this post we will dig into the details of sending emails with Drupal. The focus will be on Drupal 7 but not much has changed in the newest version so most of the information presented will still apply for Drupal 6.
Submitted by Caleb Thorne on Tue, 2012-05-29 12:46
An essential part of debugging for web based tests is the ability to grab a screenshot of the current page. A good test design should automatically take screenshots of important pages for manual review or any time an assertion fails. Fortunately Selenium Webdriver (http://seleniumhq.org/docs/03_webdriver.html) makes this very easy. Below is an example of taking screenshots using Webdriver and python.
Taking a screenshot with python is as simple as calling
Submitted by Caleb Thorne on Thu, 2012-05-24 13:50
Git is a fast distributed version control system. If you haven't heard of git, you can read all about it at http://git-scm.com/. Here are some convenient aliases I've created to speed up Git usage. You can put these directly in your .bashrc or .bash_aliases file for unix based systems.
First, some basic commands that I find myself typing often.