Skip to content

Instantly share code, notes, and snippets.

View csuhta's full-sized avatar
🔮
Afloat in the multiverse

Corey Csuhta csuhta

🔮
Afloat in the multiverse
View GitHub Profile
@robmathers
robmathers / readinglisturls.py
Last active November 16, 2023 21:18
Prints out URLs of items in Safari’s Reading List
#!/usr/bin/env python
import plistlib
from shutil import copy
import subprocess
import os
from tempfile import gettempdir
import sys
import atexit
BOOKMARKS_PLIST = '~/Library/Safari/Bookmarks.plist'
@jberkus
jberkus / gist:6b1bcaf7724dfc2a54f3
Last active January 7, 2024 21:26
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@sergejmueller
sergejmueller / ttf2woff2.md
Last active March 9, 2024 13:37
WOFF 2.0 – Learn more about the next generation Web Font Format and convert TTF to WOFF2
@0xabad1dea
0xabad1dea / singularthey.md
Last active June 18, 2022 18:01
Singular They in Technical English

Guidelines for Singular They in Technical English

by 0xabad1dea, December 2014

This document is an RFC of sorts for increasing the adoption rate of Singular They in technical English. This is not an ultimatum; this is not shaming anyone who has done otherwise; and this is definitely not applicable to any other language.

What is Singular They?

@0xabad1dea
0xabad1dea / banned.h
Last active December 27, 2015 19:46
banning macros
/* include this file AFTER your standard includes */
/* clang -Weverything -Wno-unused-macros */
/* SIGNED ARITHMETIC IS THE ENEMY. (use "signed" for main, etc.) */
#define int BANNED
/* THESE OTHER THINGS ARE ALSO THE ENEMY. */
#ifdef strcpy
#undef strcpy
#endif
#define strcpy BANNED
@nl5887
nl5887 / gpg-agent.conf
Last active November 14, 2022 09:37
Using GPG Agent on OS-X
launchctl unload -w -S Aqua /System/Library/LaunchAgents/gpg.agent.daemon.plist
launchctl load -w -S Aqua /System/Library/LaunchAgents/gpg.agent.daemon.plist
@will
will / postgres_types.rb
Created February 17, 2016 18:31
proper postgres types for rails
# config/initializers/postgres_types.rb
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES.tap do |t|
t[:primary_key] = "bigserial primary key"
t[:datetime] = "timestamptz"
t[:timestamp] = "timestamptz"
t[:string] = "text"
end
#!/usr/bin/env ruby
# Takes a directory and turns music in it to mp3s; deleting originals.
require 'find'
require 'fileutils'
# Find files
files = []
Find.find(ARGV.first) do |file|
require "rubocop"
module RuboCop
module Cop
module Lint
# This cop checks bad use of the Minitest `assert` method
#
# `assert` method's second argument is the error message when the
# first argument evals to false.
#

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.