How to create a Python or Django logger to log to a string

8 Jan

I had to allow some of our admin users to view the logic and results of a parsing module to help find and pinpoint improvements. Since my backend Python Celery module already uses Python logging, I needed a way to log to a string to display the results on a Web page.

Here’s a function that will return a StringIO variable and a Python logger. Once you are done logging or need the logger results, you can easily get the output logger in a string. Also, I found a Stack Overflow article to remove Django database debug info from being logged so I added this as a default parameter that can be changed.

Here’s the Gist:

Email recipes and templates for nicely formatted HTML messages

29 Aug

A few geeks may still prefer text emails but when building a site or an app, you know you need HTML emails. It just still works. What doesn’t always work, thought, is the myriad of mail clients that all have their quirks and may break some of your formatting. What you need is a recipe or a template to display your stuff the way you want and ensure it works across most rich clients.

MailChimp HTML templates

While reading Hacker News this morning, I stumbled on this thread about HTML Email Boilerplate and discovered two great resources that deserve a place in your toolbox:

Creating a Generic jQuery Countdown Timer

7 Sep

I needed to create many HTML countdown timers for a little pet project of mine. So, I wrote a jQuery selector function to create countdown timers on demand. These timers are really simple, they countdown for a number of seconds to zero.

Add this to your scripts:

