Skip to content

Instantly share code, notes, and snippets.

View nfarring's full-sized avatar

Nathan Farrington nfarring

View GitHub Profile
@nfarring
nfarring / Toolchain-ELDK-4.1-ppc_85xx.cmake
Created October 22, 2010 02:16
A CMake toolchain file for using the ELDK 4.1 to target the MPC85xx processor family.
# This is a CMake toolchain file to configure CMake to use the ELDK 4.1
# cross-compiler for the Embedded PowerPC MPC85xx family.
#
# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=Toolchain-ELDK-4.1-ppc_85xx.cmake
#
# Reference: http://www.cmake.org/Wiki/CmakeEldk
#
SET(ELDKBASE $ENV{ELDKBASE})
SET(ELDKROOT $ENV{ELDKROOT})
SET(ELDKLOCAL $ENV{ELDKLOCAL})
@nfarring
nfarring / Toolchain-ELDK-4.2-ppc_85xx.cmake
Created October 22, 2010 02:24
A CMake toolchain file for using the ELDK 4.2 to target the MPC85xx processor family.
# This is a CMake toolchain file to configure CMake to use the ELDK 4.2
# cross-compiler for the Embedded PowerPC MPC85xx family. This file
# assumes that the ELDK is installed to /opt/eldk-4.2.
#
# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=Toolchain-ELDK-4.2-ppc_85xx.cmake
#
# Reference: http://www.cmake.org/Wiki/CmakeEldk
#
# The name of the target operating system.
SET(CMAKE_SYSTEM_NAME Linux)
@nfarring
nfarring / CMakeLists.txt
Created October 28, 2010 17:51
Example of how *not* to generate a Python wrapper library from a C library using CMake. Instead, CMake should only be used to build and install the C library, and distutils should be used for the Python wrapper library.
find_package(PythonLibs)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_PATH})
find_package(SWIG REQUIRED)
if(SWIG_FOUND)
include(${SWIG_USE_FILE})
#set(CMAKE_SWIG_FLAGS "")
#set_source_files_properties(my_swig_file.i
# PROPERTIES SWIG_FLAGS "")
#
@nfarring
nfarring / build_python_wrapper_library_with_swig.sh
Created October 28, 2010 17:58
This script manually builds a Python wrapper library for a C library. There is an easier/better way to do this using distutils.
#!/usr/bin/env bash
#
# Generate my_python_library_wrap.c and MyPythonLibrary.py
#
swig -python my_python_library.i
#
# Generate _MyPythonLibrary.so
#
gcc `python-config --cflags --ldflags` -I/path/to/my/c/library/headers -L/path/to/my/c/library -lmy_c_library my_python_library_wrap.c -fPIC -shared -o _MyPythonLibrary.so
@nfarring
nfarring / gitall.sh
Created October 28, 2010 19:57
Iterates through all of the git repos in the current directory and performs some git operation. The default is 'git status'.
#!/usr/bin/env bash
GITCMD=status
if [[ -n $1 ]]; then
GITCMD=$1
fi
echo
for dir in `ls`; do
(if [[ -d "$dir" && -d "$dir/.git" ]]; then
@nfarring
nfarring / gist:654573
Created October 29, 2010 22:32
Remove all .svn subdirectories.
find . -name .svn -exec rm -rf {} \;
@nfarring
nfarring / gist:704717
Created November 18, 2010 07:18
Console output when compiling Thrift 0.6.0-dev with the C++, Python, and Perl languages.
(Helios-archlinux)[nfarring@thanos thrift]$ PY_PREFIX=$VIRTUAL_ENV PERL_PREFIX=$VIRTUAL_ENV ./configure --prefix=$VIRTUAL_ENV --without-java --without-ruby --without-php --without-php_extension --without-erlangchecking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
@nfarring
nfarring / TemplateClass.py
Created January 28, 2011 01:43
A template for a Python module that implements a single Python class.
# Copyright (c) 2011, Nathan Farrington
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
@nfarring
nfarring / typecheck.py
Created January 28, 2011 13:55
Python runtime type checking decorator function
import functools
def typecheck(*args1,isclassmethod=False):
"""Python is a language with typed objects, but untyped references. This means that there is no compiler to help catch type errors at design time. This typecheck function acts as a function decorator so that you can declare the type of each function or method argument. At runtime, the types of these arguments will be checked against their declared types.
Example:
@typecheck(types.StringType, Decimal)
def my_function(s, d):
pass
@nfarring
nfarring / gist:1078911
Created July 12, 2011 20:32
Script to install lastest version of Python on a Ubuntu/Debian system.
# Make sure we have the basics.
sudo apt-get install build-essential
# Install the build dependencies for Python.
# Replace with python2.7 if your distro supports it.
sudo apt-get build-dep python2.6 python-gdbm python-bsddb3
# Use pythonbrew to actually compile Python.
curl -kL http://xrl.us/pythonbrewinstall | bash
pythonbrew install 2.7.2