Skip to content

Instantly share code, notes, and snippets.

View thelahunginjeet's full-sized avatar

Kevin Brown thelahunginjeet

View GitHub Profile
@thelahunginjeet
thelahunginjeet / scripting-fish
Last active August 29, 2015 14:02
example fish shell script that chews through multiple .cfg files for a utility that requires them
for f in *.cfg
echo 'Working on' $f
set out (basename $f .cfg).out
set err (basename $f .cfg).err
<myprog> --config=$f >$out ^$err
python process_output.py -input=$out -output=results.dat
end
@thelahunginjeet
thelahunginjeet / timer.py
Created July 25, 2014 18:32
simple python timer
import time
class Timer:
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self,*args):
self.end = time.clock()
self.interval = self.end - self.start
@thelahunginjeet
thelahunginjeet / timeparse.py
Created June 26, 2015 15:52
Simple translator between 'mm/dd/yyyy hh:mm:ss' object and python datetime object.
import datetime as dt
def date_parser(datestring):
"""
Accepts a datestring in the format:
mm/dd/yyyy hh:mm:ss
and returns a python datetime object with all relevant fields properly set.
"""
mdy = [int(x) for x in datestring.split(' ')[0].split('/')]
hms = [int(x) for x in datestring.split(' ')[1].split(':')]
@thelahunginjeet
thelahunginjeet / cleanwhite.py
Created July 21, 2015 18:25
python idiom for cleaning up lines with inconsistent whitespace
def clean_whitespace(s):
'''
Returns a version of s with no leading or trailing whitespace/\t/\n and one whitespace
between each whitespace-separated token in the string.
Ex: ' a b c d \n' -> 'a b c d'
'''
return ' '.join(l.strip().split())
@thelahunginjeet
thelahunginjeet / profile.py
Created July 30, 2015 15:16
example usage of cProfile module
import pstats,cProfile
import my_function
cProfile.runctx("my_function(a,b)",globals(),locals(),"Profile.prof")
s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
@thelahunginjeet
thelahunginjeet / recdel.sh
Created July 11, 2019 15:06
recursive file delete
find . -type f -name 'myfiles.*' -delete