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 / 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/*
@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 / 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 / json.swift
Created September 5, 2016 20:19
A snippet that makes working with JSON in Swift a little less painful using JS-like syntax.
/**
Handles JSON in an OO/JavaScript-y fashion
# Example usage
`let json: JSON = JSON(url: "https://me.com/me.json")`
`print(JSON.parse(json.load()))`
*/
public struct JSON {
@AstroCB
AstroCB / SpotifyInfo.scpt
Created July 23, 2016 03:21
Displays a notification containing information about the currently playing Spotify track (works best when assigned to a keyboard shortcut)
tell application "Spotify"
set currentArtist to artist of current track as string
set currentTrack to name of current track as string
display notification "\"" & currentTrack & "\" by " & currentArtist with title "Now Playing"
delay 1
end tell
@AstroCB
AstroCB / softblink.ino
Last active August 29, 2015 14:23
Blinks a light softly by scaling analog values (demo at http://i.imgur.com/dz3ZJUF.gif)
@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==