(function($) {
  $.fn.createCountdownTimer = function(selector,time,tick,cb) {
    var seconds = time;
    var el = this;
    tick = tick || 1;
    var timer = function() {
      seconds -= tick;
      if (seconds > 0)
         setTimeout(timer,tick * 1000);
         cb && cb();
    setTimeout(timer,tick * 1000);
    return this;

Parameters tick and cb are optional. tick defaults to 1 as you usually tick down 1 second at a time.

Suppose you have a HTML countdown timer such as:

<div id="my_timer">Starting in <span class="timer">10</span> seconds...</div>

then, all you need to do to start a countdown from 10 to 0 is:


You can also supply a callback as a fourth parameter that will be called when the timer is done counting to zero. For example:

$("#my_timer").createCountdownTimer(".timer",10,1,function() {

Integrating with WordPress 3.0 Shortlinks Support

2 Jul

The official release of WordPress 3.0 being a bit recent, I’ve had a hell of a time trying to find plugin that supports WordPress 3.0. The idea is to get your short URL instead of the WordPress 3.0 short URL that uses your own domain name when you press the “Get Shortlink” button of a post editor. support in WordPress 3.0

I found the “WP” plugin which looks pretty good but does not yet support WordPress 3.0.

So what does an unsatisfied geek do on a Friday evening instead of having dinner? He finds a solution.

1. Download the WP plugin

2. Fix the plugin code

In file wp.bitly.php, put lines 47-48 in comment:

/*add_action( 'wp',      'wpbitly_shortlink_header' );
add_action( 'wp_head', 'wpbitly_shortlink_wp_head' ); */

If you too are a geek and you need to know, this will make sure WordPress 3.0 continues to take care itself of the HTML response header and the Web page HTML header as per the rel=”shortlink” proposed standard. Otherwise, the WP plugin would add these twice to a page which wouldn’t be clean.

3. Modify your theme’s function.php

Add the following code to your theme’s functions.php file:

/* shortlink */

function get_bitly_shortlink($shortlink, $id, $context, $allow_slugs) {
   if (function_exists('wpbitly_get_shortlink')) {
      $slink = wpbitly_get_shortlink($id);
      if (empty($slink)) {
         $slink = wpbitly_get_shortlink($id);
      return !empty($slink) ? $slink : $shortlink;
   return $shortlink;
add_filter( 'get_shortlink', 'get_bitly_shortlink',10,4);

This code links the plugin code to the new WP 3.0 shortlink feature. It also makes sure that WordPress 3.0 will continue to operate as before if you do not enable the WP plugin or you disable it.

Generate the links from the plugin

So that the “Get Shortlink” button gets you a link (instead of the default permalink), these should be generated once from the plugin’s settings. For new posts new links should be created automatically.

Be aware that visits and crawls to your site will generate links for each visited posts if no link already existed for each visited post. This is due to the fact that the short links are included in the code of each of your page to support new standards.

Fix for Facebook URL Linter / Open Graph Protocol Bug with WordPress 3.0

2 Jul

I’ve been helping At Home with Kim Vallee support the Open Graph Protocol promoted by Facebook. It’s easy to implement and great research that we’ll be adding immediately to Shwowp. If you want to learn a bit more why it’s important for your site to implement the Open Graph Protocol, read this article: “Facebook Unleashes Open Graph Search Engine, Declares War On Google”.

URL Linter is a handy Facebook Developer tool that allows you to analyze a Web page meta data to see how Facebook understands it.

The problem is that URL Linter was working for the home page but not for the article pages. After much lost sleep and a call for help on Facebook Developer Forums, Paul from Facebook confirmed it was a bug:

  • WordPress 3.0 added a shortlink feature
  • If you changed your WordPress permalinks to friendly names instead of the default, it adds an HTTP header variable in the form
    • Link    <>; rel=shortlink
    • This new header variable is part of a proposed microformat standard.
    • The Facebook URL Linter and crawler currently has trouble parsing the page when it sees this HTTP header

The Fix

The bug should be fixed by Facebook in about a week. In the meanwhile, if you run WordPress 3.0 and are implementing Open Graph Protocol support to your site, you can add the following code in your theme’s functions.php to disable the shortlink in the HTTP header output:

/* Remove WP 3.0 shortlink */
function empty_shortlink($shortlink, $id, $context, $allow_slugs) {
return NULL;
add_filter( 'get_shortlink', 'empty_shortlink',10,4);

Twitter allows to follow Facebook friends, Facebook blocks feature

23 Jun

In their recent Mashable article, HUGE: Twitter Lets You Automatically Follow Your Facebook Friends, we learn that we can now use Twitter’s Facebook Application to find friends to follow in Twitter.

It looks like it was short lived because minutes after this article was published, it seems that Facebook blocked that capability:

Really wondering what game is being played right now! The Twitter Facebook app allow you (as an option) to publish your tweets to Facebook and it now seems that you can’t find new friends through Facebook so you can follow them on Twitter (and optionally post back to Facebook!). Strange!

Facebook was really quick in blocking Twitter and I’m wondering which Term of Service Facebook thinks Twitter did not respect.

UPDATE: on Techcrunch, there’s now an update article from MG Siegler which says this might be an issue on Facebook’s end. Maybe a coding error or, more probable: a) an API problem on Facebook’s end or b) Facebook really blocked Twitter.

UPDATE 2: it seems it is not intentional. Facebook is working with Twitter to solve the problem.

How to fix the WordPress plugin WP-SpamFree to avoid the “Your location has been identified as part of a reported spam network” error

11 Mar

My wife Kim is the successful editor behind At Home with Kim Vallee. She uses the WordPress platform.

With success and a popular platform, problems with comment and contact form spam becomes quickly a pain to manage. That’s why you need a good toolset to keep your sanity intact. Good WordPress plugins to protect against spamming and keep your installation secure include:

  • Akismet – protects against spam
  • Login LockDown – adds extra security to your login form
  • WP Security Scan – security
  • WP-SpamFree – extra spam protection

WP-SpamFree is quite invaluable against robots and contact form spam. However, it came to our attention that some people would see the following message instead of the contact form:

Your location has been identified as part of a reported spam network. Contact form has been disabled to prevent spam.

See the message when it would appear instead of Kim’s contact form:


This was really annoying. People were telling Kim they couldn’t send comments.

By chance, one PC at our office had this bug. The unique IP address assigned to our network by Videotron seemed clean. So I dug further and looked at the plugin code to understand and debug what’s happening. It seems some browsers in some configurations (in our case a particular Firefox installation on Windows XP) do not transmit the HTTP_ACCEPT_LANGUAGE variable to servers. There is a check in the WP-SpamFree plugin that identifies the visitor as a spammer if this variable is empty.

Once the problem identified, the fix is easy: simply disable this verification. The quick fix to the plugin is to modify the wp-spamfree.php file in the plugin directory to put this condition in comment. See my changes in red:

            $user_http_accept_language = trim($_SERVER['HTTP_ACCEPT_LANGUAGE']);
            if ( !$user_http_accept_language ) {
                $contact_form_blacklist_status = ’2′;
                $spamfree_error_code .= ‘ CF-HAL1001′;
            // Add blacklist check – IP’s only though.

            if ( $contact_form_blacklist_status ) {
                $spamfree_contact_form_content = ‘<strong>Your location has been identified as part of a reported spam network. Contact form has been disabled to prevent spam.</strong>’;
            $content_new = str_replace(‘<!–spamfree-contact–>’, $spamfree_contact_form_content, $content);

That’s it. No more false positives for Kim’s visitors!

I’ll send this issues to the WP-SpamFree devs.

The iPad: The Emperor says you shall pass through our gates – Mac App Store next?

28 Jan

Yesterday Steve Jobs announced his latest creation, the Apple iPad.Bite_me_in_the_rain_by_sherryetal

The Emperor has spoken and it’s very telling. Apple’s present and future is no longer about a fine-tuned combination of hardware and software. It’s also about being the content gatekeeper.

The announcement

We finally know what kind of tablet computer the Apple folks were cooking! Basically, it’s a blend of an oversized iPod Touch and iPhone. At the same time, it’s really a computer; the chip looks much more powerful. It’s supposedly very fast. Like any first generation Apple product, it has a lot going for it while missing a few things. No real surprises except maybe the starting price and very surprised about seeing a touch version of iWorks.

What’s more telling about Steve’s strategy is the lack of support for Adobe Flash. Not that I am very fond of Flash, but it is very telling.

It’s all about control

It’s no secret Steve Jobs is a control freak. It has worked well for him. Since the first Apple computer, Apple has had an aversion for clones. Apple wants to control the whole experience starting from hardware. Forget about having an Orange, a Pear or a Peach. Like Eve, all you need is to get a bite out of the Apple and you’re hooked. (Their logo is really telling). By controlling hardware and software combined with their sense of design and controlled user experience they’ve been able to do what most tech giants still dream of.

But today, controlling the user experience is also all about controlling content distribution.

They’ve done a really good job with iTunes out of distributing songs for people to buy. Then, Apple added an App Store to iTunes to distribute and install software. It made sense: it is more user-friendly and practical. What a success it has been!

Now enters the iPad which uses exactly the same model than the iPhone or iPod Touch. To download and install and application you still need to go through the Apple store. Oh, and you can download books now.

The excuse for the lack of Flash support on the iPhone Safari browser was that it was using too much CPU. It would deter the user experience. It wasn’t a bad excuse. Heck! Flash is known to bring underpowered computers to a crawl. But that excuse doesn’t fly well with the iPad. Those who got to try the device were all raving on how fast it is with its new Apple designed chip.

I do not care that much about the lack of Flash on Web sites. It is usually more a pain than a gain.

On the other hand, Adobe is prepping Flash CS5 which allows to build iPod Touch, iPhone and iPad applications. Who needs Flash support? Adobe is building it in some way! Who needs Adobe Air support on the iPad computer? Here’s a solution!

The thing is these Flash applications will have to be distributed by the App Store and approved and censored by Apple. There is no other way to do it unless you want to break Apple’s terms of use.

That’s why I don’t see Flash being supported natively in the browser on the iPad or the iPhone. It would be a way for developers to distribute software in a Web page without going through the content distribution gatekeeper Apple has become. Do pass go, but we’ll charge a fee on your 200$!

What’s next?

Apple’s announcement of the iWorks software suite for the iPad was quite a surprise to me. Digesting this announcement means Apple does not see the iPad as just an oversized iPhone. It’s also a computer where you can get some sort of work done. With the new screen estate, I can see a lot of exciting business applications being built for this new toy. But again, all these will have to pass through the gatekeeper.

To conclude, I predict we will see App Store support for Mac applications in the near future. It would make perfect sense when you think of it. Users get to download everything in a single place. Invoices are easy to find. You are dealing with a single company you trust. Why download and install something from somewhere else? That’s really too hard and too risky!

I wouldn’t be surprised to someday see a new computer from Apple which will make everything even easier for the computer illiterate. It will support a mouse and keyboard when touch is not yet as efficient. You will be able to get some real work done with it. It will use a blend of the Mac OS and the iPad OS to offer a seamless experience from hardware to content consumption. We almost have this device with the iPad but it’s just a start. In a future near you, your Adobe PhotoShop or Microsoft Office installations for a Mac will probably be downloaded from Apple.

Image source: Bite me in the rain by *sherryetal


Some interesting articles popped-up on the subject after I wrote this:

The joys of IP telephony

5 Jan

IPphoneI’ve been quite busy with work during the holidays. I had a huge mandate to complete for January 4th. This doesn’t mean I’m always at the office. I’m always looking for new way to make my office more mobile.

This is why I’ve been using an IP Telephony service (from Ubity in Montreal) for a year now. With such a service, you can plug your phones anywhere there’s an Ethernet jack.

Location, location

The location where I’m at doesn’t matter. I could be in Mexico, in Europe, wherever and when I use my phone, it’s my office phone calling locally from Montreal.

So, I have a phone plugged in at my office, I have one at home and I have another one at my cottage. When the phone rings these 3 phones will all ring at the same time and I can answer like I was at the office. When I call someone, I always look as if I was at the office. I can be at my cottage and answer as if I was at the office after a day of skiing.

SubaruNeigeSuttonNot only that, I also have software phone support. So, when travelling, I can use my laptop at the hotel to make calls: I just plug in my iPhone headphones (which as a microphone) and I still appear as being in the office when returning calls from clients!

I’ve also installed a VoIP application on my iPhone called iSip. Unfortunately, it does not allow to make calls over the 3G network yet. It only supports Wi-Fi. The cool thing is I can be having a glass of port and smoking a cigar on my terrace and use the phone to call back clients or partners while still looking as if I’m at the office!

The day I’ll move my office, I just need to plug the phone somewhere else and I’m instantly ready to make and answer calls.


This kind of service has all the usual telephony and corporate voicemail features for an affordable price. Calls in North America are free (1000 minutes per months) and calls to countries the other side of the Ocean are ridiculously cheap. On top of that I have features such as “find me” where in my corporate voicemail, people can press a button in my inbox to find me. They get to speak their names while the service calls my cell phone. Then, when receiving the call on my cell phone, after listening to who’s calling, I can press a button to accept or ignore the call.

The downside is I’m extremely reachable. But I often need to be.

The upside is that I can enjoy the pleasures of life a bit more and work where it’s more practical and enjoyable while looking like I’m never leaving my office and even sleeping there!

My predictions for 2010

4 Jan

So, I decided to join the bandwagon and give my predictions for 2010 in technology and social media.450px-Glaskugel_CrystalBall

1. We’ll see a new breed of social media curating

As we are more than ever overloaded with information, implicit filtering becomes a must. Are you able to keep up with your RSS feed? I can’t! Do you feel like you’re missing on a lot of interesting conversations shared across your networks? I sure do!
We’ve already seen a bunch of aggregators in the social media landscape as destination sites. The next wave, which will happen this year, will focus on personalized our social media streams based on our social interactions and preferences. We’ll see a lot of innovation in this space.

2. Telcos start adopting a single Android platform

Google’s upcoming Nexus One Android phone proves that Google can’t afford to have a platform where it does not better control the experience in its fight against Apple’s iPhone. I predict we will see many telcos start adopting a unified Android which will be a packaged version of the Nexus One and thelcos will start dropping other Android implementations.

3. It will be the year of BuddyPress

As more and more bloggers become media empires and as different brands want to embrace social media, we’ll see an impressive number of mainstream sites adopt BuddyPress to build their own communities.

4. Bing will integrate social shopping features

As innovation in e-commerce is stagnating outside of Amazon, social shopping will continue to boom. We’ll see major players such as Google, Microsoft and even Apple jump into social shopping. Bing, which already has some focus on shopping, will integrate social features in its search engine.

5. There will be at least one high profile lawsuit against Apple

Losers love their lawyers and success breads jealousy. A major company will have a major lawsuit against Apple. Easy prediction. There probably will be more than one high profile lawsuit against Apple. As a bonus, Apple will fend these off.

6. 2010: the year of the tablet

Another easy prediction. Everyone’s making it. I had to.

The real questions are: Will Windows 7 stand of the crowd with its multi-touch features? Will Android be majorly used? Will Apple’s tablet be great enough? As a side prediction it is sure that Apple fans will drink to cool-aid.

7. More anti-trust investigations against Google

The American Department of Justice and the European Union will open both new probes and investigations into Google’s activities. At least another high profile acquisition will be blocked. It a rite a passage Microsoft had to go through and its Google turn.

8. Facebook to become the next Paypal

In 2010, Facebook will finally launch a payment platform that can be used as a virtual currency. Eventually, users can exchange credits.

9. Facebook e-commerce applications

We will see adoption of Facebook’s payment platform outside of social gaming and we will see it adopted on Facebook Connect sites too. Want to make a donation through Facebook?

10. We’ll see innovation in e-commerce outside of Amazon

I had to make this prediction because I feel e-commerce is still at the 1.0 stage. It’s a matter of time before we begin to see innovation outside of Amazon. I’m making this prediction because you’ll have to stay tuned to Shwowp a new startup from Tara Hunt and yours truly. If others don’t start to innovate, at least there will be us! In any case, it will become true if #9 becomes true.

Image copyright: