Skip to content

Instantly share code, notes, and snippets.

View timbledum's full-sized avatar

Marcus Croucher timbledum

  • Auckland, New Zealand
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@timbledum
timbledum / ttt2.py
Created April 17, 2019 23:53
TTT refactored for pyxel
import sys
import pyxel
# https://github.com/kitao/pyxel for information about the pyxel game library
# Window
WIDTH = 150
HEIGHT = 180
RED = 3
WHITE = 7
import pygame
import sys
# Window
WIDTH = 300
HEIGHT = 325
LINETHICKNESS = 5 # The thickness of the line used to represent 3 in a row
RED = (250, 0, 0)
WHITE = (250, 250, 250)
BLACK = (10, 10, 10)
#!/usr/bin/env python3
# downloadXkcd.py - Downloads every single XKCD comic.
import requests, os, bs4
url = "http://xkcd.com" # starting url
os.makedirs("xkcd", exist_ok=True) # store comics in ./xkcd
while not url.endswith("#"):
# Download the page.
print("Downloading page %s..." % url)
import statistics
def calculator(degree, minutes, seconds):
calc = 0.0
calc = abs(degree) + (minutes / 60) + (seconds / 3600)
minus = "-" if degree < 0 else ""
print(f"{degree}° {minutes}` {seconds}`` --> {minus}{calc:.2f}")
return calc
import csv
from itertools import groupby
# Constants
TRANSACTIONS_FILE = "transactions.csv"
PRODUCTS_FILE = "products.csv"
def get_city_mapping():

So you know how you have built in types in python? For example, lists.

list is a type, and we can pretty much create our own custom types by making classes. This is confirmed by Python:

>>> type(list)
<class 'type'>

>>> class Sample:
...     pass

...

SIZES = {"s": "Small", "m": "Medium", "l": "Large"}
PRICES = {"s": 1.5, "m": 1.75, "l": 2.0}
SWEETENED = {"s": "Sweetened", "u": "Unsweetened"}
class Beverage:
name = "Beverage"
def __init__(self, size, price):
self.size = size
self.price = price
data = {'Account balances': [{'2008-04-04': 252216},
{'2010-05-17': 3619948},
{'2010-10-25': 590954},
{'2014-10-01': 568340},
{'2016-09-04': 2424784},
{'2018-08-25': 261463}],
'Address book contacts': [{'2017-12-05': 20580060}],
'Age groups': [{'2014-02-17': 37784}, {'2017-12-31': 84011}],
'Ages': [{'2014-09-01': 1287073}],
'Apps installed on devices': [{'2017-12-05': 20580060}],
#! /usr/bin/python3
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QMainWindow,
QVBoxLayout, QTabWidget)
from .gui import npc, places, items, quest, monsterbuilder
class App(QMainWindow):
def __init__(self):