Archive of articles classified as' "Programming"

Back home

Download large file in chunks with Python using urllib2 to a temporary directory

4/12/2011

No Comments

List directories by date using PHP

1/12/2011

I struggled for an elegant way to list directories and files by date with PHP.  Here is the fruit of much Google-Fu.  This will list directories and files from newest to oldest.

1 Comment

Install node.js and npm from source on OS X

14/01/2011

You will need git, and all the xcode goodies. This is the easiest way to copy and paste your way to a working node.js and npm setup with OS X 10.6. Live on the bleeding edge!

No Comments

Create a thumbnail or resize an image with Imagemagick in PHP

28/11/2010

This is the most elegant way I could find to create an thumbnail for an image I want to resize with PHP and Imagemagick. The function will return a filename.

To install imagemagick using Ubuntu, just run

sudo aptitude install php5-imagick

No Comments

massif-visualizer Ubuntu Install Notes

29/07/2010

Here are the partial instructions for Ubuntu 10.04 with branch 8f84a30 from July 29, 2010

Get the depends:
#sudo aptitude install kdelibs
#sudo aptitude install cmake
#sudo aptitude install kdelibs4-dev
#sudo aptitude install kdebase
#sudo apt-get install libphonon-dev build-essential
#sudo aptitude install kde-devel

get kgraphviewer:

#sudo aptitude install graphviz-dev graphviz
#sudo aptitude install kdepimlibs5-dev
#sudo aptitude install boost-build libboost-all-dev

#mkdir kgraphviewer
#cd kgraphviewer/

#svn co svn://websvn.kde.org:443/home/kde/trunk/extragear/graphics/kgraphviewer/ .

Then follow their README and install

Then Get git:
#sudo aptitude install git-core

get the Massif-Visualizer from http://gitorious.org/massif-visualizer:

#git clone git://gitorious.org/massif-visualizer/massif-visualizer.git

Then you can follow the massif-visualizer readme

See images at : http://www.flickr.com/photos/gourneau/sets/72157625248823281/with/5169269487/

3 Comments

Simple Graphical Python Profiling with RunSnakeRun

26/07/2010

sudo aptitude install python-wxtools

sudo easy_install runsnakerun

sudo aptitude install python-profiler

(If you are using Debian check this out : http://www.cherrypy.org/wiki/ProfilingOnDebian
)

run with:

python -m cProfile -o barbazzr.profile barbazzr.py

Check out the output with:
runsnake name.profilepython -m cProfile -o barbazzr.profile barbazzr.py

No Comments

Django 1.2 CSRF verification failed

17/02/2010

Are you updating an old Django  project to use Django 1.2, and getting this error message when you try to login to the Django admin page?

403 Forbidden

CSRF verification failed. Request aborted.
Help

Reason given for failure:

CSRF cookie not set.

Then you need to add  ‘django.middleware.csrf.CsrfViewMiddleware’, and  ‘django.middleware.csrf.CsrfResponseMiddleware’ your settings.py file. Mine looks like this:

MIDDLEWARE_CLASSES = (
‘django.middleware.common.CommonMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.middleware.csrf.CsrfResponseMiddleware’,
)

Thanks to the Django docs http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it

26 Comments

Find the path of a Python module

19/06/2009

The builtin inspect module makes it easy to find out information about the modules you are loading. Just ‘import inspect’ and use inspect.getfile

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import inspect
>>> import random
>>> inspect.getfile(random)
‘c:\\Python26\\lib\\random.pyc’

1 Comment