Skip to content

Instantly share code, notes, and snippets.


Aidan Feldman afeld

View GitHub Profile
afeld / rehearsals.rb
Created Nov 12, 2020
get rehearsals from calendar
View rehearsals.rb
# 1. gem install icalendar
# 2. get the Secret Address from Google Calendar:
# 3. modify the constants below
# 4. run `ruby rehearsals.rb`
require "icalendar"
require "csv"
START_FROM =, 1, 15)
View jest-nock.test.js
// ensures that there's a clean slate for each test, and that no real HTTP requests are made
const nock = require("nock");
beforeAll(() => {
// ensures no requests hit live APIs
beforeEach(() => {
afeld /
Last active Mar 19, 2020
running SQL against Google Sheets

Google Sheets has a QUERY function that can be used for writing SQL queries. It uses the Google Visualization API Query Language, which is unfortunately a pretty limited SQL dialect. A few options for writing more complex SQL queries:

  • Export to CSV and load into a database somewhere
    • Pros: Use whatever database you want
    • Cons: Have to re-export every time the data is updated
  • Load into BigTable
    • Pros: Automatically updates
    • Cons: Requires some Google Cloud setup
  • Load into Google Colaboratory ("Colab")
    • Pros: Very flexible, as you can use SQL, Pandas, or any other Python code/packages
afeld /
Created Mar 9, 2020
get all domains (record sets) from all zones in an account in AWS Route53
set -eo pipefail
aws route53 list-hosted-zones --query 'HostedZones[].Id' | \
jq -r '.[]' | sed 's/\/hostedzone\///' \
| \
xargs -I zone_id \
aws route53 list-resource-record-sets \
--hosted-zone-id zone_id \
afeld /
Last active Mar 28, 2019
run SAS script from UNIX command line

To use, put the script in a file on the machine you want to run SAS, then make it executable.

chmod +x

After that, you can use it to run SAS scripts:

afeld / MY_Exceptions.php
Created Feb 10, 2019
StackDriver reporting for PHP CodeIgniter
View MY_Exceptions.php
use Google\Cloud\ErrorReporting\Bootstrap;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Core\Report\SimpleMetadataProvider;
// application/core/MY_Exceptions.php
class MY_Exceptions extends CI_Exceptions {
public function __construct()
afeld /
Created Sep 17, 2018
get list of properties from a JSON Schema

Uses jq.

cat schema.json | \
  jq -r '[paths | join(".")] | .[]' | \
  grep 'properties\.\w\+$' | \
  sed 's/properties\.//g'

Example with this file:

afeld /
Created Jul 9, 2018
redact IP addresses in output

When running a command with output that will be publicly available, you may not want to show IP addresses. This might come up with output from a freemium continuous integration (CI) service like TravisCI or CircleCI, for example. Pipe output into the following command to redact the first three segments:

sed -E 's/[0-9]+\.[0-9]+\.[0-9]+\.([0-9]+)/███.███.███.\1/g'

The squares are the Unicode "full block" character. Example use:

$ ansible-playbook -i --list-hosts playbooks/test.yml | sed -E 's/[0-9]+\.[0-9]+\.[0-9]+\.([0-9]+)/███.███.███.\1/g'
afeld /
Last active Aug 22, 2018
ways to send me money
afeld / mocks.go
Created Feb 22, 2018
example mocking in Golang
View mocks.go
type APIClientIface interface {
CreateAccountInOrgUnit() bool
type RealAPIClient struct {}
func (ac RealAPIClient) CreateAccountInOrgUnit() bool {
// ...