May 21, 2012

Lighttpd on Cpanel VPS

Working on a new project for a client, I need to run Django/Satchmo. At my advice, the client purchased a VPS from LiquidWeb to run it on.

The problem is that I want to run with Python 2.5 instead of 2.4, and I don’t want to use Apache 1.3. Unfortunately, that’s what comes stock with CPanel. So, I came up with a decent workaround that I haven’t seen documented anywhere else.

What I did was to set up Lighhtpd on one of the other IPs provided with the account, and I simply use my custom-compiled Python with that.

[Read more...]

Enhancing FAQs with jQuery

I’m so pleased by how useful and concise jQuery has been for my development of a dynamic FAQ module for Drupal. I can’t share that module yet, but I can talk about the jQuery that gives it a snappy and useful facelift.

It isn’t original, of course. Just click-to-toggle questions on a faq page. What is original is how easily styled this solution is, and how concise the javascript used to get there. Add to that a reasonable markup scheme, not burdened with superfluous divs or ids, and I’m a happy developer.

[Read more...]

CSSEdit is my friend

kungfu CSSEdit is my friendDeveloping sites for clients involves a lot of heavy CSS work for me. I’d been using Aquamacs, an Emacs editor for OSX. That was good, but I don’t care for any of the CSS modes available. I moved to TextMate, which was much better, but still very much a code, reload, code, reload cycle.

That gets very slow, especially when developing using something like Drupal which isn’t very speedy to begin with.

[Read more...]

Howto Reset The Admin Password in Django

I keep needing to do this, darn it! I leave a project for a few months, possibly push it live, and then I go back to fire up the dev server but I simply cannot remember the password I used for admin during development.

Why don’t I use my stupid-development-password? I don’t know, but this seems to happen with some regularity.

Luckily, it is trivial to fix with a few lines at the python commandline:

Deep:/opt/webapps/invisible bruce$ ./manage.py shell
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
Type "copyright", "credits" or "license" for more information.

IPython 0.7.2 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from django.contrib.auth.models import User

In [2]: users = User.objects.all()

In [3]: users
Out[3]: [<User: admin>]

In [4]: users[0].set_password('whatever');

In [5]: users[0].save()

That’s it, fire up the dev server again and your new password will get you in.

[tags]django,python,commandline,auth,login,password[/tags]

Semitransparent rollovers made easy with JQuery

I’m continuing to enjoy working with jQuery. This article shows a simple method for enabling semi-transparent rollovers which actually work on IE 6. Yes, you could use a .gif file for a crude version, but many effects, especially “glowing” effects just look much better if you use a format which supports alpha channel transparency.

[Read more...]

Dell CN 3100 for OSX

I just got my beautiful new color laser printer from Dell. I did a lot of research, and I really think Dell’s CN3100 is the best color laser currently available for under $400 (if you buy it from delloutlet.com). Besides the 100s of dollars of savings you get from buying from Dell Outlet, you also get full print toner cartridges, instead of starters. That will save hundreds by itself a few months down the line.

I had just one issue getting it to work with my Mac OSX machine. Most of the instructions talk about how to set up on Windows, and there is little information for Mac setup. At least not if you want to print to the network.

A bit of experimenting got me to the answer:

1) Do Install the printer driver that you download from Dell’s support site. Even though it knows Postscript, installing Dell’s driver makes a difference.
2) Install the printer using “HP Jetdirect (Socket)”, not “IP Printing Protocol”. If you need to find the IP address, press “menu” on the printer, then the checkmark when the screen says “print settings”. A page will print (very fast) showing the current IP Address. I always make a label to put on the printer, it is amazing how often you end up needing that information in the future.
3) You can browse to the printer and control most of its settings via a web interface.

Update: Download the driver here

[tags]cn3100, dell-cn3100,osx,color laser,color-laser[/tags]

Django Formatter Mixin Class

guitar Django Formatter Mixin ClassI’ve always disliked having to write __repr__ methods for my classes. It isn’t hard, it is just tedious. In Django, it is especially important to make them, since the admin pages use that method when listing objects from the data model.

However, since Python allows classes to have multiple inheritance, I have long since made a helper “Mixin” class to remove most of the pain from writing my __repr__ methods. If you haven’t heard the term, a “Mixin” is a class which adds functionality to classes which inherit from it. The philosophy is that it shouldn’t change base functionality, thus avoiding many of the problems with multiple inheritance.

Philosophy aside, mixins can be extremely useful, and I love this one. [Read more...]

Converting WMA to MP3 on OSX or Linux

headphones Converting WMA to MP3 on OSX or LinuxFinding this technique took more time than I thought it should, so I thought I’d share a quick and simple music transcoding tip.

Converting WMA to MP3

1) Get mplayer and lame installed. I use the accelerated and precompiled mplayer and lame for OSX.

2) Create a simple shell script:

