Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@misterhay
misterhay / postPressure.py
Last active August 29, 2015 14:15
posting atmospheric pressure data from openweathermap.org
import requests
# fill in the appropriate values from your data.sparkfun.com data stream
publicKey = 'G2pKDamRDDUwKy7aMdy5'
privateKey = ''
dataLabel = 'pressure'
# Weather location, see openweathermap.org/current for more information
location = 'Edmonton,ca'
weatherUnits = 'metric'
@misterhay
misterhay / geocode.py
Created February 18, 2015 23:13
translating addresses to latitude and longitude
import geocoder
import csv
def getGeo(address):
lat = geocoder.google(address).lat
lng = geocoder.google(address).lng
print lat, lng
source = csv.reader(open('source.csv', 'rb'))
for row in source:
@misterhay
misterhay / logIP.py
Last active April 14, 2017 03:54
finds the machine's hostname and external and internal IP address, and logs them to data.sparkfun.com
#!/usr/bin/env python
# by David Hay @misterhay
# This script finds the machine's hostname and external and internal IP address, and logs them to data.sparkfun.com
# borrowed some code from http://blog.turningdigital.com/2012/09/get-ip-address-of-raspberry-pi-operating-headlessly/
# edit the next two lines with your values from https://data.sparkfun.com/streams/make
public_key = ''
private_key = ''
import os
#!/usr/bin/python
# some code/ideas borrowed from http://youtu.be/oaf_zQcrg7g
import time, threading
delayTime = 0.25
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
pins = [2, 3, 4, 17, 27, 22, 10, 9, 11, 14, 15, 18, 23, 24, 25, 8, 7]
#pins = [2, 3, 4, 17, 27, 22, 10, 9, 14, 15, 18, 23, 24, 25, 8, 7]
#pins = [2, 3, 4, 17, 27, 22, 10, 9, 11]
// Create a Google spreadsheet with a list of student email addresses in column A starting at row 2.
// Rename the sheet Achievements or change line 17 of this code.
// Under the Tools menu choose Script editor and paste in this code.
// Follow the directions at https://developers.google.com/classroom/quickstart/apps-script to authorize your script.
// Set up a trigger to run countClassroomAssignments() every morning or every week.
// https://developers.google.com/apps-script/reference/spreadsheet/sheet
function listCourses() {
// Run this then check the execution logs to find the courseId for your desired course
var courses = Classroom.Courses.list().courses;
@misterhay
misterhay / drawSomething.gs
Last active December 30, 2016 21:02
Generates a subject, verb, and location for a drawing game (in Google Sheets with Google Apps Script)
// in a Google Sheet that has two sheets: Cards and Drawn
// The 'Cards' sheet should have three columns: subject, verb, and location
// This code is public domain, but let me know if there are any copyright concerns.
// https://developers.google.com/apps-script/guides/sheets
// https://docs.google.com/spreadsheets/d/1mrnsKUCSkum-ZmAvGtK10uAf1eypdxsoFP7tbjWynsQ
function addMenu() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Game').addItem('Draw Something', 'drawSomething').addToUi();
}
@misterhay
misterhay / concatenateStudentResponses.gs
Created January 7, 2017 07:01
Starting from a Google Spreadsheet containing links to student response documents, this creates a single document containing all of their responses.
function addMenu() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Student Responses').addItem('Concatenate all responses', 'concatenateResponses').addToUi();
}
function concatenateResponses() {
var responsesDoc = DocumentApp.create('Student Responses');
var responsesDocID = responsesDoc.getId();
var sheet = SpreadsheetApp.getActiveSheet();
var columnContainingLinksToDocuments = 6;
@misterhay
misterhay / PandasPlotlyJupyter.py
Last active February 14, 2018 06:05
experimenting with Panada and Plotly offline in Jupyter for visualizing open data
import pandas as pd
import plotly
from plotly.graph_objs import Scatter, Layout
plotly.offline.init_notebook_mode(connected=True)
plo = plotly.offline.iplot
results = pd.read_excel('https://education.alberta.ca/media/3680582/diploma-multiyear-auth-list-annual.xlsx')
years = []
for value in results.columns.values:
numberOfRolls = 10
numberOfSides = 6
from random import randint # a module for random integers
resultsList = [] # create an empty list
for x in range(0,numberOfRolls): # loop through this a number of times
number1 = randint(1, numberOfSides) # pick a number between 1 and 6
number2 = randint(1, numberOfSides) # pick another number between 1 and 6
total = number1 + number2 # add those two values
#print(total)
resultsList += [total] # append the sum to the resultsList
@misterhay
misterhay / TeleprompterFormatter.gs
Created October 8, 2018 15:08
Video Announcements Teleprompter Formatting Script (Google Apps Script)
// remember to add an on-open trigger for addMenu
function addMenu() {
var ui = DocumentApp.getUi();
ui.createMenu('WBO Announcements')
.addItem('Format Announcements', 'formatAnnouncements')
.addToUi();
}
function formatAnnouncements() {