Skip to content

Instantly share code, notes, and snippets.

View aasmith's full-sized avatar

Andrew A Smith aasmith

View GitHub Profile
@aasmith
aasmith / NumberConverter.java
Created February 12, 2025 03:19
BSD number.c in Java
/*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@aasmith
aasmith / VolumeStepping.ahk
Created January 22, 2025 01:54
Change Windows volume in larger increments using AutoHotKey
#Requires AutoHotkey v2.0
; Changes volume up and down by 10% instead of 2% when using volume up/down media keys
$Volume_Up:: ; Use $ to prevent an infinite loop because we send the keypress through
{
Send "{Volume_Up}" ; Send one keypress through in order to show the volume HUD
SoundSetVolume "+8"
}
@aasmith
aasmith / CommonsRngSamplerTest.java
Last active January 3, 2025 04:15
Benchmark of JDK17 RandomGenerator & Commons RNG 1.6 algorithms
package org.tinnedfruit.microbenchmarks;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.ArraySampler;
import org.apache.commons.rng.sampling.ListSampler;
import org.apache.commons.rng.simple.RandomSource;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
@aasmith
aasmith / instructions.md
Last active March 7, 2024 02:32
Add extra resolutions to your AirPrint printer

Recent versions of MacOS heavily favour AirPrint as the driver. These can lack extra options, such as resolution.

When printing, the Print Dialog will typically show "Normal" as the only option. This can be found under the "Media & Quality" section of the Print Dialog.

If you know your printer has a higher resolution, follow these steps to add it:

  1. Obtain the actual resolution from the manual. Mine says "HQ1200" which is actually 2400x600dpi.
  2. Run lpstat -a to get a list of printers.
  3. Run lpoptions -d printername -l to show the options. Mine has just a single resolution:
@aasmith
aasmith / pps.sh
Created September 15, 2021 19:28
Linux interface bytes per second using only /proc
#!/bin/bash
time="1" # one second
int="eth1" # network interface
while true
do
txbytes_old="`cat /sys/class/net/$int/statistics/tx_bytes`" # sent bytes
rxbytes_old="`cat /sys/class/net/$int/statistics/rx_bytes`" # recv bytes
sleep $time
@aasmith
aasmith / gdd.rb
Created April 30, 2020 01:37
Calculate Growing Degree Days (GDD) in ruby
# Calculates Growing Degree Days (GDD) using generally-accepted methods
# defined by the Division of Agriculture and Natural Resources, University
# of California [1].
#
# The single-sine method seems to be the defacto way of determining a GDD [2].
#
# The triangulation methods are originally from [3] and are used to correct
# a transcription error in [1].
#
#
@aasmith
aasmith / ghcn.rb
Last active April 26, 2020 03:00
Fetch and parse NOAA GHCN-Daily historical weather data
# find a weather station code via https://www.ncdc.noaa.gov/cdo-web/search?datasetid=GHCND
#
# Example:
#
# ```
# g = Ghcn.new("USW00094290")
# g.fetch
# data = g.parse
# ```
#
@aasmith
aasmith / Gemfile
Last active January 23, 2020 00:13
Ruby URI Benchmark
# frozen_string_literal: true
source "https://rubygems.org"
gem "addressable"
gem "uri_parser", github: "aasmith/uri_parser", branch: "master"
gem "benchmark-ips"
@aasmith
aasmith / node.def
Last active December 1, 2019 22:36
Set custom sshd listen-address with ip:port on Vyatta / EdgeOS
# Replace /opt/vyatta/share/vyatta-cfg/templates/service/ssh/listen-address/node.def
multi:
type: txt
help: Local addresses SSH service should listen on
val_help: ipv4: IP address to listen for incoming connections
val_help: ipv6: IPv6 address to listen for incoming connections
val_help: any; IP address with port, ip:port
create: sudo sed -i -e '/^Port/a \
ListenAddress $VAR(@)' /etc/ssh/sshd_config
@aasmith
aasmith / activate-target.sh
Created February 12, 2018 04:12
Place an instance exclusively into an AWS LB Target Group
#!/bin/bash
set -euo pipefail
function log {
echo "$(date +%T): $@"
}
tgname=$1
iid=$2