Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
pyrtsa / default.o.do
Created July 8, 2011 12:49
A redo file I've been using for my pet project
redo-ifchange env.sh && source env.sh
SRC=${1#"$BUILDDIR/"}
redo-ifchange "$SRC" # <- Mark the source (.cpp) dependency to Redo's database
$COMPILE -c "$SRC" -o "$3" $CXXFLAGS $INCLUDES -MMD -MF "$1.o.dep"
DEPS=""
while read -r line; do # Loop over all the header dependencies, and collect
@pyrtsa
pyrtsa / output.txt
Created July 16, 2011 18:40
std::map using string keys compared backwards
map contents in order:
- three: 3
- one: 1
- two: 2
- four: 4
map["three"]: 3
/path/to/nt2/build $ cmake .. -DCMAKE_C_COMPILER=gcc-4.6 -DCMAKE_CXX_COMPILER=g++-4.6 -DCMAKE_BUILD_TYPE=Release
-- [nt2] build type: Release (-O3 -DNDEBUG )
-- [nt2] loading module arithmetic
-- [boost.simd.sdk] SIMD flag: -msse4.1 -mfpmath=sse
-- [boost.simd.sdk] target system: Mac OS X (Darwin 10.8.0)
-- [boost.simd.sdk] target processor: x86 (i386)
-- [boost.dispatch] Boost version: 1.47.0
CMake Error at cmake/nt2.preprocess.cmake:27 (string):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
@pyrtsa
pyrtsa / stderr.txt
Created September 12, 2011 07:47
gcc-4.6 -v -x c++ -fsyntax-only - < /dev/null 2> stderr.txt
Using built-in specs.
COLLECT_GCC=gcc-4.6
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.6.0/gcc/libexec/gcc/x86_64-apple-darwin10.7.0/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10.7.0
Configured with: ../configure --enable-languages=c,c++,objc --prefix=/usr/local/Cellar/gcc/4.6.0/gcc --datarootdir=/usr/local/Cellar/gcc/4.6.0/share --bindir=/usr/local/Cellar/gcc/4.6.0/bin --program-suffix=-4.6 --with-gmp=/usr/local/Cellar/gmp/5.0.1 --with-mpfr=/usr/local/Cellar/mpfr/3.0.1 --with-mpc=/usr/local/Cellar/libmpc/0.9 --with-system-zlib --enable-stage1-checking --disable-lto --disable-nls
Thread model: posix
gcc version 4.6.0 (GCC)
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.8' '-v' '-fsyntax-only' '-mtune=core2'
/usr/local/Cellar/gcc/4.6.0/gcc/libexec/gcc/x86_64-apple-darwin10.7.0/4.6.0/cc1plus -quiet -v -D__DYNAMIC__ - -fPIC -quiet -dumpbase - -mmacosx-version-min=10.6.8 -mtune=core2 -auxbase - -version -fsyntax-only -o /dev/null
GNU C++ (GCC) version 4.6.0 (x86_64-apple-darwin10.7.0)
@pyrtsa
pyrtsa / gist:1210862
Created September 12, 2011 08:49
cmake .. -DCMAKE_C_COMPILER=gcc-4.6 -DCMAKE_CXX_COMPILER=g++-4.6 -DCMAKE_BUILD_TYPE=Release
/path/to/nt2/build $ cmake .. -DCMAKE_C_COMPILER=gcc-4.6 -DCMAKE_CXX_COMPILER=g++-4.6 -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/gcc-4.6
-- Check for working C compiler: /usr/local/bin/gcc-4.6 -- works
-- Detecting C compiler ABI info
@pyrtsa
pyrtsa / gist:1285258
Created October 13, 2011 19:30
iterable(x)
def iterable(x):
"""Check whether x supports iteration"""
# originally implemented in NumPy, http://bit.ly/mSbVjo
try: iter(x)
except: return False
return True
@pyrtsa
pyrtsa / gist:1285350
Created October 13, 2011 20:06
mapping(x)
def mapping(x):
"""Check whether x is a mapping type (e.g. dict)"""
import sys
if 'numpy' in sys.modules:
try:
from numpy import ndarray
if isinstance(x, ndarray): return False # nasty special case
except ImportError:
pass
methods = ['__contains__', '__getitem__', 'items', 'iteritems']
@pyrtsa
pyrtsa / gist:1285366
Created October 13, 2011 20:11
isstring(x)
def isstring(x):
"""Check whether x is a string (i.e. inherits basestring)"""
return isinstance(x, basestring)
@pyrtsa
pyrtsa / gist:1285407
Created October 13, 2011 20:24
prod(iterable)
def prod(iterable):
"""Multiply elements of the iterable from left to right"""
import operator
end, it = object(), iter(iterable)
first = next(it, end)
return reduce(operator.mul, it, first) if first is not end else 1
@pyrtsa
pyrtsa / gist:1285415
Created October 13, 2011 20:27
mean(iterable)
def mean(iterable):
"""Find the mean value of the sequence (0 if empty). Consumes generators"""
if hasattr(iterable, '__len__'):
n = len(iterable)
return sum(iterable) / float(n) if n > 0 else 0.0
else:
sentinel, iterable = object(), iter(iterable)
n, s = 1, next(iterable, sentinel)
if s is sentinel: return 0.0
for x in iterable: n,s = n+1, s+x