Disclaimer:
These pages about different languages / apis / best practices were mostly jotted down quckily and rarely corrected afterwards.
The languages / apis / best practices may have changed over time (e.g. the facebook api being a prime example), so what was documented as a good way to do something at the time might be outdated when you read it (some pages here are over 15 years old).
Just as a reminder.

Howto for using py2app on MacOsX

Developer notes for how to use it and common installation problems

Py2app, how to use it on macosx

Installation of py2app

It already exist in Snow Leopard and later (not sure about before) , in
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/


So normally no need to install it on Macosx.

If you need to install it:

Download the latest py2app

Install it from source:
sudo python setup.py install
To use it on your python script:
py2applet --make-setup py2app_test.py
python setup.py py2app

Possible problems

AttributeError: 'NoneType' object has no attribute 'get_config_var'
Solution: ?

Cant recall the error message, but if it complains about argv emulation when trying to execute the app
Set it to false in setup.py: 'argv_emulation': False

Links to relevant websites

py2app, MacPorts, Snow Leopard, and PIL: a match made in Hell
How to make standalone OS X application bundles from PyQt apps using py2app

Usage examples of py2app

Including extra files (e.g. images)
Edit setup.py to include the extra files in DATA_FILES
DATA_FILES = ['pyhon_py2app_package_testing.png']

Alternatives to py2app

Platypus, "Platypus is a developer tool for the Mac OS X operating system. It creates native Mac OS X applications from interpreted scripts such as shell scripts or Perl, Ruby and Python programs. This is done by wrapping the script in an application bundle along with a native executable binary that runs the script."

Python general notes

installing pgdb with mac ports

Make sure you have the macports pip (and not the default one)
sudo port install py27-pip

install with pip:
pip-2.7 install PyGreSQL

If pg_config tool is not available:
Make sure the postgres bin is in the path, e.g.
export PATH=/usr/local/pgsql91/bin/:$PATH

Timeout when waiting for user input

# Expect the user to type something
# if he does not type something within 5 seconds the script complains

import sys, signal

Timeout = 'Timeout exception.' 

def timed_out(signo, frame):
    raise Timeout

signal.signal(signal.SIGALRM, timed_out)

print "write something! "

buf = ''
try:
    signal.alarm(5)
    buf = sys.stdin.readline()
    signal.alarm(0)
except Timeout:
    print "\a----Are you still there?"

if buf:
    print "Received: ", buf

Dump a dictionary

(to avoid "too many values to unpack" problem)

for field, possible_values in fields.iteritems():
    print field, possible_values

Check syntax without executing

python -m py_compile

Convert int to string and vice versa

str(42)
int('42')

Find methods of instance, parameters for function

import inspect inspect.getargspec(flann.nn_index) dir(flann)

boto

Sending/Receiveing msgs to SQS automatically decode/encode base64

jupyter notebook

%matplotlib inline df.Age.plot(kind='hist')

Pandas

df.dtypes df.Sex.value_counts() df.Sex.describe() #number of missing values for each attribute df.isnull().sum() #Selecting someframe[ someframe['ThisIsAcolumn'] == '9' ].head(5) #Selecting based on the index df['itemid'].iloc[3] #Rename columns merged2.rename(columns={'How Many People': 'new_col_name'}, inplace=True) #Export specific columns, leaving out index header = ["somecol", "other_col", "blabablalbal"] merged2.to_csv('/tmp/output.csv', columns = header, sep='|', index=False) #Concatting two dataframes df = pd.concat([dfa,dfb]) #After concatting, reset index df.reset_index(drop=True, inplace=True) http://www.swegler.com/becky/blog/2014/08/06/useful-pandas-snippets/

More programming related pages

Workflow: Release process
Workflow: Bug tracking
Teambox (Redbooth) - Mantis connector
Design Patterns
Git & Github
Go / Golang
CVS
CVS backup script
Distribution process
Installation script
Java Server Faces
Facelets
jibx
jBoss
jBpm
Perl tips
Perl links
PostgreSQL
Python / py2app
Shell scripts
Xslt
Node.js
Facebook / Opengraph
PHP developer notes
Redbooth API through php
Website optimization
jqTableKit demo
Javascript / html / css links