Skip to content

Instantly share code, notes, and snippets.

View afeld's full-sized avatar

Aidan Feldman afeld

View GitHub Profile
@afeld
afeld / toggl.py
Created January 27, 2024 17:04
setting Toggl entries to billable
# didn't seem to work, but saving here in case it's useful to others
import requests
from base64 import b64encode
workspace_id = 67337
project_id = 190841872
headers = {
"content-type": "application/json",
"Authorization": "Basic %s"
@afeld
afeld / rates.csv
Last active November 21, 2022 15:06
freelance rates
Client type Hourly rate Day rate
Government/education/non-profit $200 $1,500
For-profit $250 $1,850
@afeld
afeld / sample.py
Last active November 5, 2021 15:20
reduce size of CSV with pandas
import pandas as pd
# maintain the original data format by reading everything as strings
original = pd.read_csv("original.csv", dtype="object")
# set the random_state so it's reproducible. alternatively, can pass a `frac` to use a percentage.
sampled = original.sample(n=5000, random_state=1).sort_index()
# exclude the index so the columns match the orignal
@afeld
afeld / rehearsals.rb
Last active July 27, 2024 23:48
get rehearsals from calendar - moved to https://github.com/afeld/rehearsals
# 1. `gem install icalendar`
# 2. Get the "Secret adddress in iCal format" from Google Calendar: https://support.google.com/calendar/answer/37083#link
# 3. Open that URL in a browser to download the .ics file
# 3. Modify the constants below
# 4. Run `ruby rehearsals.rb`
require "icalendar"
require "csv"
START_FROM = DateTime.new(2023, 4, 25)
@afeld
afeld / jest-nock.test.js
Created September 29, 2020 06:14
Jest+Nock setup
// 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
nock.disableNetConnect();
});
beforeEach(() => {
@afeld
afeld / README.md
Last active March 19, 2020 14:44
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
afeld / domains.sh
Created March 9, 2020 21:09
get all domains (record sets) from all zones in an account in AWS Route53
#!/bin/bash
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
afeld / README.md
Last active March 28, 2019 20:11
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 run_sas.sh

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

./run_sas.sh myscript.sas
@afeld
afeld / MY_Exceptions.php
Created February 10, 2019 08:20
StackDriver reporting for PHP CodeIgniter
<?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
afeld / README.md
Created September 17, 2018 16:42
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: