Skip to content

Instantly share code, notes, and snippets.

View jalaziz's full-sized avatar

Jameel Al-Aziz jalaziz

  • Paradigm Connect
  • Los Angeles, CA
  • X @jalaziz
View GitHub Profile
@andreineculau
andreineculau / get-aws-cli-sts.js
Created December 22, 2017 10:55
fucking get aws-sdk-js to read your aws-cli assumed role
import aws from 'aws-sdk';
import fs from 'fs';
import ini from 'ini';
import path from 'path';
// compatibility with aws-cli
let cliCacheFolder = path.join(process.env.HOME, '.aws', 'cli', 'cache');
let awsProfile = process.env.AWS_PROFILE || process.env.AWS_DEFAULT_PROFILE;
if (awsProfile) {
try {

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.

@hochgi
hochgi / PartitionWith.scala
Last active March 6, 2022 11:48
akka-stream retry flow
package hochgi.util
package object collections {
/**
* `partition` and `map` combined.
* for a given collection, and a function from the collection elements to `Either[A,B]`,
* generates a tuple of 2 collections of types `A` and `B`
*
* @param xs the collection of elements
* @param f a function that convert an element to an `Either[A,B]`
@pzrq
pzrq / mro_exploration.py
Last active December 15, 2020 07:18
Better PyCharm mixin handling would make it far more useful for Django Class-Based Views, Managers, etc
# -*- coding: utf-8 -*-
"""
# usage: python mro_exploration.py
# https://github.com/pzrq/
Better PyCharm mixin handling would make it far more useful for
Django Class-Based Views, Managers, and in contexts others have identified
such as Werkzeug.
https://youtrack.jetbrains.com/issue/PY-7712
global
log logstash local0 #Change logstash to your naming
log-send-hostname
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
maxconn 4000
defaults
@suprememoocow
suprememoocow / raid.yml
Created April 28, 2014 16:32
Setup and initialise a RAID10 array of EC2 EBS volumes using an Ansible playbook
- action: ec2_facts
- apt: pkg=lvm2 state=present
- apt: pkg=mdadm state=present
- pip: name=boto state=latest
- ec2_vol: instance="{{ hostvars[inventory_hostname]['ansible_ec2_instance-id'] }}"
volume_size=20
device_name="{{ item }}"
To get started with Docker/Marathon/Mesos, you need to install a
new Mesos, a new Marathon, and Deimos, the bridge to Docker.
You'll also need Docker and the JVM. These instructions are for
Ubuntu 13.10.
## Install Mesos prerequisites
:; sudo apt-get update
:; sudo apt-get install zookeeperd default-jre python-setuptools python-protobuf curl pip
## Install recent Mesos
@solidsnack
solidsnack / syslogged
Created July 26, 2013 18:08
Wrapper for logging any command's STDOUT and STDERR to syslog.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<EOF
USAGE: syslogged <program> <args>
Wraps a command invocation with logging, sending STDOUT and STDERR to
syslog, setting the syslog tag to:
<program>[<pid>]
@algal
algal / nginx-cors.conf
Created April 29, 2013 10:52
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@rcrowley
rcrowley / whisper-clean.py
Created July 20, 2012 23:35
Clean up Whisper files that no longer map to this host.
import os
import os.path
import sys
from graphite.render.hashing import ConsistentHashRing
instances = []
unwelcome_instances = []
for arg in sys.argv[1:]:
unwelcome = False