Skip to content

Instantly share code, notes, and snippets.

View ashwin's full-sized avatar

Ashwin Nanjappa ashwin

View GitHub Profile
@ashwin
ashwin / ReturnNone.py
Created May 4, 2012 14:31
None returned by function in Python
def foo( x ):
print( x )
y = foo( 10 )
if y is None:
print( "foo returned None" ) # Printed
else:
print( "No, it did not!" )
@ashwin
ashwin / Profile.py
Created May 5, 2012 05:20
Profiling in Python
# Assuming we want to profile function doMain()
import cProfile
cProfile.run( "doMain( a, b )" )
@ashwin
ashwin / CudaErrorCheck.cu
Created May 10, 2012 11:16
CUDA Error Checking Functions
// Define this to turn on error checking
#define CUDA_ERROR_CHECK
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ )
inline void __cudaSafeCall( cudaError err, const char *file, const int line )
{
#ifdef CUDA_ERROR_CHECK
if ( cudaSuccess != err )
@ashwin
ashwin / ObjectSize.py
Created May 10, 2012 13:57
Size of objects in Python
# Tried with Python 3.2.2 64-bit
import sys
a = None
sys.getsizeof( a ) # 16
a = 0
sys.getsizeof( a ) # 24
a = 12345678
@ashwin
ashwin / gist:2669815
Created May 13, 2012 00:15
Reverse page order of PDF using PDFTK
# Assume in.pdf has 20 pages
pdftk in.pdf cat 20-1 output out.pdf
@ashwin
ashwin / Rot13Python2.py
Created May 14, 2012 11:39
ROT13 in Python 2.x
s = "Hello"
os = s.encode( "rot13" )
print( os ) # "Uryyb"
@ashwin
ashwin / Rot13Python3.py
Created May 14, 2012 11:40
ROT13 in Python 3.x
import codecs
s = "Hello"
enc = codecs.getencoder( "rot-13" )
os = enc( s )[0]
print( os ) # "Uryyb"
@ashwin
ashwin / SearchFiles.ps1
Created May 26, 2012 05:55
Search text in files using PowerShell
### Search "foo_bar" recursively in all files in current directory
# Verbose
Get-ChildItem -Recurse | Select-String "foo_bar"
# Short
ls -r | Select-String "foo_bar"
@ashwin
ashwin / fciv.bat
Created May 29, 2012 03:54
Verify MD5 or SHA-1 hash on Windows
REM Generate MD5 hash
fciv foobar.iso
REM Generate SHA-1 hash
fciv -sha1 foobar.iso
@ashwin
ashwin / FloatAsInt.cu
Created June 7, 2012 07:19
Reinterpret float as int in CUDA
// 1. Using union
__device__ int floatAsInt( float fval )
{
union FloatInt {
float f;
int i;
};
FloatInt fi;
fi.f = fval;