Skip to content

Instantly share code, notes, and snippets.

View phidgets-jupyter-demo.html
%%html
<script>
requirejs.config({
paths: {
'phidget22': ['https://unpkg.com/phidget22@^3.10/browser/phidget22'],
}, // strip .js ^, require adds it back
});
var usbconn;
require(['phidget22'], function(phidget22) {
@misterhay
misterhay / wisdom-of-the-crowd.ipynb
Last active Jul 11, 2022
A "Wisdom of the Crowd" Callysto
View wisdom-of-the-crowd.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@misterhay
misterhay / datalogging.py
Created Jun 19, 2022
Python code for logging data to (and retrieving data from) EtherCalc.net
View datalogging.py
class_code = '5L'
value = 12
from datetime import datetime
import requests
import pandas as pd
ethercalc_id = 'callysto' # can be the same as class_code, or randomly generated
base_url = 'https://ethercalc.net/'
post_url = base_url+'_/'+ethercalc_id
View graph-alberta-energy-generation.py
import pandas as pd
import plotly.express as px
url = 'http://ets.aeso.ca/ets_web/ip/Market/Reports/CSDReportServlet'
df = pd.read_html(url, header=0)
updated = df[1].columns[-1].split(': ')[1]
legend = df[1]['Legend'].values.tolist()
notes = df[1]['Legend.1'].dropna().values.tolist()
@misterhay
misterhay / join-downloaded-climate-data.py
Created Jan 27, 2022
Canadian temperature and precipitation 30 year averages for Canada from World Bank Climate Change Knowledge Portal
View join-downloaded-climate-data.py
# download csv files from https://climateknowledgeportal.worldbank.org/download-data
import pandas as pd
import os
df = pd.DataFrame()
for root, dirs, files in os.walk('.'):
for name in files:
if name.endswith('.csv'):
df2 = pd.read_csv(os.path.join(root, name), skiprows=1)
@misterhay
misterhay / gapminder-electricity-use-and-carbon-dioxide-production.py
Last active Jan 24, 2022
Create a double bar graph from Gapminder data
View gapminder-electricity-use-and-carbon-dioxide-production.py
countries = sorted(['Canada','United States','Mexico','Costa Rica','China'])
year = '2013'
import pandas as pd
co2 = pd.read_csv('https://docs.google.com/spreadsheets/d/1VxxG9XJNG5oFXBo_0TTCP_sQ9wEv3Oy5SEOlR_0du5c/export?gid=1415343215&format=csv')
electricity = pd.read_csv('https://docs.google.com/spreadsheets/d/1L9CAwtcOoG3WfGkrFOYjAByaznce-DGE1dPK-1-23PU/export?gid=1944428591&format=csv')
y1 = co2[co2['country'].isin(countries)][year]
y2 = electricity[electricity['country'].isin(countries)][year]/1000
y1_name = 'Carbon Dioxide Emissions per Person'
@misterhay
misterhay / halo-infinite-statistics.ipynb
Last active Jan 14, 2022
Halo Infinite Statistics.ipynb
View 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 Jan 5, 2022
Read data from the Wikipedia article on electricity generation in Alberta and create a pie chart
View electricity-generation-in-alberta.py
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 Jan 2, 2022
Javascript for creating a Halo Infinite statistics endpoint on autocode.com
View autocode-halo-infinite-stats.js
// 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 Dec 13, 2021
A Python script to extract images from Minecraft Education Edition portfolio exports
View extract-minecraft-portfolio-images.py
# 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'):