Skip to content

Instantly share code, notes, and snippets.

@capttwinky
capttwinky / hfonottest.py
Created August 13, 2012 21:24
test conditions for HFO object
with openHDFS('/my/path/filename','w') as HFO:
HFO.write('string A')
### on inpect /my/path/filename == 'string A'
with openHDFS('/my/path/filename','w') as HFO:
HFO.write('string B')
### on inpect /my/path/filename == 'string B'
with openHDFS('/my/path/filename','a') as HFO:
@capttwinky
capttwinky / getout.py
Created August 13, 2012 20:28
shell command to string
import shlex
import subprocess
from lib_joel import fnprint
class sp_error(StandardError):
pass
def get_out(cmd):
'''execute shell command in subprocess, return result'''
import os
import sys
def findmod(targetMod):
lstOut = []
for myDir in sys.path:
if os.path.isdir(myDir) and "%s.py"%targetMod in os.listdir(myDir):
lstOut.append(myDir)
return lstOut
@capttwinky
capttwinky / procparse.py
Created March 20, 2012 22:07
beginnings of a /proc fs -> serialized object script
import re
from collections import namedtuple
from itertools import islice as itslice
def sdict(ntpl, keys, defval = None):
return {k: getattr(ntpl, k, defval) for k in keys}
class ParseHolder(object):
attribs = {}
def __init__(self):
#include <stdio.h>
#include <string.h>
int main(){int myi=1;char stout[26];char stmid[2];while(myi<=13){sprintf(stmid,"%02X",myi*2);strcat(stout,stmid);myi++;}printf("%s\n",stout);return 0;}
@capttwinky
capttwinky / fncObject.py
Created January 27, 2012 23:06
How OO is python? ... it's objects, all the way down
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def myFunction(**kwargs):
return attrSetter(myFunction,**kwargs)
def attrSetter(target,**kwargs):
for k,v in kwargs.iteritems():
setattr(target,k,v)
return True
@capttwinky
capttwinky / gitGc.py
Created October 21, 2011 23:52
run git gc on all your dirs!
import sys
import os
from subprocess import Popen, PIPE
myWorkDir = '/home/jpmcgrady/workspace'
def runGc(dirNameIn):
os.chdir(dirNameIn)
try:
output = Popen(["git", "gc"], stdout=PIPE).communicate()[0]
@capttwinky
capttwinky / rplparse.py
Created September 28, 2011 20:59
an rplish expression parser
# -*- coding: latin-1 -*-
from decimal import Decimal
import re
import operator as op
d = lambda n: Decimal(n)
lstFns=['+','-','*','/']
dictFns=dict(zip(lstFns,[op.__add__,op.__sub__,op.__mul__,op.__truediv__]))
@capttwinky
capttwinky / threadping.py
Created September 28, 2011 19:46
threaded pinger
#!/usr/bin/env python
from Queue import Queue
from threading import Thread
from time import time, sleep
from subprocess import Popen, PIPE
class HostRangeGenerator(object):
def __init__(self, lstIn):
self.myList = [range(256) if x =="*" else [x] if hasattr(x,'real') else x for x in lstIn]
self.A, self.B, self.C, self.D = self.myList