The switch statement is a common control structure in programming languages. You will have undoubtedly seen a few if you spend any time working with Drupal modules or themes. Switch statements love to hangout with a theme's template.php file in preprocess hooks. Consider, if you will, the following:

This recipe is perfect for a quick dinner using leftover pork or chicken. The homemade Chipotle BBQ sauce is a perfect blend of sweet and spicy. And don't be afraid to get creative with the toppings!

INGREDIENTS
2 and 1/2 pounds boneless pork or chicken
1 medium onion, diced
1 large potato
2 large carrots
2 teaspoons minced garlic
1 cup chicken broth
2 tablespoons packed brown sugar
1 tablespoon chili powder
1 teaspoon salt
1 teaspoon ground cumin
1/8 taspoon ground cinnamon
INSTRUCTIONS
  1. Peel and dice the onion.
  2. Slice the potato and carrots

This snippet demonstrates how to create the CSS3 style sticky notes similar to those found on this site.

See a demo at http://jsfiddle.net/8ZSKR/embedded/r...

Personalized pancake

If you are a regular user of Microsoft's Windows operating system, then you have undoubtably been greeted with this popup:

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.

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() written in Python.

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.

Pages

Subscribe to Caleb Thorne RSS