This file contains 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
"""easy string compression, based on the old compressed bitmap""" | |
class listComp(object): | |
@staticmethod | |
def compactLst(lstIn, lastOne = ''): | |
if lastOne == '': | |
listComp.myList = [] | |
if lstIn[0] != lastOne: | |
#start a new acumulator |
This file contains 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
class myStr(str): | |
def pogoCase(self,jumpInt): | |
return "".join([myCar.lower() if myInt % jumpInt else myCar.upper() for myInt, myCar in enumerate(self)]) | |
thisThing = myStr("The quick brown fox jumped over the lazy dog.") | |
print thisThing | |
print thisThing.pogoCase(3) | |
print thisThing.pogoCase(2) | |
print type(thisThing) is str |
This file contains 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/env python | |
from Queue import Queue | |
from threading import Thread | |
from urllib2 import urlopen | |
from time import time | |
from random import shuffle | |
hosts = ["yahoo.com", "google.com", "amazon.com","ibm.com", "apple.com", | |
"bbc.co.uk", "npr.org", "cnn.com", "ubuntu.com", "soundcloud.com", | |
"bogus.url",'ebay.com','linux.org','osuosl.org','renren.com','alibaba.com', |
This file contains 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
listA = [1,2,3,4] #listA now holds a refrence to a list object | |
listB = listA #a refrence to the refrence held by listA | |
listC = list(listA) #a new copy of the object reffered to in the refrence held by listA | |
listA.append('dog') #update the object reffered to in the refrence held by listA | |
print(listB) #a refrence to the refrence held by listA -> the object reffered to in the refrence held by listA | |
print(listC) #the copy we made before updating is, of course, unchanged |
This file contains 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
class dictWrap(object): | |
def __init__(self, dictIn = False, fnXform = False): | |
self.noneVal = None | |
if dictIn: | |
if fnXform: | |
dictIn = dict((k,fnXform(v)) for k,v in dictIn.items()) | |
self.__dict__.update(dictIn) | |
def __getattribute__(self, attr): | |
try: | |
return object.__getattribute__(self, attr) |
This file contains 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
class ConfigInfo(object): | |
rootDir = "/home/jpmcgrady/workspace" | |
subDir = "src" | |
class GrepDict(object): | |
def __init__(self, projName, findMe): | |
self.config = ConfigInfo | |
self.projName = projName | |
self.findMe = findMe |
This file contains 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
def main(): | |
lstIn = "dog,horse,cat,trouser,shark,artichoke,constantine,Christmas,Antartica,Ninja,Sanitizer".split(",") | |
lst1 = sorted(lstIn) #looks ok, but sorts on ord(c) | |
print lst1 #uppers before lowers | |
lst2 = sorted(lstIn, key=lambda x: x.lower()) #does a case insenstive sort | |
print lst2 #what you'd expect from an alphabetic sort | |
lstIn.sort(key=lambda x: (len(x),lst2.index(x))) #to sort on n vars, return an n-tupple | |
print lstIn #list sorted by length of word then alphabet |
This file contains 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
import time | |
class myNote(object): | |
def __init__(self, myInt): | |
self.name = myInt | |
self.provided_time = None | |
self.mytime = time.time() | |
#we're going to consider every thing above here imported |
This file contains 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/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 |
This file contains 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
# -*- 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__])) |
OlderNewer