Skip to content

Instantly share code, notes, and snippets.

@misterhay
misterhay / callysto-nbgitpuller-bookmarklet.js
Last active August 16, 2022 17:16
Javascript bookmarklet to generate nbgitpuller links from GitHub repositories. Create a bookmark and replace the URL of the new bookmark with the code below.
javascript:(function(){var url=location.href;var res=url.split("/");var site=res[2];var user=res[3];var repo=res[4];var treeBlob=res[5];var branch=res[6];var nbgitputllerUrl="https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=";if(site=="github.com"){if(treeBlob){var subPath=url.substring(url.indexOf(branch)+branch.length+1);nbgitputllerUrl+=encodeURIComponent("https://github.com/"+user+"/")+repo+"&branch="+branch+"&subPath="+subPath+"&depth=1";}else{nbgitputllerUrl+=url;}}window.prompt("Callysto nbgitpuller link",nbgitputllerUrl);})();
@misterhay
misterhay / note-frequency-table.py
Created September 11, 2019 20:08
Generate a frequency (equal tempered) of musical notes chart using Pandas
import pandas as pd
noteList = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
def generateOctave(note, startingFrequency):
frequencyList = [startingFrequency]
for x in range(1,9):
frequencyList.append(startingFrequency * 2**x) # each octave up is twice the previous frequency
frequencyDf = pd.DataFrame({note:frequencyList})
return frequencyDf
@misterhay
misterhay / graphing_income_tax.py
Created October 16, 2019 21:24
Construct a graph of net income (Alberta) versus hourly wage
def calculateFederalTax(income):
taxBrackets = [47630, 95259, 147667, 210371]
taxRates = [.15, .205, .26, .29, .33]
taxes = []
for i in range(0, len(taxBrackets)):
taxes.append(taxBrackets[i] * taxRates[i])
if income < taxBrackets[0]:
tax = income * taxRates[0]
elif income < taxBrackets[1]:
tax = taxes[0] + (income - taxBrackets[0]) * taxRates[1]
@misterhay
misterhay / colab-gitpuller.js
Last active November 4, 2019 16:32
Create a Colab link for notebook from GitHub
javascript:(function(){var url=location.href;var res=url.split("github.com/");var site=res[1];colabGitUrl="https://colab.research.google.com/github/"+site;window.prompt("Colab gitpuller link",colabGitUrl);})();
@misterhay
misterhay / delete-folder.ipynb
Last active January 22, 2020 21:06
A Jupyter notebook containing some file management commands in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@misterhay
misterhay / bitly-api-with-google-apps-script.gs
Last active May 12, 2023 20:54
JavaScript code to interact with the Bitly API
function bitlyGroupId() {
var accessToken = ''; // paste in your access token from https://bitly.is/accesstoken
var headers = {'Authorization' : 'Bearer '+accessToken};
var params = {'headers' : headers};
var fetchUrl = 'https://api-ssl.bitly.com/v4/groups';
var response = UrlFetchApp.fetch(fetchUrl, params);
var group_guid = JSON.parse(response.getContentText()).groups[0].guid;
Logger.log(group_guid)
return group_guid
}
@misterhay
misterhay / clear_jupyter_outputs.py
Created March 16, 2020 16:39
Clearing outputs from Jupyter notebook files
import os
import json
def clear_outputs(notebook_name_and_path):
original_file = open(notebook_name_and_path, 'r')
notebook_contents = json.load(original_file)
original_file.close()
for cell in notebook_contents['cells']:
if cell['cell_type']=='code':
cell['outputs'] = []
@misterhay
misterhay / clear_jupyter_outputs.py
Created March 16, 2020 16:39
Clearing outputs from Jupyter notebook files
import os
import json
def clear_outputs(notebook_name_and_path):
original_file = open(notebook_name_and_path, 'r')
notebook_contents = json.load(original_file)
original_file.close()
for cell in notebook_contents['cells']:
if cell['cell_type']=='code':
cell['outputs'] = []
@misterhay
misterhay / append_jupyter_banners.py
Created March 16, 2020 16:43
Append markdown banners the first and last cell in every Jupyter notebook with Callysto banners
import os
import json
first_cell_data = {'cell_type': 'markdown','metadata': {},'source': ['![Callysto.ca Banner](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-top.jpg?raw=true)']}
last_cell_data = {'cell_type': 'markdown','metadata': {},'source': ['[![Callysto.ca License](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-bottom.jpg?raw=true)](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)']}
def add_first_and_last_cells(notebook_name_and_path):
original_file = open(notebook_name_and_path, 'r')
notebook_contents = json.load(original_file)
original_file.close()
@misterhay
misterhay / turtle-writing-misterhay.py
Created March 20, 2020 19:49
Python code for a turtle in a Jupyter notebook to write out MISTERHAY
from mobilechelonian import Turtle
t = Turtle()
t.speed(10)
full = 80
half = full/2
quarter = half/2
diagonal = full*0.707
spacing = 10