Created
July 1, 2011 19:21
-
-
Save jl2/1059206 to your computer and use it in GitHub Desktop.
.pythonrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import sys | |
import math | |
import random | |
from datetime import datetime | |
def wget(url): | |
import urllib.request | |
import urllib.parse | |
tu = urllib.parse.urlparse(url) | |
if tu.scheme == '': | |
tu = 'http://' + tu.geturl() | |
else: | |
tu = tu.geturl() | |
with urllib.request.urlopen(tu) as inf: | |
return inf.read() | |
def choice(*options): | |
return random.sample(options, 1)[0] | |
def showEnv(pat=None): | |
import re | |
rx = re.compile(".*") | |
if pat is not None: | |
rx = re.compile('.*' + pat + '.*', re.I) | |
for ev in os.environ: | |
if rx.match(ev): | |
print('{} : {}'.format(ev, os.environ[ev])) | |
def which_week(dstr=datetime.utcnow().strftime("%m/%d/%Y")): | |
that_date = datetime.strptime(dstr, "%m/%d/%Y") | |
return int(that_date.strftime("%W")) | |
def week_diff(dstr): | |
this_date = datetime.utcnow() | |
that_date = datetime.strptime(dstr, "%m/%d/%Y") | |
year_diff = that_date.year - this_date.year | |
this_week = int(this_date.strftime("%W")) | |
that_week = int(that_date.strftime("%W")) | |
return (that_week - this_week) + (year_diff * 52) | |
def week_to_date(wn): | |
this_year = datetime.utcnow().year | |
begin_date = datetime.strptime("{} {} {}".format(wn, 0, this_year), "%W %w %Y") | |
end_date = datetime.strptime("{} {} {}".format(wn+1, 0, this_year), "%W %w %Y") | |
return "{} - {}".format(begin_date.strftime("%m/%d/%Y"), | |
end_date.strftime("%m/%d/%Y")) | |
week_num = which_week | |
weeknum = which_week | |
weekNum = which_week | |
wn = which_week | |
def cd(nd='.'): | |
os.chdir(nd) | |
def ls(nd='.'): | |
return os.listdir(nd) | |
def wscb(): | |
import win32clipboard | |
win32clipboard.OpenClipboard(0) | |
txt = win32clipboard.GetClipboardData() | |
ntxt = txt.replace('/', '\\') | |
win32clipboard.EmptyClipboard() | |
win32clipboard.SetClipboardText(ntxt) | |
win32clipboard.CloseClipboard() | |
def in_box(bstr, pstr): | |
cbstr = bstr.replace(') - (', ' ') | |
cbstr = cbstr.replace('(','') | |
cbstr = cbstr.replace(',','') | |
cbstr = cbstr.replace(')', '') | |
x1,y1,z1,x2,y2,z2 = [float(x) for x in cbstr.split(' ')] | |
cpstr = pstr.replace(',', '') | |
px,py,pz = [float(x) for x in cpstr.split(' ')] | |
return (x1<=px<=x2 and | |
y1<=py<=y2 and | |
z1<=pz<=z2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment