Skip to content

Instantly share code, notes, and snippets.

View natekupp's full-sized avatar

Nate Kupp natekupp

View GitHub Profile
@natekupp
natekupp / gist:1010281
Created June 6, 2011 13:43
Use Case for Python Decorators
def timeout(seconds_before_timeout):
def decorate(f):
def handler(signum, frame):
raise TimeoutError()
def new_f(*args, **kwargs):
old = signal.signal(signal.SIGALRM, handler)
signal.alarm(seconds_before_timeout)
try:
result = f(*args, **kwargs)
finally:
@natekupp
natekupp / gist:1072750
Created July 8, 2011 20:37
Identifying the list indices of duplicate elements in a list
dups = [x for x in myList if myList.count(x) > 1]
indices = [i for i, x in enumerate(myList) if x in dups]
@natekupp
natekupp / example.py
Created September 26, 2015 19:08
impyla+multiprocessing crash example
import multiprocessing
import impala.dbapi
class Impala(obect):
def __init__(self, host, database, port, username, password, lock=None):
self.conn = impala.dbapi.connect(host=host,
port=port,
database=database,
user=username,
password=password,
@natekupp
natekupp / gist:2047390
Created March 15, 2012 22:33
FFX Performance Test
def buildmodel():
EPS = 0.001
data = pandas.read_csv('iris.csv')
xtrain = data.ix[:50,0:2]
xtest = data.ix[51:100,0:2]
ytrain = data.ix[:50,2]
ytest = data.ix[51:100,2]
# Use pandas.DataFrame
models = ffx.run(xtrain, ytrain, xtest, ytest)
@natekupp
natekupp / gist:2090168
Created March 19, 2012 01:55
Installation for py2cairo on OSX Lion 10.7
python waf clean
export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/lib:$LD_LIBRARY_PATH
export LINKFLAGS='-search_dylibs_first -L /Library/Frameworks/Python.framework/Versions/2.7/lib/'
export ARCHFLAGS='-arch x86_64'
export CC=/usr/bin/gcc-4.2
export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/1.10.2/lib/pkgconfig/
python waf configure --prefix=$PYTHONPATH
@natekupp
natekupp / gist:2628399
Created May 7, 2012 15:26
running node.js and simple HTTP server
try:
# start http server
self.p_http = subprocess.Popen(
["python", "-m", "SimpleHTTPServer"],
preexec_fn = sigint_replace,
cwd = self.resource_dir
)
# start node.js server
self.p_node = subprocess.Popen(
@natekupp
natekupp / gist:2954743
Created June 19, 2012 15:21
numpy_imshow
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Terminal visualization of 2D numpy arrays
# Copyright (c) 2009 Nicolas P. Rougier
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
class DataProcSparkOperator(BaseOperator):
"""
Start a Cloud DataProc cluster, run a Spark job, then shut down the Spark cluster.
"""
template_fields = ['arguments']
ui_color = '#0273d4'
@apply_defaults
def __init__(
self,
@natekupp
natekupp / dask_exception.py
Last active May 16, 2019 04:18
Minimal repro example of Dask exception
import dask
import dask.distributed
from tornado import gen
PUBSUB_NAME = 'test'
class Task:
def __init__(self, key, num, upstream_tasks):
# example_airflow.py
from dagster import lambda_solid, pipeline
@lambda_solid
def hello_world():
return "hello, world"
@pipeline
def basic_pipeline():
hello_world()