Skip to content

Instantly share code, notes, and snippets.

@misterhay
misterhay / halo-infinite-statistics.ipynb
Last active January 14, 2022 14:41
Halo Infinite Statistics.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@misterhay
misterhay / electricity-generation-in-alberta.py
Created January 5, 2022 21:40
Read data from the Wikipedia article on electricity generation in Alberta and create a pie chart
import pandas as pd
import plotly.express as px
df = pd.read_html('https://en.wikipedia.org/wiki/List_of_generating_stations_in_Alberta')
categories = ['coal','natural gas','dual fuel','biomass','geothermal','hydroelectric','wind','solar']
values = []
for i, c in enumerate(categories):
total = int(pd.to_numeric(df[i+1]['Capacity (MW)'], errors='coerce').sum())
values.append(total)
px.pie(names=categories, values=values)
@misterhay
misterhay / autocode-halo-infinite-stats.js
Last active January 2, 2022 04:04
Javascript for creating a Halo Infinite statistics endpoint on autocode.com
// Return Halo Infinite stats for a gamertag as a json string
// instructions for creating your own endpoint at https://docs.autocode.com/getting-started/creating-your-first-project/creating-an-endpoint/
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
module.exports = async (context) => {
const gamertag = context.params.gamertag;
// if no gamertag is passed return an error
if (!gamertag) {
return {
@misterhay
misterhay / extract-minecraft-portfolio-images.py
Last active December 13, 2021 18:17
A Python script to extract images from Minecraft Education Edition portfolio exports
# python -m pip install PyMuPDF Pillow
import os # for files and directories
import io # for bytes
import fitz #PyMuPDF
from PIL import Image #Pillow
for root, dirs, files in os.walk("."):
for filename in files:
if filename.endswith('.pdf'):
@misterhay
misterhay / update-youtube-privacy.gs
Last active December 11, 2021 17:04
Google Apps Script function to change a YouTube video's privacy status
// schedule this Google Apps Script function to run at a certain time to change a YouTube video's privacy status
function updateVideoPrivacy() { // enable the YouTube Data API under "Services"
var channels = YouTube.Channels.list('contentDetails', {mine: true});
for (var i=0; i<channels.items.length; i++) {
var uploadsPlaylistId = channels.items[i].contentDetails.relatedPlaylists.uploads;
var playlistResponse = YouTube.PlaylistItems.list('snippet', {playlistId: uploadsPlaylistId, maxResults: 1}); // or more than 1 if needed
var video = playlistResponse.items[0]; // the first video in the list we retrieved
var metadata = {
status: {'privacyStatus': 'private'}, // public, unlisted, private
id: video.snippet.resourceId.videoId}; // we need to include the video ID from the playlist response
@misterhay
misterhay / testing.js
Created April 1, 2021 05:05
A quick test for loading external JavaScript files
function test() {
return "this works";
}
@misterhay
misterhay / SWEETVIZ_REPORT.html
Last active March 13, 2021 17:10
A quick demo of Sweetviz for exploratory data analysis in a Jupyter notebook
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAPD4/AC0vMADd3+AAWFpbAFlaWwC8vb0AOjw9AERHRwCSlJUAk5SVAJ6fnwD39/cAW1xeAGVnaAC0t7YAgYOEAI2OjgDk5uYA9fX1AFhaXABzdHUA5ubmAG5wcAA6PD4Ax8jIAEVHSAA2ODkAqaqqAPLz8wB7fX0AQ0VGADQ2NwB6e3sAs7W1AJqbnAAjJSYAi4yNAP7+/gDu7+8A7+/vAHZ5eQDf4OAAtbe4ANHR0QBPUFEAwsLCAKioqQCjpKQA/Pz8AO3t7QBrbG0AvcDAAExOTwDJy8oAlpeYAC4wMQDe4OEAkZOTAPr6+gBoamsAWVtcANzc3ABkZmYAKy4vAK6vrwAsLi8A/fz9AJCRkQDe3t8AZmhpANna2gDa2toAYmRkAJGTlADr6+wA9vb2AH6AgABlZmcAYGJiAMjJyQBGSEkAr6+wAIGCgwC3uLgAqKmpANTU1ABSU1QAqqusAEJERQC1trYAlpiYAC8xMQD///8AfX5/AH5+fwBtb3AA8PDwAODh4QB6enoAuLi5ALO0tAA8Pj4A/f39AHt8fQDu7u4Ad3h4AExPUADFxcYA0NDQAMDBwQBOT1AAPkBBAPn7+wDq7OwAeXp7ANvd3QDc3d0AdHZ2AEtNTgBMTU4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@misterhay
misterhay / videoconference_controller.ino
Last active February 14, 2021 19:52
Videoconference controller with arcade buttons and Teensy microcontroller (Arduino)
// Teensy 2 Videoconference Buttons Controller
// Choose Keyboard from the "Tools > USB Type" menu
// buttons connected to 6 pins, and a switch for different programs
#include <Bounce.h>
Bounce button0 = Bounce(2, 50);
Bounce button1 = Bounce(1, 100); // this button was too sensitive
Bounce button2 = Bounce(0, 50);
Bounce button3 = Bounce(3, 50);
Bounce button4 = Bounce(14, 50);
@misterhay
misterhay / rps.py
Created January 29, 2021 08:10
Animating a "Rock Paper Scissors" tournament
number_of_rounds = 50
player1 = 'Steven'
player2 = 'Edward'
choices = {
'Steven':['Rock','Paper','Scissors'],
'Bart':['Rock'],
'Edward':['Scissors','Scissors','Scissors','Scissors','Paper','Paper'],
'Freddie':['Paper','Paper','Rock','Paper','Paper','Rock']}
# create a dataframe of rock beats scissors etc.
@misterhay
misterhay / marking.py
Last active January 23, 2021 21:01
Parsing Brighspace assignment downloads and marking spelling and other conventions
import os
import pdfplumber
from spellchecker import SpellChecker
spell = SpellChecker()
for path, directories, files in os.walk('.'):
for filename in files:
if filename.endswith('.pdf'):
filepath = path + os.sep + filename
student = path.split('- ')[1].strip() # get the student name from the directory name