page_grabber


Download managers can be pesky creatures with hard to use batch-downloading features. This is why Python is useful. This program has been used an modified so many times I’ve forgotten just when I programmed it. I’m going to settle with fall 2010-ish. import urllib.request,os url_part = "http://examplewebsite.com/" url_end = "page.php?number=%i" save_dir = "page/" for i […]

Posted in: Code by nsundin

mandelbrot


Graphs a Mandelbrot fractal. Coded August 2010. from PIL import Image def mandelbrot(x0, y0, maximum): Z = complex() C = complex(x0,y0) i = 0 while (Z.real**2 + Z.imag**2 <= 4.0 and i < maximum): Z = Z**2 + C i+=1 if i == maximum: #it is in the set return 255, 255, 255 else: #even […]

Posted in: Code by nsundin

point_gen_protractor


When you find yourself faced with a Pre-Calculus assignment that requires a protractor in radians, Python can help. This was something I whipped up in a few minutes to make my life a lot easier. Coded around winter 2011. import math for i in range(int(2*math.pi*10)+2): rad = float(i/10) print(rad," rad, deg:", round((rad*180)/math.pi), (rad*180)/math.pi)

Posted in: Code by nsundin

additive_hash


This is a little easy-to-code cipher I made for encrypting text. There are various issues with it, but it’s always fun to have ones own secret code. import hashlib def additive_encrypt(data, key): result = "" h = hashlib.md5() h.update(key.encode()) keyhash = str(h.hexdigest()) k_idx = 0 for byte in data: n = byte+int(keyhash[k_idx],16) if n > […]

Posted in: Code by nsundin

quizzer_vocab


This is a program I made to study for biology vocabulary tests. It’s useful for any kind of vocabulary test and it’s been helpful throughout high school. It reads a text file in the format: “word-this is the definition word2-this is the definition” import random list_of_stuff = [] f = open("material.txt") lines = f.readlines() for […]

Posted in: Code by nsundin

pi_calc


Two things that most people like: pie and pi. Many people also like Py(thon). Coded August 2010. #create PI, fresh from the oven i = 0 current_number = 0 current_denominator = 1 while i < 10000000: current_number+=(i/current_denominator) if current_denominator > 0: current_denominator = -current_denominator-2.0 else: current_denominator = -current_denominator+2.0 i+=1 print(abs(current_number*8))

Posted in: Code by nsundin

simple_compression2


The sequel to my first program “simple_compression.” Even more experimenting. Coded July 2010. import struct from PIL import Image import math def writeUnsignedInt(stream,v): stream.write(struct.pack(‘<I’, v)) def readUnsignedInt(stream): s = stream.read(4) p, = struct.unpack(‘<I’, s) return p def writeUnsignedShort(stream,v): stream.write(struct.pack(‘<H’, v)) def readUnsignedShort(stream): s = stream.read(2) p, = struct.unpack(‘<H’, s) return p def writeDouble(stream,v): stream.write(struct.pack(‘d’, v)) […]

Posted in: Code by nsundin

simple_compression


This program is my first dabbling in image compression. It turns out that storing pixel data as gradients isn’t any smaller than indexing. Anyway, it was fun novel idea I had been meaning to try for a while (coded July 2010). import struct from PIL import Image import math def writeUnsignedShort(stream,v): stream.write(struct.pack(‘<H’, v)) def readUnsignedShort(stream): […]

Posted in: Code by nsundin

internet_checker


Probably the most utilitarian piece of code I’ve ever written, this program, coded in July 2010 when I was having faulty internet problems. It repeatedly attempts to contact google.com and plays a sound when it is successful (unfortunately the sound playing only works under Windows). import urllib.request, winsound url_to_check = "http://google.com" run_program = True while […]

Posted in: Code by nsundin

linear_least_square


This humbly-named little program went from a single function for line-fitting multiple data-points to an entire workbench for completing my geography project (coded in August 2009). The idea behind the project was to figure out the warming factor in terms of latitude. Before this was found, the altitude correction for temperature needed to be extracted. […]

Posted in: Code by nsundin
Copyright © 2011-2024 Programmatic Verse · RSS Feed
Built on Skeleton
Powerered by Wordpress