Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import subprocess
import sys
def run_cmd(cmd):
return subprocess.check_output(cmd).decode("utf8").strip()

Quick and dirty Twitter API pricing analysis for [Thresholderbot]

Summary

Twitter's [new API pricing starts at $5,000 per month][pricing] to read 1 million tweets per month. According to our metrics, [Thresholderbot] read more than 15 million tweets per month on average over the last 12 full months of activity — and that estimate may be far too low if retweets are counted as 2 reads.

Tweets read by Thresholderbot every 30 days over the past year

@mccutchen
mccutchen / .envrc
Created November 3, 2022 14:06
Example direnv .envrc for Python projects that manages a local virtualenv that updates automatically when requirements.txt changes
#!/bin/bash
VENV_DIR=".venv"
REQUIREMENTS_HASH_FILE="$VENV_DIR/requirements.shasum"
REQUIREMENTS_HASH_FUNC="shasum"
REQUIREMENTS_HASH_VAL=$($REQUIREMENTS_HASH_FUNC requirements.txt | cut -d ' ' -f 1)
function reset_venv() {
rm -rf "$VENV_DIR"
@mccutchen
mccutchen / gcloud
Created March 31, 2022 21:22
gcloud — a wrapper that executes the gcloud CLI in a docker container, to avoid requiring a local installation.
#!/bin/bash
#
# A wrapper that executes the gcloud CLI in a docker container, to avoid
# requiring a local installation.
#
# Adapted from this helpful blog post:
# https://blog.scottlowe.org/2018/09/13/running-gcloud-cli-in-a-docker-container/
GCLOUD_SDK_TAG="312.0.0"
#!/usr/bin/env python3
import argparse
import subprocess
import sys
import urllib.parse
def main(env: str, services: [str]) -> int:
filters = [f"env:{env}"]
@mccutchen
mccutchen / github-graphql-examples.md
Last active September 24, 2024 06:36
A couple of ways to look up a GitHub pull request via the v4 GraphQL API

GitHub GraphQL API v4 Examples

Here are two queries that look up information about a pull request via GitHub's GraphQL API v4. The first looks up a pull request by number, the second looks up a pull request by ref (i.e. commit hash, branch name, tag name).

Why tho

While it is trivial to use the RESTful v3 API to look up a pull request by number, the GraphQL API is the only way to do the same thing for an arbitrary reference in a single HTTP request.

These took a bit of trial and error in the GitHub's GraphQL Explorer and various support threads to get right, so I'm putting them up here for posterity.

@mccutchen
mccutchen / Pulumi.test.yaml
Created November 25, 2020 23:18
Test case to reproduce odd pulumi/SQS interaction
config:
aws:region: us-east-2
pulumi:template: aws-go
@mccutchen
mccutchen / README.md
Created November 18, 2020 14:29
golang scoping surprise

golang scoping surprise

Here's a short snippet of code that demonstrates a surprising effect of golang's variable scoping rules. (This is maybe only surprising for me, with Python's scoping rules deeply ingrained in my brain.)

In the real world, this came up in the context of an HTTP middleware function, where state accumulated in surprising ways across multiple requests to the handler wrapped by the middleware.

#!/usr/bin/env python3
import subprocess
import sys
def run_cmd(cmd):
return subprocess.check_output(cmd).decode('utf8').strip()
@mccutchen
mccutchen / lookup-pull-request
Last active November 6, 2019 00:16
Proof-of-concept showing how to use GitHub's v4 GraphQL API to look up the pull request associated with an arbitrary commit
#!/usr/bin/env python3
import os
import sys
import requests
def run_query(api_token, query):
url = 'https://api.github.com/graphql'