Skip to content

Instantly share code, notes, and snippets.

View jcracknell's full-sized avatar

James Cracknell jcracknell

View GitHub Profile
@jcracknell
jcracknell / transcode.sh
Created August 27, 2014 01:13
Transcodes a tree of FLAC files to OPUS.
#!/bin/bash
#
# transcode.sh
#
# Transcodes a tree of FLAC files in a specified source directory to a matching tree of
# Opus files in the specified destination directory.
scriptName=$(basename "$0")
sourceDirectory="${1%/}"
destinationDirectory="${2%/}"
@jcracknell
jcracknell / levenshtein.sh
Last active July 31, 2022 01:06
levenshtein.sh
#!/bin/bash
function levenshtein() { a="$1"; b="$2";
if [ "$a" == "$b" ]; then echo 0; return 0; fi
if [ 0 -eq ${#a} ]; then echo ${#b}; return 0; fi
if [ 0 -eq ${#b} ]; then echo ${#a}; return 0; fi
d0=(0)
d1=()
for i in $(seq 1 ${#b}); do d0[$i]=$i; done
def urldecode:
def unhex:
if 48 <= . and . <= 57 then . - 48 elif 65 <= . and . <= 70 then . - 55 else . - 87 end;
def bytes:
def loop($i):
if $i >= length then empty else 16 * (.[$i+1] | unhex) + (.[$i+2] | unhex), loop($i+3) end;
[loop(0)];
def codepoints:
@jcracknell
jcracknell / CSV.bas
Created September 12, 2018 17:19
CSV.bas
' Rudimentary CSV parser in VBA. Wheee.
Option Explicit
Public Function IsEmptyRecord(ByRef record() As String)
IsEmptyRecord = UBound(record) = 0 And record(0) = ""
End Function
' Reads a CSV record from the provided TextStream, assigning the fields
' to the provided array reference. Returns True if a record is read from
' the TextStream, or False if the end of the stream has been reached.
@jcracknell
jcracknell / numerals.sql
Created December 20, 2021 20:48
Recursive CTE for alpha/roman numeral encoding
-- Encodes the provided numeral value using alpha numerals.
create or alter function encode_alpha(@numeral int, @a char(1)) returns varchar(32)
with returns null on null input as
begin
declare @result varchar(32);
with [alphabet] ([Value], [Char]) as (
select [n].[Value], char(ascii(@a) + [n].[Value] - 1)
from (values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26)) as [n] ([Value])
),
@jcracknell
jcracknell / dnsmasq.conf
Created December 23, 2023 15:18
FreshTomato dnsmasq configuration
# Use a much larger DNS cache size than the default of 150 entries, which is
# ludicrously small
cache-size=4096
# Use stale cache entries (up to 1 day out of date). Using stale cache data triggers
# a background update of the cached entry, but responds immediately.
use-stale-cache
# Query all configured DNS servers simultaneously, using the first response.
# Reduces response times for uncached DNS lookups.