Skip to content

Instantly share code, notes, and snippets.

View willjobs's full-sized avatar

Will Jobs willjobs

View GitHub Profile
@willjobs
willjobs / megabackup.sh
Last active October 1, 2017 10:14 — forked from matteomattei/megabackup.sh
Mega server backup using megatools (revised for updated megatools, serverpilot app locations, and to include timestamps)
#!/bin/bash
now=$(date +"%T")
echo "Starting backup at ${now}..." | tee -a /root/megabackup.log
SERVER="servername"
DAYS_TO_BACKUP=7
WORKING_DIR="/root/backup_tmp_dir"
BACKUP_MYSQL="true"
@willjobs
willjobs / enumerate_bin.R
Last active October 2, 2017 03:04
R script to enumerate all binary strings of a certain length and type. Useful for getting all possible combinations of columns, for example.
# "enumerate_bin("1xx000") generates a vector of all binary strings: c("100000","101000","110000","111000")
enumerate_bin <- function(input_str) {
strlen<-nchar(input_str)
for(i in 1:strlen) {
if(tolower(substr(input_str,i,i))=="x") {
str0 <- paste(substr(input_str,1,i-1),"0",substr(input_str,i+1,strlen),sep="")
str1 <- paste(substr(input_str,1,i-1),"1",substr(input_str,i+1,strlen),sep="")
return(c(enumerate_bin(str0), enumerate_bin(str1)))
}
}
@willjobs
willjobs / google-sumdollars.js
Created October 2, 2017 03:11
Custom function for Google sheets to sum all of the dollar amounts written in notes in a given cell. If given a range of cells, will calculate the sums for each cell independently and output them below the cell with the formula.
function sumdollars(input) {
if(input.map) {
return input.map(sumdollars);
} else {
if(input.length === 0) {return 0;}
if(typeof input === 'number') {return input;}
var strArr = input.split('$').slice(1);
var mysum = 0;
for(i=0; i < strArr.length; i++) {
mysum += parseFloat(strArr[i].split(/[^0-9\.]+/)[0]);
@willjobs
willjobs / Fastmail-tampermonkey.txt
Last active October 2, 2017 04:14
Tampermonkey/greasemonkey script to fix FastMail's email body width (which is set to 938px) to fit on the page
// ==UserScript==
// @name Fastmail - email body width
// @description Fix width of emails being wider than screen
// @author Will Jobs
// @id fastmail-emailwidth
// @include https://www.fastmail.com/mail/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
@willjobs
willjobs / getMonth.gs
Created October 11, 2017 05:24
Google Sheets custom function to get month name (either full or 3-character abbreviation), given an integer
function getMonthText(val, short) {
if(val !== parseInt(val,10)) {
return "";
}
if(val < 1 || val > 12) {
return "";
}
var x = "";
switch(val) {
case 1:
@willjobs
willjobs / magoosh_gre_time.js
Created November 29, 2017 08:10
JS code to summarize the amount of video content on the Magoosh GRE site (https://gre.magoosh.com/lessons)
overall_sum = 0;
$('.thin.list-unstyled.lesson-list-condensed').each(function(idx, el) {
sum = 0;
$(el).find('.lesson-item').each(
function(idx2, inner_el) {
time = $(inner_el).find('.lesson-item-subtitle').text();
time = time.split(':');
if(time.length > 1) {
@willjobs
willjobs / Extract_PDF.py
Last active March 27, 2020 20:21
Extract PDF - Python script to extract pages of PDF into separate files
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
orig = input("enter path to file:\n")
pages_at_a_time = int(input('how many pages per file?\n'))
path, filename = os.path.split(orig)
path += '\\split'
filename = filename[:-4]

Software Preferences (and why)

This is meant to be an ongoing list of software alternatives I've evaluated, the pros and cons of each, and which I ultimately favored. It's mostly meant to remind me why I did or didn't switch so that I don't waste time re-evaluating in the future when I get annoyed by a bug or UI issue in the one that I chose. In case this helps others, I've posted it here too.

GoodNotes vs Notability

Winner: GoodNotes, for now

GoodNotes
@willjobs
willjobs / gpx_merge.py
Last active January 27, 2021 22:05
Merge (and possibly rename) GPX files
########
# This code is useful for combining many GPX files, each with a single <trk>, into
# a single GPX file containing one <trk> that has one <trkseg> per input GPX file.
#
# This is necessary for animating GPX files using GPX Animator: https://gpx-animator.app/
########
import shutil
import glob
from datetime import datetime
@willjobs
willjobs / Excel Comparison.txt
Last active January 31, 2021 02:22
Custom Excel Functions to compare two strings
Public Function countDifferences(str1 As String, str2 As String) As Integer
Dim i As Integer
If Len(str1) <> Len(str2) Then
countDifferences = -1
Exit Function
End If
countDifferences = 0
For i = 1 To Len(str1)
If Mid(str1, i, 1) <> Mid(str2, i, 1) Then