Skip to content

Instantly share code, notes, and snippets.

@srossross
srossross / popen_gevent.py
Last active October 15, 2015 18:05
Async popen with gevent (Works in Python3)
from gevent.monkey import patch_all; patch_all()
import subprocess as sp
import gevent
import time
import io
import sys
from contextlib import contextmanager
class read_with_timeout:
0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/Users/sean/anaconda/envs/_build/bin/npm',
1 verbose cli 'install',
1 verbose cli 'git://github.com/srossross/node-authenticate-pam.git' ]
2 info using npm@2.7.3
3 info using node@v0.10.35
4 warn package.json wnext@0.0.0 No repository field.
5 silly cache add args [ 'git://github.com/srossross/node-authenticate-pam.git', null ]
6 verbose cache add spec git://github.com/srossross/node-authenticate-pam.git
## psudo code for conda create
conda = Conda()
print conda.cache_locations
print conda.default_cache_location
print conda.env_locations # list of places to search for environemtns
print conda.default_env_location # environment prefix to install new envs
@srossross
srossross / gist:270bdc77c247ad2567ca
Created September 2, 2014 18:42
Wait for windows fd
import ctypes, os, signal, select
def wait_for_read_windows(fd):
import msvcrt
from ctypes import wintypes
WaitForMultipleObjects = ctypes.windll.kernel32.WaitForMultipleObjects
WaitForMultipleObjects.argtypes = [wintypes.DWORD,
ctypes.POINTER(wintypes.HANDLE),
@srossross
srossross / pysubl.sh
Created March 24, 2014 19:43
Function to open python module in sublime text editor
pysubl (){
### Function to open python module in sublime text editor
### Usage example: pysubl this
xpyc=`python -c "import sys; stdout = sys.stdout; sys.stdout = sys.stderr; import $1; stdout.write($1.__file__)"`
if [ "$xpyc" == "" ]; then
echo "Python module $1 not found"
elif [[ $xpyc == *__init__.py* ]]; then
@srossross
srossross / gist:9282214
Created February 28, 2014 23:34
publish error npm v1.4.4
mr_chomps:express-blueprints sean$ npm publish
npm http PUT https://registry.npmjs.org/express-blueprints
npm http 403 https://registry.npmjs.org/express-blueprints
npm ERR! publish Failed PUT 403
npm ERR! Error: forbidden Cannot replace previously published version: 0.0.1: express-blueprints
npm ERR! at RegClient.<anonymous> (/Users/sean/anaconda/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:237:14)
npm ERR! at Request.self.callback (/Users/sean/anaconda/lib/node_modules/npm/node_modules/request/request.js:123:22)
npm ERR! at Request.EventEmitter.emit (events.js:98:17)
npm ERR! at Request.<anonymous> (/Users/sean/anaconda/lib/node_modules/npm/node_modules/request/request.js:893:14)
npm ERR! at Request.EventEmitter.emit (events.js:117:20)
@srossross
srossross / gist:9282190
Created February 28, 2014 23:32
publish error npm v1.3.8
mr_chomps:express-blueprints sean$ npm publish
npm http PUT https://registry.npmjs.org/express-blueprints
npm http 503 https://registry.npmjs.org/express-blueprints
npm ERR! registry error parsing json
npm http PUT https://registry.npmjs.org/express-blueprints
^Cmr_chomps:express-blueprints sean$ npm publish
npm http PUT https://registry.npmjs.org/express-blueprints
npm http 201 https://registry.npmjs.org/express-blueprints
npm http GET https://registry.npmjs.org/express-blueprints
npm http 200 https://registry.npmjs.org/express-blueprints
Build 14.0 Sumitted id:530cbd35f53f2a3ebc615bb4
This build is in the build queue ...
... Build popped off queue
Start build binstar/binstar 14.0 -- id:530cbd35f53f2a3ebc615bb4
Start build
Setting engine
conda create -n install --quiet --yes python=2
Package plan for installation in environment /opt/anaconda/envs/install:
This build is in the build queue ...
... Build popped off queue
Start build sean/libdynd_build_test 1.0 -- id:52f3ce1cf53f2a4d0d9fc031
Start build
Setting engine
conda install --quiet --yes python=2
# All requested packages already installed.
# packages in environment at /opt/anaconda:
#
python 2.7.6 1
@srossross
srossross / redirect.sh
Last active December 19, 2015 05:09
IP Table eedirect
sudo iptables -t nat -F
sudo iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT --to-ports 8080
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080