Even more bullsh*t

This commit is contained in:
madmaurice 2014-11-04 13:06:32 +01:00
parent 71c1288c1d
commit 09ac2aecbd
7 changed files with 166 additions and 0 deletions

25
benchmark.py Normal file
View file

@ -0,0 +1,25 @@
import gc
import timeit
import time
class Timer:
def __init__(self, timer=None, disable_gc=False, verbose=True):
if timer is None:
timer = timeit.default_timer
self.timer = timer
self.disable_gc = disable_gc
self.verbose = verbose
self.start = self.end = self.interval = None
def __enter__(self):
if self.disable_gc:
self.gc_state = gc.isenabled()
gc.disable()
self.start = self.timer()
return self
def __exit__(self, *args):
self.end = self.timer()
if self.disable_gc and self.gc_state:
gc.enable()
self.interval = self.end - self.start
if self.verbose:
print('time taken: %f seconds' % self.interval)

4
bin2hex.py Normal file
View file

@ -0,0 +1,4 @@
while True:
r = int(input(">"),2)
print("%X" % r)

75
chunksizer.py Normal file
View file

@ -0,0 +1,75 @@
# -*- coding: cp1252 -*-
import Tkinter, tkFileDialog, tkMessageBox, os
def getsize(directory):
total_size = 0
for dirpath, dirnames, filenames in os.walk(directory):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
def calcChunkCount(chunksizeKB, total_size):
chunksizeB = chunksizeKB * 1024
chunkcount = total_size / chunksizeB
return chunkcount
def chunklabel(size, dirsize, parent):
chunklabel = Tkinter.Label(parent, text=str(size)+"KB: " + str(calcChunkCount(size, dirsize)))
return chunklabel
def choosedir():
path = tkFileDialog.askdirectory()
dirsize = getsize(path)
mainFrame = Tkinter.LabelFrame(window, text=path)
mainFrame.pack()
resultsFrame = Tkinter.Frame(mainFrame)
resultsFrame.pack()
infoFrame = Tkinter.LabelFrame(resultsFrame, text="Infos")
labPath = Tkinter.Label(infoFrame, text="Verzeichnis: " + path )
labSize = Tkinter.Label(infoFrame, text="Groesse: " + str(dirsize/1024) + "KB" )
labPath.pack()
labSize.pack()
infoFrame.pack(side="left")
chunksizeFrame = Tkinter.LabelFrame(resultsFrame, text="Chunk-Counts")
chunk64K = chunklabel(64, dirsize, chunksizeFrame)
chunk64K.pack()
chunk128K = chunklabel(128, dirsize, chunksizeFrame)
chunk128K.pack()
chunk256K = chunklabel(256, dirsize, chunksizeFrame)
chunk256K.pack()
chunk512K = chunklabel(512, dirsize, chunksizeFrame)
chunk512K.pack()
chunk1024K = chunklabel(1024, dirsize, chunksizeFrame)
chunk1024K.pack()
chunk2048K = chunklabel(2048, dirsize, chunksizeFrame)
chunk2048K.pack()
chunk4096K = chunklabel(4096, dirsize, chunksizeFrame)
chunk4096K.pack()
chunk8192K = chunklabel(8192, dirsize, chunksizeFrame)
chunk8192K.pack()
chunksizeFrame.pack(side="right")
buttonFrame2 = Tkinter.Frame(mainFrame)
closeBtn = Tkinter.Button(buttonFrame2, text="schliessen", command=mainFrame.destroy)
closeBtn.pack()
buttonFrame2.pack()
window = Tkinter.Tk()
window.title("Torrent Chunksize Calculator by BSOD")
window.minsize(width=400, height=200)
l = Tkinter.Label(window, text="dieses Tool soll euch beim Torrents erstellen helfen :)")
l.pack()
buttonFrame = Tkinter.Frame()
choosedirBtn = Tkinter.Button(buttonFrame, text="neues Verzeichnis für Berechnung wählen", command=choosedir)
choosedirBtn.pack(side="left")
quitBtn = Tkinter.Button(buttonFrame, text="Beenden", command=window.destroy)
quitBtn.pack(side="right")
buttonFrame.pack()
window.mainloop()

20
ds.py Normal file
View file

@ -0,0 +1,20 @@
class Time:
def __init__(self, hour, minute):
self.hour = hour
self.minute = minute
def addminutes(self,dminutes):
self.minute += dminutes
self.hour += int(self.minute / 60)
self.minute = self.minute % 60
def __str__(self):
return "%02d:%02d" % (self.hour,self.minute)
t = Time(7,30)
for i in range(8):
print("%d.DS: %s" % (i+1,str(t)))
t.addminutes(90+20)

21
fib.py Normal file
View file

@ -0,0 +1,21 @@
from functools import lru_cache
@lru_cache(maxsize=1000)
def fibc(n):
if n < 2:
return 1
else:
return fibc(n-1)+fibc(n-2)
def fibs(n):
i = 1
a = 1
b = 1
while i < n:
(a,b) = (b,a+b)
i+=1
return b
print(fibc(1000))
print(fibs(1000))

16
gcd.py Normal file
View file

@ -0,0 +1,16 @@
import benchmark
import random
def gcd(a,b):
while a != b:
if a > b:
a = a - b
else:
b = b - a
return a
with benchmark.Timer():
for i in range(10000):
gcd(random.randint(2,10000), random.randint(2,10000))

5
test.py Normal file
View file

@ -0,0 +1,5 @@
for x in [1]:
print(x)
else:
print("List empty")