Skip to content

Instantly share code, notes, and snippets.

Lev E. Givon lebedov

Block or report user

Report or block lebedov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lebedov
lebedov / sshtunnel.sh
Created Feb 24, 2014
Functions for managing ssh tunnels in bash
View sshtunnel.sh
#!/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 Mar 23, 2014
torque submit filter that sets CUDA_VISIBLE_DEVICES based on specified number of GPUs.
View filter.py
#!/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 Apr 11, 2014
Automatically create and submit Torque job script with specified commands to qsub.
View qwrap.py
#!/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 Jul 15, 2014
How to synchronize ZeroMQ routers and dealers
View zmq_router_dealer_sync.py
#!/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 Jul 21, 2014
Decorator for profiling functions.
View prof_dec.py
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 / msgpack_pandas_attrib.py
Created Jul 23, 2014
Serialize/unserialize a class with a pandas data structure attribute using msgpack.
View msgpack_pandas_attrib.py
#!/usr/bin/env python
"""
Serialize/unserialize a class with a pandas data structure attribute using msgpack.
"""
import msgpack
import numpy as np
import pandas as pd
@lebedov
lebedov / func_ptr_fused.pyx
Created Jul 29, 2014
How to use function pointers with fused types in Cython
View func_ptr_fused.pyx
# 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 Aug 29, 2015
Demo of how to write a decorator with optional arguments.
View decorate_with_args.py
#!/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 Aug 13, 2014
Demo of how to write a property decorator with optional arguments.
View decorate_property_with_args.py
#!/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 Sep 10, 2014
Nonblocking file logging handler using ZeroMQ.
View nbfilehandler.py
#!/usr/bin/env python
"""
Nonblocking file logging handler using ZeroMQ.
"""
import atexit
import collections
import logging
import multiprocessing as mp
You can’t perform that action at this time.