Skip to content

Instantly share code, notes, and snippets.

View aasmith's full-sized avatar

Andrew A Smith aasmith

View GitHub Profile
@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
@aasmith
aasmith / nested-json.sh
Created September 19, 2017 21:23
How to decode nested json with jq
# Typical use-case is decoding an AWS STS message. The DecodedMessage key contains escaped JSON.
jq '.DecodedMessage | fromjson | .' message.json
@aasmith
aasmith / ec2-private-ip.sh
Last active May 20, 2017 16:04
Get the private IP address of an EC2 instance
aws ec2 describe-instances --instance-ids <id> --output text --query 'Reservations[*].Instances[*].PrivateIpAddress'
@aasmith
aasmith / .curlrc
Created May 10, 2017 05:37
.curlrc
# print timings after each call. Use curl -q to suppress this file.
write-out = "%{http_code} ns:%{time_namelookup} conn:%{time_connect} appconn:%{time_appconnect} prexfr:%{time_pretransfer} rdr:%{time_redirect} ttfb:%{time_starttransfer} TOTAL:%{time_total}\n"