Skip to content

Instantly share code, notes, and snippets.

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

Brad Howes bradhowes

🏠
Working from home
View GitHub Profile
@bradhowes
bradhowes / mattermost3.py
Created June 8, 2017 12:51
Simple Python 3 Performance Test Script
import asyncio
import websockets
import json
import pickle
import sys
import multiprocessing
import random
import time
from collections import deque
@bradhowes
bradhowes / noPlay.py
Last active July 24, 2017 17:58
Locate albums in iTunes with a low aggregate play count (Python 2)
import plistlib, sys
from pprint import pprint
delimiter = '~'
def scan(srcRoot, playLimit):
albumMap = {}
for trackId, attributes in srcRoot['Tracks'].iteritems():
albumName = attributes.get('Album')
artistName = attributes.get('Album Artist')
#!/bin/bash
#
# Custom mapping for Apple MacBookPro 2017 keyboard.
#
# - Map §/± (SECTION) to `/~ (BACKQUOTE) to match US keyboard
# - Map CAPS LOCK (LOCK) to SHIFT (L_SHIFT) to locking
# - Map right CMD (R_CMD) to CAPS LOCK to enable locking if really wanted
# - Map `/~ to (BACKQUOTE) to SHIFT (L_SHIFT) to make SHIFT-^ easier
#
# To run at startup:
@bradhowes
bradhowes / bump-version.sh
Last active December 6, 2023 07:51
Bash script to increase build number and optionally marketing version of Xcode targets using Apple's `agvtool`
#!/bin/bash
#
# Script to bump the build number and optionally the marketing version found
# in *.info files.
#
# Usage: bump-version.sh [ARG]
#
# Without ARG, just increment the build number. When ARG is present, it indicates
# which part of the marketing version to increment:
#
@bradhowes
bradhowes / async_remarkable.js
Last active April 11, 2020 15:50
Enable async render operations on Remarkable
// Snippets from my build.js script for my static site generator. Shows how I handle async render operations
// during the Remarkable render operation.
//
const md = new Remarkable("full", markdownOptions).use(katexPlugin).use(require("./consoleFence.js"));
// My own custom codeFence processing for static highlighting using Prism.
md.renderer.rules.fence = require("./codeFence.js");
md.renderer.rules.fence_custom.graph = require("./graphFence.js");
md.renderer.promises = {};
md.renderer.addPromise = (key, promise) => {
@bradhowes
bradhowes / AUParameterTree+SwiftUI.playground
Last active September 28, 2024 04:37
Swift playground that integrates a @published attribute and a AUParameter instance, allowing changes in either to affect the other.
import SwiftUI
import AVFoundation
import PlaygroundSupport
class Model: ObservableObject {
@Published var value: Double = 5.0 // sole source of truth
}
class ParamTree {
static let address: AUParameterAddress = 123
@bradhowes
bradhowes / RepeatButton.playground
Last active January 16, 2021 11:53
Xcode playground showing SwiftUI custom button that repeatedly fires an action while touched
import SwiftUI
import PlaygroundSupport
class Model: ObservableObject {
@Published var value: Double = 5.0
}
struct RepeatButton: View {
private let title: String
private let systemImage: String
@bradhowes
bradhowes / sawsbuck.swift
Last active November 18, 2021 15:55
Swift Expression Parsing
// Demo using https://github.com/nicklockwood/Expression to parse
// https://www.wolframalpha.com/input/?i=Sawsbuck+Winter+Form%E2%80%90like+curve
import Foundation
import Expression
let Xt = "((-2/9 * sin(11/7 - 4 * t) + 78/11 * sin(t + 11/7) + 2/7 * sin(2 * t + 8/5) + 5/16 * sin(3 * t + 11/7) + 641/20) * θ(107 * π - t) * θ(t - 103 * π) + (-1/40 * sin(10/7 - 48 * t) - 1/20 * sin(32/21 - 47 * t) - 1/75 * sin(9/7 - 44 * t) - 1/10 * sin(35/23 - 41 * t) - 1/8 * sin(23/15 - 33 * t) - 1/13 * sin(38/25 - 30 * t) - 2/11 * sin(23/15 - 27 * t) - 1/7 * sin(14/9 - 23 * t) - 3/14 * sin(20/13 - 22 * t) - 1/5 * sin(17/11 - 19 * t) - 1/9 * sin(38/25 - 18 * t) - 1/13 * sin(14/9 - 13 * t) - 9/8 * sin(17/11 - 12 * t) - 3/10 * sin(11/7 - 11 * t) - 5/7 * sin(14/9 - 9 * t) - 6/7 * sin(17/11 - 6 * t) - 5/7 * sin(11/7 - 5 * t) - 131/15 * sin(11/7 - 3 * t) + 166/11 * sin(t + 11/7) + 82/13 * sin(2 * t + 11/7) + 5/4 * sin(4 * t + 11/7) + 7/15 * sin(7 * t + 33/7) + 23/22 * sin(8 * t + 11/7) + 7/5 * sin(10 * t + 19/12) + 1/2 * sin(14
@bradhowes
bradhowes / Arithmetic.swift
Created November 24, 2021 22:07
Math expression parsing using Point-Free's swift-parsing library. Expands on code found in the infix-operator branch.
import Parsing
import XCTest
import Foundation
#if canImport(Darwin)
import Darwin.C
#elseif canImport(Glibc)
import Glibc
#endif
@bradhowes
bradhowes / code_coverage.md
Created December 21, 2021 18:00
Github Action for Swift Code Coverage
  1. Create a Github action for your SwiftPM project.
  2. Add a step to build: swift build
  3. Add a step to run tests: swift test --enable-code-coverage
  4. Fetch coverage value (see below)
  5. Write coverage value to gist and generate badge from it

For step #4, we need to do some sleuthing and digging around into artifacts created by the Swift toolchain. First, we need to find the location of the XCTest bundle that step #3 generated and save it in an environment variable: