Skip to content

Instantly share code, notes, and snippets.

View richardtallent's full-sized avatar
🏠
Working from home

Richard Tallent richardtallent

🏠
Working from home
View GitHub Profile
@richardtallent
richardtallent / numoff.sh
Created November 22, 2023 22:46
Numlock Off for Mac
#!/bin/sh
# This makes OS X treat numpad 1-9 as if NumLock is off.
# Reference: https://developer.apple.com/library/archive/technotes/tn2450/_index.html
hidutil property --set '{"UserKeyMapping":[
{"HIDKeyboardModifierMappingSrc":0x700000059,"HIDKeyboardModifierMappingDst":0x70000004D},
{"HIDKeyboardModifierMappingSrc":0x70000005A,"HIDKeyboardModifierMappingDst":0x700000051},
{"HIDKeyboardModifierMappingSrc":0x70000005B,"HIDKeyboardModifierMappingDst":0x70000004E},
{"HIDKeyboardModifierMappingSrc":0x70000005C,"HIDKeyboardModifierMappingDst":0x700000050},
{"HIDKeyboardModifierMappingSrc":0x70000005E,"HIDKeyboardModifierMappingDst":0x70000004F},
{"HIDKeyboardModifierMappingSrc":0x70000005F,"HIDKeyboardModifierMappingDst":0x70000004A},
@richardtallent
richardtallent / eslint-package-json.js
Last active February 27, 2024 15:40
Example eslint config in a package.json
"prettier": {
"useTabs": true,
"semi": false,
"singleQuote": false,
"bracketSpacing": true,
"trailingComma": "es5",
"printWidth": 160
},
"eslintConfig": {
"parserOptions": {
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GroupName</key>
<string>_www</string>
<key>InitGroups</key>
<true/>
<key>KeepAlive</key>
<true/>
#!/bin/bash
# The intent of this script is to search for photos you've tagged and create optimized versions
# of them in a particular folder (with subfolders for each tag). You can then set iTunes to sync
# your phone's Photos app to this folder, allowing you to easily carry around some albums
# (separate from your camera roll, Photostream, or other cloud folders). I created this as a way
# to ensure that both my phone and my wife's have consistent, offline copies of our favorite family
# photos. We use different Mac computers but have a shared drive with family photos, so I needed a
# solution that allows either of us to flag photos. Once set up, adding photos to your phone is as
# simple as adding a tag to the photo in Finder and re-running the script (which can be set to run
@richardtallent
richardtallent / Base16384.cs
Created July 20, 2016 03:56
Integer Encoding in Base 16384
// Encodes a positive integer (or 0) in Base 2^14, using the Unicode CJK Unified Ideographs block as digits.
// This is a silly thing to do, but has a particular use case.
// Blog post here: http://blog.tallent.us/?p=368
public static int FromBase16384(this string value) {
if(string.IsNullOrEmpty(value)) throw new ArgumentException();
int letter;
int letterBase = 1;
int iout = 0;
for(var x = 0; x < value.Length; x++) {
@richardtallent
richardtallent / ValidateCASRN.vb
Last active February 2, 2016 19:33
Validates CAS Registry Numbers for length and checksum. Intended to be used in Excel for data validation.
' This is a quick VBA function to validate CAS Registry Numbers for length and checksum.
' It does not check the location of the dashes, and will fail if non-digits are included.
' Spaces are ignored. Blanks can either be allowed or not, depending on your use case.
' https://en.wikipedia.org/wiki/CAS_Registry_Number
' Usage: Debug.Print ValidateCAS("7732-18-5")
Public Function ValidateCASRN(ByVal CAS As String, Optional ByVal allowBlank As Boolean = False) As Boolean
Application.Volatile False
Dim numDigits As Integer
@richardtallent
richardtallent / RT.ResultT.cs
Created December 29, 2015 03:16
Special-purpose tuple for returning both a value and status from a function in C#
namespace RT {
/// <summary>
/// Generic, yet more expressive mechanism for returning both a value and a status from a function.
/// Nothing earth-shattering, just syntactic sugar and logic to create an immutable struct with
/// minimal effort.
///
/// Usage:
/// return Result<foo>.Succeeded(myFoo); // returned foo is good
/// return Result<foo>.Failed(); // unsuccessful, no foo to return