Skip to content

Instantly share code, notes, and snippets.

@rolandcrosby
rolandcrosby / towns.rb
Created Nov 30, 2020
generate some massachusetts town names
View towns.rb
#!/usr/bin/env ruby
class WordMarkov
def initialize(data=[])
@nexts = {}
@initials = []
data.each do |word|
chars = word.split('')
@initials << chars[0..1]
chars[0..-3].each_with_index do |char, i|
@rolandcrosby
rolandcrosby / flightaware-kml-merge.py
Last active Sep 14, 2020
merge multiple KML track files from FlightAware into a single file that can be imported into Google My Maps
View flightaware-kml-merge.py
from glob import glob
from lxml import etree
def xpath(el, path):
return el.xpath(path, namespaces={
'kml': 'http://www.opengis.net/kml/2.2',
'gx': 'http://www.google.com/kml/ext/2.2'
})
View repositories-20200717.txt
"rolandcrosby/adjacency"
"rolandcrosby/adsb"
"rolandcrosby/airports-that-sound-alike"
"rolandcrosby/alexa-transit"
"rolandcrosby/balloonboy"
"rolandcrosby/bernie"
"rolandcrosby/calligraphy"
"rolandcrosby/ccal"
"rolandcrosby/citibike"
"rolandcrosby/cloudwriter"
@rolandcrosby
rolandcrosby / ffmpeg.sh
Last active Oct 24, 2020
just so i have this next time i want to dub some audio with ffmpeg
View ffmpeg.sh
# mix two audio streams together:
youtube-dl "https://www.youtube.com/watch?v=c38HJR-9vhU" -f best -o burnafterreading.mp4
youtube-dl "https://www.youtube.com/watch?v=Pqh63ca__mM" -f best -o chromatica.mp4
ffmpeg \
-ss 77.2 \ # skip first 77.2 seconds of first input
-i burnafterreading.mp4 \
-i chromatica.mp4 \
-filter_complex "[0:1][1:1] amix=inputs=2:weights=2 1" \ # mix track 1 (audio) of inputs 0 and 1, make audio 0 twice as loud as 1
-map 0:0 \ # use track 0 (video) from input 0
-c:a aac -strict -2 \ # don't think this is necessary, default encoder settings should be fine
@rolandcrosby
rolandcrosby / mkcsr.py
Created May 6, 2020
make a certificate signing request that you can use with mkcert
View mkcsr.py
#!/usr/bin/env python3
from OpenSSL import crypto, SSL
from typing import List, Optional
import sys
import os
import errno
def get_or_make_key(cn: str) -> crypto.PKey:
@rolandcrosby
rolandcrosby / openterm.sh
Created Apr 25, 2020
switch to gnome-terminal if it's open, otherwise launch a new one
View openterm.sh
#!/bin/bash
read -r win_found <<<$(wmctrl -l -p | awk '{print $1,$3}' | while read -r wins; do ps -o command= -p "${wins/0x* /}" | grep -q gnome-terminal && echo "${wins/ */}" && break; done)
if [ -z "$win_found" ]; then
gnome-terminal
else
wmctrl -i -a $win_found
fi
View most-used sandwich ingredients.sparql
SELECT ?ingredient ?ingredientLabel (GROUP_CONCAT(DISTINCT ?sandwichLabel; SEPARATOR = ", ") AS ?sandwiches) WHERE {
?sandwich ((wdt:P31?)/(wdt:P279*)) wd:Q28803;
wdt:P527 ?ingredient.
MINUS { ?ingredient (wdt:P279*) wd:Q7802. }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en", "fr".
?sandwich rdfs:label ?sandwichLabel.
?ingredient rdfs:label ?ingredientLabel.
}
}
@rolandcrosby
rolandcrosby / Palme d'Or.sparql
Last active Jul 24, 2020
Wikidata SPARQL query to retrieve films that have won the Palme d'Or at Cannes
View Palme d'Or.sparql
SELECT
?film
?title
?directors
?year
WHERE
{
SELECT
?film
?title
View list comprehensions.md

these are all pretty similar --

Scala:

val outer = List(List(1, 2, 3, 4, 5), List(4, 5, 6, 7, 8))
for {
  inner <- outer
  x <- inner
} yield x
@rolandcrosby
rolandcrosby / rot13-inline.js
Created Apr 8, 2020
rot13 the current selection in your browser
View rot13-inline.js
(function () {
function rot13(str) {
return str.replace(/([A-Ma-m])|([N-Zn-z])/g, function (m, p1, p2) {
return String.fromCharCode(m.charCodeAt(0) + (p1 ? 13 : -13));
});
}
if (document.getSelection().rangeCount == 0) {
return;
}
const range = window.getSelection().getRangeAt(0);
You can’t perform that action at this time.