#! /bin/sh
set -e
F=$1
mplayer -ao pcm:file="${F%.wma}.wav" "$F"
lame --preset hifi "${F%.wma}.wav" "${F%.wma}.mp3"
rm -f "${F%.wma}.wav"

Save as “convert_wav.sh”, make executable, and run it on your wma files. An easy way to hit all of them in a directory tree is:


find . -name "*wma" -exec convert_wav.sh {} \;

Thanks to the original version, found and modified from that given on Macosxhints.com.
[tags]mp3, osx[/tags]

A Django Killer App – Web Table Data

light bulb yellow A Django Killer App   Web Table DataYet another great use for Django is to make trivial the creation of shared tables & forms for internal projects. It is one of the most common needs in any size company, “Make me a web form to capture these data.” “Oh, and make sure to keep it locked down so that xxx dept can’t see it, and only you and I can modify it.”

Making these kind of web apps is one of the most boring tasks possible, yet they are both common and almost always poorly implemented. After all, they are just for internal use, right? And “they” rarely give you enough time to make a decent app anyway.

Well Django to the rescue. In four steps, you can have an app with far more functionality and usability than you’d ever have with some quick-hack up PHP page or ASP.

Step 1: Create the project directory and app directory

$ django_admin startproject projectbase
$ cd projectbase
$ ./manage.py startapp projectname

Step 2: Edit projectbase/settings.py
You can leave most everything default, at the simplest you can simply use a SQLite database, which requires no password or database setup. Be sure to enable the admin app, like so:


DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/path/to/your/project.db'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'projectbase.projectname'
)

Step 3: edit projectbase/projectname. Models.py: Here you put the class or classes you want to track in your table. Here is an example taken from a simple migration tracking app I made at work.


from django.db import models

class Migration(models.Model):
    account = models.CharField(maxlength=30)
    email = models.EmailField(blank=True, null=True)
    prop = models.CharField(maxlength=30, null=True)
    requestor = models.EmailField()
    domains = models.TextField()
    target = models.CharField(maxlength=6)
    status = models.CharField(maxlength=20,
                              blank=True, null=True)
    created = models.DateField(null=True, blank=True)
    scheduled = models.DateField(null=True, blank=True)
    completed = models.DateField(null=True, blank=True)
    archived = models.DateField(null=True, blank=True)
    notes = models.TextField(null=True, blank=True)

    def __repr__(self):
        return self.account

    __str__ = __repr__

    class Meta:
        get_latest_by = "created"
        ordering = ("created",)

    class Admin:
        list_display = ("account", "email", "prop",
                        "requestor", "domains",
                        "target", "status", "notes",
                        "created", "scheduled",
                        "completed", "archived")
        search_fields = ("account", "domains")

Step 4: Create the database and tables

$ manage.py syncdb

At this point, you have a full fledged system available to you. Start Django however you please, add a few users and show off. You’ll have a full app available, with sorting of tables, updating, searching, and full authentication. All in a half hour of work.

[tags]django,killer app,python[/tags]

Django on Rimuhosting

thumbs up Django on RimuhostingThis is just a quick post to confirm that Django does indeed work perfectly on Rimuhosting with very little effort required to set up. It is fast, it connected to my Mysql db without a peep of a complaint, and it is making me a happy developer.

Setup details

I’m using Rimu’s “MiroVPS3″ plan. It is $39 a month, less 10% for being an open-source developer. It provides 4G hard drive space, 60G bandwidth (in and out combined), and 160 MB ram.

I’m running the following “stack”:

  • Debian: I know and love Debian much more than any other Linux distro. Almost everything is installable with a simple “aptitude install whatever” command.
  • APF: firewall, set up according (mostly) to the instructions on Webhostgear. I had to tweak it for Debian, by setting “monokern=1″ and by symlinking /etc/rc.d/init.d to /etc/init.d
  • Imap/Smtp set up according to the instructions on The Perfect Rails/Debian/LightHttpd Stack article.
  • Mysql: Actually not my favorite db, but I didn’t want to convert to PostgreSQL at the moment, at least not until I’d proven my existing dev setup worked. Rimu set this up for me, since I’d requested a Django setup.
  • PIL: I need the Python imaging library, so “aptitude install python-imaging” did the trick.
  • python_mysqldb: Another simple “aptitude install python-mysqldb”
  • Apache2 with Mod_Python: Apache2 is more flexible about vhosts, and I’m going to use the heck out of them. Mod_python is the preferred deployment environment. I am not using any other mod_plugins. Rimu set this up, and I made vhosts entries based on what I read in the django documentation. The only “tricky” bit was setting up a different vhost for the media URLs. I did that one without mod_python support, to make for lighter server threads.

It is a very responsive environment. I can hardly wait to deploy some real apps on it very soon.

[tags]django,rimuhosting,debian,vps setup,python webhosting[/tags]