Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jonathanduke on github.
  • I am jonathanduke (https://keybase.io/jonathanduke) on keybase.
  • I have a public key whose fingerprint is 0AF9 932B 0F4F 2ED1 8B7A 01E4 25C1 F8BD 1D9E 81CD

To claim this, I am signing this object:

@jonathanduke
jonathanduke / BuildAssemblyInfo.targets
Last active September 27, 2023 17:43
Build targets for Visual Studio to automatically include Git commit hash and other build metadata in assembly info
<!--
Based on: https://gist.github.com/jonathanduke/ab4fc1880e8b245d3f939b122f301938#file-buildassemblyinfo-targets
Dependent on: https://gist.github.com/jonathanduke/ab4fc1880e8b245d3f939b122f301938#file-gitbuildprops-targets
Public domain: http://unlicense.org/
Modify as you wish, but you are encouraged to leave this comment for future reference in case the original is updated.
-->
<Project>
<Import Project="GitBuildProps.targets" />
@jonathanduke
jonathanduke / DriveImageXmlAttrib.xsl
Created August 6, 2020 15:24
This XSLT can be applied to a DriveImage XML file to create a batch file that will reapply the file attributes (hidden, system, read only, etc.) after extracting files from Browse mode.
<?xml version="1.0" encoding="utf-8"?>
<!--
Based on: https://gist.github.com/jonathanduke/27f440de0ddb764b88194771be4564e8#file-driveimagexmlattrib-xsl
Applies to: https://www.runtime.org/driveimage-xml.htm
Public domain: http://unlicense.org/
Modify as you wish, but you are encouraged to leave this comment for future reference in case the original is updated.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
@jonathanduke
jonathanduke / git-squash-history.sh
Last active January 27, 2021 21:52
Squash historical commits, leaving only the last 30 days of history, without harming the current worktree
###
## Based on: https://gist.github.com/jonathanduke/020d97409396e784a2db84f178c8b907#file-git-squash-history-sh
## Public domain: http://unlicense.org/
## Modify as you wish, but you are encouraged to leave this comment for future reference in case the original is updated.
###
# Use at your own risk! To make sure you know what you're doing, "origin" and "master" have been replaced with different names.
git checkout -B TEMPhead
git worktree add --checkout -B TEMPstart _TEMPworktree TEMPhead~30 # goes back 30 commits (or manually specify your own branch)
cd _TEMPworktree
@jonathanduke
jonathanduke / tsig.md
Last active June 1, 2022 12:42
Deferred Proof of Authorship using Digital Signatures and Blockchain Timestamps

Deferred Proof of Authorship using Digital Signatures and Blockchain Timestamps

by Jonathan Duke

Abstract. Suppose an author has created a document that he wants to publish anonymously, but at some point in the future he would like to have the option to prove both his identity and the time of creation. A digital signature can be used to sign the document's content, but there is no mechanism to prevent another person from spoofing the timestamp and signing their own version of the document to claim they are the original author. Using a public, permanent blockchain such as bitcoin could allow the author to augment the digital signature with a timestamp that could be proven to match the document signature. The signature and timestamp could be stored privately until the author wishes to claim ownership at a later date. This might be compared to a privately-held NFT.

1. Introduction

Will anyone ever prove the identity of [Satoshi Nakamoto](https

@jonathanduke
jonathanduke / ddwrt_nvram.cs
Created June 10, 2022 00:09
C# code to read a binary DD-WRT backup file and export commands to set the values on the router
// read a DD-WRT nvrambak_xyz.bin backup file and create "nvram set" commands FOR COMPARISON ONLY
// NOTE: some values may have issues, so you can't just copy and paste the whole output or it can mess up your router
// The format should be similar to processes to export from the router via the command line:
// https://gist.github.com/Aikhjarto/5b1c6b5e5d373d8d60c004e075b29acc
// https://gist.github.com/rambotech/d1e2486228c5e972c3c9c8936920f2fc
var set = new List<string>();
using var file = System.IO.File.OpenRead(args[0]);
var buffer = new byte[0xFFFF];
int len = 6;
int count = file.Read(buffer, 0, len);
@jonathanduke
jonathanduke / git-list-worktrees.bat
Last active September 7, 2023 20:22
List all Git worktrees recursively with the location of the repository (either a .git directory or the gitdir location specified in the .git file)
::::
:: Original source: https://gist.github.com/jonathanduke/92eac20fe8a85eff8e8840b5d56551f9#file-git-list-worktrees-bat
:: Public domain: http://unlicense.org/
:: Modify as you wish, but you are encouraged to leave this comment for future reference in case the original is updated.
::::
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=*" %%f in ('dir /a /s /b .git') do (
if exist "%%f\*" (
set "_dir=%%~dpf"
@jonathanduke
jonathanduke / int_range.dart
Last active January 18, 2024 20:30
Implementation for int.minValue and int.maxValue in Dart
// https://dartpad.dev/?id=dad879af094b27b24fd6070e1175e791
// Pending feature request: https://github.com/dart-lang/sdk/issues/41717
// Note: this requires Dart 2.14 and above (to support the >>> operator)
class IntRange {
// based on: https://stackoverflow.com/a/75928881
static const int maxValue = (-1 >>> 1);
static const int minValue = -1 - maxValue;
}
@jonathanduke
jonathanduke / ffmpeg.txt
Last active January 21, 2024 22:55
ffmpeg commands that I need to remember
# This is for converting a ripped movie to a 480p size so my kids can watch it on their tablets in the car.
# I'm cropping off 276 pixels from the top and bottom, which means it's a 3840x2160 image with a 2.39:1 letterboxed video.
# The width can vary based on the aspect ratio, but the height should always be 480px.
# I'm hard-coding it to use H.264 and yuv420p and to downmix surround sound to regular stereo channels.
# On some movies, I had to use -map 0:2 to get the 5.1 audio stream if the 7.1 was truehd and ffmpeg didn't like that.
ffmpeg -i "4k.mkv" -vf "crop=iw:ih-552:0:276,scale=1146:480" -c:v libx264 -c:a copy -ac 2 -sn -pix_fmt yuv420p -map 0:0 -map 0:2 -crf 18 -map_chapters -1 "480p.mp4"
# After getting the resolution right, follow this process to reduce the size of the video: https://trac.ffmpeg.org/wiki/Encode/H.264#twopass
ffmpeg -y -i original.mp4 -c:v libx264 -b:v 1000k -pass 1 -an -f null NULL && ffmpeg -i original.mp4 -c:v libx264 -b:v 1000k -pass 2 -c:a aac -b:a 128k shrink.mp4
import 'package:flutter/material.dart';
extension LocaleFallbackExtensions on Locale {
/// Look up the most specific version of a localized string, falling back through the BCP 47 language-script-region hierarchy.
String? getString(String? key, String? Function(String k) lookup) {
final prefix = key != null ? '${key}_' : "";
String? text;
if (null != (text = lookup('$prefix${toString()}'))) {
// full locale code (en_US, es_MX, fr_CA, zh_Hans_CN, zh_Hant_TW)