Skip to content

Instantly share code, notes, and snippets.

View AstroCB's full-sized avatar
👀

Cameron Bernhardt AstroCB

👀
View GitHub Profile
@AstroCB
AstroCB / ghpm-publish.js
Last active July 27, 2020 05:54
This script publishes npm packages to GitHub package manager – specifically, it takes npm-distributed (through npmjs.com) packages and converts them to the required format, publishes them to the GitHub registry, and then reverts them back to their original state.
#! /usr/bin/env node
// =========== REPLACE YOUR USERNAME HERE ===========
// Must be lowercase; package will be listed as @username/package-name on GHPM
const GITHUB_USERNAME = "username";
// =========== REPLACE YOUR USERNAME HERE ===========
// Performs the changes needed to publish an npm package to GitHub package
// manager, then publishes it, then undoes those changes (to be a regular npm
// package). Assumes package.json exists in cwd.
@AstroCB
AstroCB / LinkFormatter.js
Created November 1, 2014 18:32
Puts links in the format "-hyperlinked_title (source)" and outputs HTML source
var title = "empty";
var url = "empty";
var source = "";
var i = 0;
var j = 0;
var webData = {};
var sources = [];
var finalData = "";
@AstroCB
AstroCB / CleanYourListen.user.js
Last active June 4, 2020 08:06
Clean up YourListen podcast service
// ==UserScript==
// @name Clean Up YourListen
// @namespace http://greasyfork.org/
// @include http://yourlisten.com/*
// @description Remove YourListen cruft
// ==/UserScript==
window.addEventListener("load", function () {
var classes = ["a_tabs", "ad-trackeable", "fbLeft", "navbar-inner", "ad-pad-sm"];
var ids = ["social", "audio_sdb", "f"];
@AstroCB
AstroCB / showGrades.user.js
Created May 10, 2015 22:33
Show numerical grades that teachers have hidden on BCPS One
// ==UserScript==
// @name Show Hidden Grades
// @namespace http://github.com/AstroCB
// @author Cameron Bernhardt
// @description Show numerical grades that teachers have hidden on BCPS One
// @version 1.0
// @include *://bcpsone.bcps.org/student/?*
// ==/UserScript==
var grades = document.querySelectorAll("a .hidden");
for (var i = 0; i < grades.length; i++) {
@AstroCB
AstroCB / smallcaps.user.js
Last active June 4, 2020 08:05
Automatically changes your Stack Exchange chat messages to Sᴍᴀʟʟᴄᴀᴘs
// ==UserScript==
// @name Smallcaps.SE
// @author Cameron Bernhardt (AstroCB)
// @description Automatically changes your Stack Exchange chat messages to Sᴍᴀʟʟᴄᴀᴘs
// @version 1.1
// @namespace http://github.com/AstroCB
// @include *://chat.meta.stackexchange.com/rooms/*
// @include *://chat.stackexchange.com/rooms/*
// @include *://chat.stackoverflow.com/rooms/*
// ==/UserScript==
@AstroCB
AstroCB / classes.js
Created January 12, 2017 06:29
An example PhantomJS script for pulling class data from a schedule webpage.
const page = require("webpage").create();
page.open("https://classes.cornell.edu/shared/schedule/SP17/f2447538c565d8b0821840d825a50430", function(status) {
console.log("Loaded with status " + status);
if (status == "success") {
var doc = page.evaluate(function(parse) {
parse(document);
}, parse);
phantom.exit();
}
});
@AstroCB
AstroCB / loadBook.js
Last active June 4, 2020 08:02
Scrapes public book pages and converts them to PDF.
var web = require("webpage"),
numPages = 819;
function load(pageNum) {
var url = "https://mediaserver.123library.org/9781292152578/svg/" + pageNum + "/206298/1485375389/907fbc6e4ef67c6e160a3d198b836551/";
var page = web.create();
page.open(url, function(status) {
if (status === "success") {
console.log("Writing page " + pageNum);
page.render("Pages/" + pageNum + ".pdf");
@AstroCB
AstroCB / wakeTimes.js
Created May 26, 2020 02:12
Script to get wake-up times based on sleep cycles adapted from sleepyti.me site's source code
#! /usr/local/bin/node
// Get wake-up times based on sleep cycles if going to sleep now
// Code adapted from sleepyti.me source (surprisingly not minified)
const N_TIMES = 6; // Number of wake-up times to provide
let dates = [new Date(new Date().getTime() + 104 * 60000)];
for (let i = 1; i < N_TIMES; i++) {
dates.push(new Date(dates[i - 1].getTime() + 90 * 60000));
@AstroCB
AstroCB / markPiazzaAsRead.js
Created October 17, 2019 02:59
Small script that adds a button to the Piazza toolbar to mark all posts in the currently selected class as read.
// Button to mark all posts as read
function makeButton() {
let button = document.createElement("button");
button.setAttribute("id", "new_post_button");
button.setAttribute("class", "btn-primary left btn-small");
button.addEventListener("click", _ => {
// Clear unread posts and reload page
document.querySelectorAll(".unread").forEach(b => b.click());
window.location.reload();
});
@AstroCB
AstroCB / xkcdBot.user.js
Created April 5, 2017 21:54
A bot in the form of a userscript that runs in Stack Exchange chat rooms.
// ==UserScript==
// @name xkcdBot
// @author Cameron Bernhardt (AstroCB)
// @description A chat bot that spurts bits of wisdom and/or snark. Oh, and xkcd cartoons.
// @version 1.3.27 (last updated 02/02/2016)
// @namespace http://github.com/AstroCB
// @downloadURL https://cameronbernhardt.com/projects/xkcdBot/xkcdBot.user.js
// @include *://chat.meta.stackexchange.com/rooms/*
// @include *://chat.stackexchange.com/rooms/*
// @include *://chat.stackoverflow.com/rooms/*