This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo( x ): | |
print( x ) | |
y = foo( 10 ) | |
if y is None: | |
print( "foo returned None" ) # Printed | |
else: | |
print( "No, it did not!" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assuming we want to profile function doMain() | |
import cProfile | |
cProfile.run( "doMain( a, b )" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tried with Python 3.2.2 64-bit | |
import sys | |
a = None | |
sys.getsizeof( a ) # 16 | |
a = 0 | |
sys.getsizeof( a ) # 24 | |
a = 12345678 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume in.pdf has 20 pages | |
pdftk in.pdf cat 20-1 output out.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = "Hello" | |
os = s.encode( "rot13" ) | |
print( os ) # "Uryyb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs | |
s = "Hello" | |
enc = codecs.getencoder( "rot-13" ) | |
os = enc( s )[0] | |
print( os ) # "Uryyb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM Generate MD5 hash | |
fciv foobar.iso | |
REM Generate SHA-1 hash | |
fciv -sha1 foobar.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Using union | |
__device__ int floatAsInt( float fval ) | |
{ | |
union FloatInt { | |
float f; | |
int i; | |
}; | |
FloatInt fi; | |
fi.f = fval; |