Skip to content

Instantly share code, notes, and snippets.

View lebedov's full-sized avatar

Lev E. Givon lebedov

View GitHub Profile
@lebedov
lebedov / sshtunnel.sh
Created February 24, 2014 14:10
Functions for managing ssh tunnels in bash
#!/bin/bash
# Add these functions to your ~/.bashrc file.
function mktunnel {
if [[ $* == '' ]] || [[ $1 == '-h' ]]; then
echo 'Usage: mktunnel LOCALPORT REMOTEPORT REMOTEHOST'
else
ssh -fCNL $1:localhost:$2 $3;
fi
@lebedov
lebedov / filter.py
Created March 23, 2014 19:39
torque submit filter that sets CUDA_VISIBLE_DEVICES based on specified number of GPUs.
#!/usr/bin/python2.7
"""
torque submit filter that automatically sets CUDA_VISIBLE_DEVICES
based upon the number of GPUs requested in a job.
Notes
-----
Assumes that /var/spool/torque/filters/trqgpu.py is available.
"""
@lebedov
lebedov / qwrap.py
Created April 11, 2014 17:32
Automatically create and submit Torque job script with specified commands to qsub.
#!/usr/bin/env python
"""
Automatically create and submit Torque job script with specified commands to qsub.
"""
import argparse
import os
import pwd
import tempfile
@lebedov
lebedov / zmq_router_dealer_sync.py
Created July 15, 2014 17:35
How to synchronize ZeroMQ routers and dealers
#!/usr/bin/env python
"""
How to synchronize ZeroMQ routers and dealers.
"""
import multiprocessing as mp
import zmq
IPC_PATH = 'ipc://zmq_router_dealer_sync'
@lebedov
lebedov / prof_dec.py
Created July 21, 2014 15:01
Decorator for profiling functions.
import cProfile
import functools
def do_cprofile(*dec_args):
"""
Decorator for profiling functions.
If a file name is passed to the decorator as an argument, profiling data
will be written to that file; otherwise, it will be displayed on the screen.
"""
@lebedov
lebedov / func_ptr_fused.pyx
Created July 29, 2014 23:20
How to use function pointers with fused types in Cython
# Demo of how to use function pointers with fused types in Cython:
cimport cython
ctypedef fused fused_type:
cython.double
cython.longlong
cdef double func0(double x, double y):
return x+y
@lebedov
lebedov / decorate_with_args.py
Last active August 29, 2015 14:05
Demo of how to write a decorator with optional arguments.
#!/usr/bin/env python
"""
Demo of how to write a decorator with optional arguments.
"""
import functools
import inspect
def mydec(*dec_args, **dec_kwargs):
@lebedov
lebedov / decorate_property_with_args.py
Created August 13, 2014 00:09
Demo of how to write a property decorator with optional arguments.
#!/usr/bin/env python
"""
Demo of how to write a property decorator with optional arguments.
"""
import functools
import inspect
def myprop(*dec_args):
@lebedov
lebedov / nbfilehandler.py
Created September 10, 2014 22:24
Nonblocking file logging handler using ZeroMQ.
#!/usr/bin/env python
"""
Nonblocking file logging handler using ZeroMQ.
"""
import atexit
import collections
import logging
import multiprocessing as mp
@lebedov
lebedov / twiggy_exception_handler.py
Created September 14, 2014 17:58
Exception handler that outputs exception data to twiggy logger.
#!/usr/bin/env python
"""
Exception handler that outputs exception data to twiggy logger.
"""
import re
import sys
import traceback
import twiggy