Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am lordsutch on github.
  • I am lordsutch (https://keybase.io/lordsutch) on keybase.
  • I have a public key whose fingerprint is 6958 A410 0D18 3097 8B3D ACB6 C9FC 41B8 F98C 66CF

To claim this, I am signing this object:

@lordsutch
lordsutch / checkbox-dummies.R
Last active August 29, 2015 14:07
Turn a comma-separated list of values (like from a Google Forms spreadsheet with a checkbox form) into logical variables
library(stringr)
mga.students <- read.csv('MGA POLS 1101 Student Profile Survey (Responses) - Form Responses 1.csv')
## Checkbox items
varlist <- c('Based.on.what.you.know.off.the.top.of.your.head..without.looking.it.up...which.of.the.following.statements.about.Middle.Georgia.State.College.do.you.believe.to.be.true..You.can.mark.more.than.one.response.',
'Which.of.the.following.statements.reflect.s..why.you.are.planning.to.transfer...You.may.select.more.than.one.answer..',
'Which.of.the.following..if.any..would.make.you.more.excited.about.pursuing.your.education.at.Middle.Georgia.State.'
)
@lordsutch
lordsutch / dropquizzes.R
Created November 14, 2012 15:41
Add a variable to a data frame giving a mean of a set of quiz grades, dropping n grades
## Note: we're assuming each grade should be weighted equally here.
dropmean <- function(x, drop=2) {
count <- length(x)-drop
round(sum(sort(x, decreasing=TRUE)[seq(1, count)], na.rm=T)/count, 2)
}
## Same formula for multiple sections; note list.files uses a regex pattern, not a glob pattern
infiles <- list.files(pattern='^gradebook-quizzes-[0-9]+\\.csv$')
for(filename in infiles) {
@lordsutch
lordsutch / README.md
Last active December 25, 2015 17:59 — forked from mbostock/.block
Futzing with OSM Vector Tiles
@lordsutch
lordsutch / fixvid
Created December 30, 2015 04:50
Convert videos to Chromebook-compatible format, if necessary
#!/usr/bin/env python3
import sys
import subprocess
import json
import os
# Supported by Chrome OS according to https://www.chromium.org/audio-video
ACCEPTABLE_VIDEO=('theora', 'vp8', 'vp9', 'h264', 'mpeg4')
@lordsutch
lordsutch / moca-password.py
Created February 1, 2017 21:17
Generate a password/key for a MoCA network with Python 3.6+
#!/usr/bin/env python3.6
import string
import secrets
while True:
password = secrets.randbelow(100000000000000000)
if password >= 100000000000:
break
@lordsutch
lordsutch / plotcells.R
Last active April 5, 2017 17:44
code for multilateration of cell towers in R
library(ggmap)
library(plyr)
library(sp)
library(geosphere)
library(doMC)
registerDoMC()
allcells <- data.frame()
for(cell in list.files(pattern="^cellinfolte.*[.]csv$")) {
@lordsutch
lordsutch / encode-anthem-st.py
Created February 28, 2019 17:20
Script to encode the Anthem digital soundtrack to AAC for iTunes etc. Can be readily adapted to other WAV albums.
#!/usr/bin/env python3
# Get 'fdkaac' from https://github.com/nu774/fdkaac (or Homebrew etc.)
import glob
import subprocess
import sys
import os
def convert_file(filename, trackcount):
@lordsutch
lordsutch / SaveAttachments.AppleScript
Created July 1, 2019 16:55
AppleScript to save attachments into a folder with filenames including the attachment date
-- Tested on macOS 10.14.5
use scripting additions
using terms from application "Mail"
on perform mail action with messages messageList -- in mailboxes mbox for rule aRule
-- Must be in your Downloads folder or a subfolder in recent macOS versions
set destinationPath to (POSIX file "/Users/quango/Downloads/enrollment/") as string
tell application "Mail"
@lordsutch
lordsutch / test_bitmask.py
Created July 25, 2019 16:57
Bitmask testing routine for Python 3.6+
# Copyright (C) 2019 Chris Lawrence
# You may freely modify, copy, and reuse this software under the terms of the MIT License.
def test_bitmask(value: int, mask: str) -> bool:
mask = mask.replace("_", "")
testval: int = 1
for bit in reversed(mask):
if bit == '1' and not (value & testval):
return False
elif bit == '0' and (value & testval):