September 3, 2010

How To Run Sandboxed Django Sites in Production

Recently, I moved all my sites from a dedicated server to a great VPS over at SliceHost. I took the opportunity of “the big move” to fix an ongoing problem I’d had, which was that all four of my Django sites were using the same libraries.

Ouch! That meant that I couldn’t update any of my sites without updating all of them, or at least retesting all of them.

This article will explain how I sandboxed my Django sites, so that all of them have their own versions of the appropriate library, and how I have them all running on the new production server.

[Read more...]

Technorati Tags: , , ,

Git SVN Error – Fixed

While working on a SVN project using my new favorite tool, “git”, I ran into a small problem. A network bobble caused the subversion portion to fail. I stopped it, but then when I tried again, git said:

Cannot dcommit with a dirty index. Commit your changes firstor stash them with `git stash'.
[Read more...]

Technorati Tags: , , , ,

How To Kill nasty Word Garbage Characters in your CMS

Recently I was doing a server move for a client. From an ancient slow system costing her too much money (and me too much bother dealing with a know-it-all-wrong admin) at Today.net, to a nice modern VPS reliably, competently and fully managed by LiquidWeb.

Last year, I wrote her a travel reservation & quoting app in PHP/Drupal. That gave her a lot of nice CMS capabilities for handling her own pages, but the problem is that she uses Word to compose most of the text before adding it. Grah! Word is a lot of things to a lot of people, but it is not a good app to use for that purpose. It likes to leave more than a few garbage and invisible characters scattered around when you cut and paste from it.

The problem really reared its ugly head when I exported the data from her database. Or rather, when I imported it into her new server. Garbage characters everywhere. Messing with character encodings simply did not help either.

I was desperate to get this done, since it was 1 in the morning. I’d started the transfer late at night so I wouldn’t step on any customers creating new travel quotes. I had to get it done in an hour or two or else put it off to the next day and start over.

I almost started writing a load of regular expressions, but I did one last search for help. Aha! My beloved TextMate has a command for just this problem. Just select all, and go to “Bundles > Text > Converting > Transliterate Selection to ASCII”. Done!

Thank you TextMate.

P.S. Yes, I suppose I could’ve used the iconv command in Linux on the server. Maybe. Hassle hassle hassle.

[tags]osx,mysql,encoding,unicode,textmate[/tags]

Django and Lighttpd configuration for smooth SSL

I use and prefer Lighttpd for serving my Django applications. Tonight I worked out a nearly perfect configuration which allows me to serve the app through fastcgi in both http, and SSL-enabled https. The media files are directly served by Lighty, without hitting the django backend at all, for maximum speed.

Better yet, this configuration allows me to directly serve the media files through ssl without having to get a separate certificate for the web server. Lastly, it serves both “www” and “non-www” versions of the domain, automatically redirecting “www” traffic.

[Read more...]

Cross-browser safe, readable Javascript style

Over time and thousands of lines of professional Javascript programming, I’ve developed an almost bulletproof Javascript layout style. It is important to have one, even if you are the only person working on your script, because:

  • it helps you read the code more quickly
  • it helps you not forget browser "gotchas"
  • it makes your code more reusable from project to project

My style rules

  • All functions and variables should live in their own namespace, not polluting the base context as much as possible. In other words, I never write simple “function foo(arg) { … };”, since that might conflict with other libraries implementations of "foo." Instead I always start every javascript source file by declaring my root namespace. I use "SSS" as the root, like so: "var SSS = SSS || {};"
  • Always put related functions together in their own namespace. For example, on a recent project codenamed "scr", I have three namespaces: SSS.scr, SSS.util and SSS.layout. This allows me to reuse useful and debugged code on different projects.
  • I put module-level variables at the top of the module namespace, then alphabetize all other functions.
  • I put a final declaration at the end of the array, "ZZZ : ‘do not remove’", which keeps me from making the IE and Safari deadly mistake of having a trailing comma at the end of the last function.

An example javascript file using my style


var SSS = SSS || {};

SSS.scr = {

    active : 'switch-0',
    flag : false,
    initialized : false,
    log : false,
    update_depth : 0,

    add_delimited_field : function(field, count, delimiter, defval) {
        // example
    },

    calc_price : function() {
        // example
    },

    cents_to_dollars : function(val) {
        // I like this simple function, so I left it in.
        var d = Math.floor(val/100);
        var c = val % 100;
        if (c < 10) c = "0" + c;
        return d + '.' + c;
    },

    cleanup_names : function(adults, children, total) {
        // example
    },

    init : function() {
        // init stuff here
        SSS.scr.initialized = true;
    },

    ZZZ : "do not delete"
}

// jquery onload initializer
$(function() {
     SSS.scr.init();
});

[tags]javascript,style[/tags]

Fixing Exim sender callout error

On my new dedicated server, I’ve been getting reports of mail bounces. Looking more closely at them, I found they said “451: Deferred sender callout cannot be verified.”

This is the result of an anti-spam measure that Cpanel enables by default for Exim. It took a while, but I finally found the well-written discussion and fix on Michael Brandonisio’s blog.

Basically, you simply add a white-list to exim for people who have misbehaving ISPs. The problem is really on their side, but telling them to fix their mailservers just doesn’t seem to work very well.

[tags]exim,cpanel[/tags]

Mass Import Yojimbo Passwords

YojimboI searched all over the place last night and I couldn’t find anything that could import passwords into Yojimbo for me. I did see a lot of complaining about the lack of ability to do so, however.

Since I really like the app in most ways except for its lame import capabilities, I whipped one up to import my 250+ password entries from a different program.

Get the program: Yojimbo Importer 1

Read on for discussion of how to use it, or else just look at the instructions provided in the download.

[Read more...]

Related posts

Technorati Tags: ,

Tricky Drupal Javascript Loading Problem

drop Tricky Drupal Javascript Loading ProblemA short tale about squashing a bug.

You see, my mistrust for IE made me miss the real problem. What was happening was that in IE 7 on Vista, a site I’m building for a client was not loading any Javascript. It wasn’t even loading the base Javascript "jquery.js" and "drupal.js", so my site theme Javascript wasn’t working at all.

I dug in and began tracing code using my typical technique of embedding "drupal_set_message()" calls in the suspect areas. Sure enough, no Javascript was getting loaded, but only when I used my IE test machine.

[Read more...]

Django auto_now Removal Gotcha

DjangoThe latest Django revisions have removed the shortcut handlers "auto_now&quot and "auto_now_add". This didn’t look like a very big deal to replace. I simply did what was suggested in a django-users thread.

The problem was that after I did that, my live code seemed to work fine, but my test cases had several repeatable errors that I just couldn’t reproduce on the live server or at the command line.

[Read more...]

VPN Client for Vista using Parallels

A recent client needed me to run some Windows-only software from their network. Since I have my lovely new MacBook with Parallels and Vista installed, I thought this should be no problem.

Famous last words.

Actually it wasn’t so bad. I don’t actively hate Vista, at least not since it is held captive in my MacBook. The problem was that I needed to connect to the client’s LAN using a Cisco VPN client and Vista didn’t like that software one bit. It would simply fail with no explanation or logging every time.

I found a solution, or at least a thread discussing possible solutions at Bill Evjen’s Blog and I crossed my fingers.

[Read more...]