Skip to content

Instantly share code, notes, and snippets.

View lebedov's full-sized avatar

Lev E. Givon lebedov

View GitHub Profile
@lebedov
lebedov / mpi4py_self_spawn_multiple.py
Created May 13, 2015 21:18
How to pass an environmental variable with different values to spawned processes using MPI4PY.
#!/usr/bin/env python
"""
Self-launching MPI4PY script that uses spawning and sets an environmental
variable to different values for each of the launched script instances..
Notes
-----
Requires an MPI implementation that supports dynamic process management.
"""
@lebedov
lebedov / dotpvc
Last active December 3, 2015 18:24
Script for continuously previewing graphviz dot files using dot2tex.
#!/bin/bash
# Script for continuously previewing graphviz dot files using dot2tex.
# Copyright (c) 2015, Lev Givon
# All rights reserved
# Distributed under the terms of the BSD license:
# http://www.opensource.org/licenses/bsd-license
SCRIPT_NAME=`basename $0`
@lebedov
lebedov / google_finance_intraday.py
Last active February 20, 2024 09:44
Retrieve intraday stock data from Google Finance.
#!/usr/bin/env python
"""
Retrieve intraday stock data from Google Finance.
"""
import csv
import datetime
import re
import pandas as pd
@lebedov
lebedov / queue_group.py
Created March 11, 2015 19:50
Class for managing a group of queues with per-queue push and simultaneous pop
#!/usr/bin/env python
"""
Group of queues; data can be pushed/popped into each queue separately, but one
can also pop off values from all of the queues simultaneously.
+-------+
queue a: in -> | |A|B|
+-------+ out -> (B,C)
queue b: in -> | |C|
@lebedov
lebedov / mpi4py_spawn_twiggy.py
Created March 4, 2015 15:32
How to use twiggy for logging in both parent and MPI-spawned processes.
#!/usr/bin/bin python
"""
How to use twiggy for logging in both parent and MPI-spawned processes.
"""
import sys
# Need to use dill to serialize the twiggy emitters because pickle can't handle
# them:
@lebedov
lebedov / allglobalvars.py
Last active August 29, 2015 14:16
How to find globals accessed by a Python object.
#!/usr/bin/env python
"""
How to find globals accessed by a Python object.
"""
import inspect
import numpy as np
@lebedov
lebedov / indexer_attrib_demo.py
Created March 4, 2015 05:28
How to create a class with an attribute that provides its own __getitem__() method.
#!/usr/bin/env python
"""
How to create a class with an attribute that provides its own __getitem__()
method (similar to pandas.DataFrame.ix).
"""
class Indexer(object):
def __init__(self, data):
if not hasattr(data, '__getitem__') or not hasattr(data, '__setitem__'):
@lebedov
lebedov / ml_syn.py
Created March 3, 2015 21:59
Morris-Lecar neurons connected by a conductance-based synapse.
#!/usr/bin/env python
"""
Morris-Lecar neurons connected by a conductance-based synapse.
"""
import numpy as np
import matplotlib
matplotlib.use('agg')
@lebedov
lebedov / ml.py
Created March 3, 2015 21:57
Morris-Lecar neuron model implemented using Brian.
#!/usr/bin/env python
"""
Morris-Lecar neuron model implemented using Brian.
"""
import numpy as np
import matplotlib
matplotlib.use('agg')
@lebedov
lebedov / ipython_config.py
Created January 29, 2015 18:19
Show virtualenv or conda environment in IPython prompt
# Put this in your IPython profile configuration, e.g., ~/.ipython/profile_default/ipython_config.py
import os
extra = ''
if os.environ.has_key('VIRTUAL_ENV'):
v = os.path.basename(os.environ['VIRTUAL_ENV'])
extra += '<%s> ' % v
if os.environ.has_key('CONDA_DEFAULT_ENV'):
extra += '[%s] ' % os.environ['CONDA_DEFAULT_ENV']