Skip to content

Instantly share code, notes, and snippets.

View jcracknell's full-sized avatar

James Cracknell jcracknell

  • GNWT Department of Justice
  • Yellowknife, NT
View GitHub Profile
@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.
@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 / 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.
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 / 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
@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 / ldapsearch.sh
Created June 12, 2014 19:27
Strip newlines from ldapsearch results
#!/bin/bash
ldapsearch "$@" | sed -n '1h; 1!H; ${ g; s/\r\?\n //g; p }'
#!/bin/bash
while true; do
ls /run/user/$UID/gvfs/* &> /dev/null
sleep 15
done
#!/bin/bash
#==========
# Uses the GIMP to set the specified DPI value on the specified image without
# changing the dimensions of the image.
#
# This is useful as Inkscape provides no means of changing the DPI of an exported
# image without altering its pixel count, and also defaults to 90dpi.
#
# Note that gimp-console must be in your $PATH.
@jcracknell
jcracknell / JsonDialect.scala
Created December 18, 2013 23:11
Abstracting away your JSON DOM with a 'dialect' mixin.
trait JsonDialect { dialect =>
import scala.language.implicitConversions
type JValue
type JArray <: JValue
type JBoolean <: JValue
type JNull <: JValue
type JNumber <: JValue
type JObject <: JValue
type JString <: JValue