Skip to content

Instantly share code, notes, and snippets.

@wolfospealain
wolfospealain / bytefunctions.py
Last active December 5, 2018 13:08
Humanise Bytes
def kilobytes(bytes):
kb = round(bytes / 2**10, 1)
return str(kb)+"KB"
def megabytes(bytes):
mb = round(bytes / 2**20, 1)
return str(mb)+"MB"
@wolfospealain
wolfospealain / asciitable.py
Created October 3, 2018 11:59
ASCII Table
#!/usr/bin/env python3
"""
This program prints an ASCII table.
"""
start = 32
end = 127
columns = 8
rows = int((end - start + 1) / columns)
@wolfospealain
wolfospealain / interface.py
Last active April 9, 2018 13:46
FOOP Skills Demo 3 Notes
"""Sample code to demonstrate reading a list of objects from a file"""
from people import *
database_list = []
# Add Staff from file to the database list until there's no text left.
file = open("staff.txt", "r")
while True:
@wolfospealain
wolfospealain / irishrail.py
Last active February 2, 2018 21:45
Irish Rail API (XML)
import untangle
from datetime import datetime
class IrishRail:
def __init__(self, station="MLLOW", minutes=6):
self.station = station
self.minutes = minutes
self.url = "http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByCodeXML_WithNumMins?StationCode={}&NumMins={}".format(self.station, self.minutes)
@wolfospealain
wolfospealain / ball.py
Created January 29, 2018 12:22
Game Basics
class Ball:
def __init__(self, x, y, radius, direction="none"):
self.x = x
self.y = y
self.radius = radius
self.direction = direction
def move(self):
if self.direction == "left":
@wolfospealain
wolfospealain / bitcoin.py
Last active March 1, 2018 04:36
BitCoin Price
# Fetches BitCoin price from CoinDesk
# https://www.coindesk.com/price/
# Code adapted from https://github.com/dursk/bitcoin-price-api
import requests
def get_price(currency='USD'):
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(currency)
response = requests.get(url)
response.raise_for_status()
@wolfospealain
wolfospealain / drone.py
Last active December 13, 2017 14:56
PyGame Basics
from datetime import datetime
class Drone:
"""Defines the Drone class."""
def __init__(self, name="drone", x_position=0, y_position=0, power=100, radius=15, colour=[255,255,255], thickness=3):
self.name = name
self.x = x_position
self.y = y_position
self.p = power
@wolfospealain
wolfospealain / sets.py
Created December 11, 2017 00:28
Schedule Meetings
import itertools
meetings = {"hardware": ["Paul", "Mairin", "Natasha", "John", "Pat"],
"networks": ["Pat", "Niall", "Bernie", "Eoin"],
"operating systems": ["Natasha", "Eoin", "Michael", "Regina"],
"programming": ["Mairin", "Michael", "Rosemary", "Mary", "Ray", "Maura", "Joan", "Sheena"],
"object oriented": ["Natasha", "Eoin", "Michael", "Maura", "Guy"],
"software architecture": ["Natasha", "Eoin", "Maura"],
"virtualisation": ["Natasha", "John", "Pat", "Regina", "Mary"],
"mobile technologies": ["Rosemary", "Ray"],
@wolfospealain
wolfospealain / conversions.py
Last active October 26, 2017 05:49
Temperature Conversion GUI
"""
Conversion Functions
Eoin Ó Spealáin
October 2017
"""
def c_to_f(temperature):
"""Converts temperature from Celsius to Fahrenheit."""
f = temperature * 9/5 + 32
return f
@wolfospealain
wolfospealain / daisy.py
Created October 4, 2017 14:38
Daisy Chain
#!/usr/bin/python3
from turtle import *
biro = Turtle()
biro.color("purple", "yellow")
biro.speed(0)
def petal():
biro.begin_fill()