Mr. Hay's Technology
Various technology-related musings.
Saturday, May 7, 2022
Creating, Editing, and Sharing Jupyter Notebooks
Saturday, December 11, 2021
Automatically Changing a YouTube Video's Privacy With Google Apps Script
Recently we had posted a video that needed to be available during a specific time. The starting availability is taken care of by setting it to premiere. However there's no option for having it unavailable at the end of the time period, so we needed to write some code for that.
Google Apps Script is a good choice for this, since it has a YouTube service that you can enable as well as triggers that can run code at a certain time.
Create a new Apps Script project and paste in the following code:
Then enable the YouTube Service and create a new trigger to run the updateVideoPrivacy function at a time-driven specific date and time. The code will then set your most recently uploaded YouTube video to private at the time you specified.
Saturday, October 30, 2021
Coding Challenge 3
The third coding challenge is up at misterhay.github.io/coding-challenges, along with a possible solution to this challenge and last month's challenge.
Thursday, September 30, 2021
Small Coding Challenge 2
The second coding challenge is up at misterhay.github.io/coding-challenges, along with a possible solution to this challenge and last month's challenge.
Saturday, September 11, 2021
Fixing a formula in multiple Google Sheets
Recently we realized that there was a calculation error in a Google Sheet template, and unfortunately we had already made a copy of it for each teacher.
Rather than opening each Sheet and manually making the correction, I wrote a Google Apps Script to automatically make the replacements. Here is the code in case it is helpful for anyone else:
function loopThem() { var folderId = 'aaaaaaaaa'; // the folder containing all of the sheets to be corrected var folder = DriveApp.getFolderById(folderId); var files = folder.getFiles(); while (files.hasNext()) { var file = files.next(); var id = file.getId(); fixIt(id); } } function fixIt(id) { var rangeToFix = 'P1:P50'; // the range in each sheet that contains the error var replaceThis = '$A'; var replaceWithThis = '$C'; var ss = SpreadsheetApp.openById(id); var range = ss.getRange(rangeToFix); var formulas = range.getFormulas(); for (var i=0; i<formulas.length; i++) { var formula = formulas[i][0]; var newFormula = formula.replaceAll(replaceThis, replaceWithThis); formulas[i][0] = newFormula; } range.setFormulas(formulas); }
Sunday, August 29, 2021
Small Coding Challenge 1
This year I'm going to design some coding challenges, and hopefully release them at least once a month.
The first coding challenge is up at misterhay.github.io/coding-challenges.
Saturday, March 13, 2021
Quick Exploratory Data Analysis with SweetViz
I recently came across a Python library that is useful for quick exploration of a dataset (or two) in a Jupyter notebook, SweetViz.
Code:
try: import sweetviz except: !pip install sweetviz --user import sweetviz import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/callysto/hackathon/f7454f5d9234df2575ceb7b8983340e512fad24d/SustainabilityOnMars/Tutorials/pets_from_bootstrap_world.csv') analysis = sweetviz.analyze(df) analysis.show_notebook() # or export with show_html()
Here is a brief notebook demonstration.