Skip to content

Instantly share code, notes, and snippets.

View aabs's full-sized avatar

Andrew Matthews aabs

View GitHub Profile
@idelem
idelem / titleUrlMarkdownClip.js
Last active March 12, 2024 02:01 — forked from bradleybossard/titleUrlMarkdownClip.js
Bookmarklet to copy current page title and url in Markdown format to clipboard, like [title](url) - Usual for posting links to resources in README.md files
javascript:(function() {
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
/*IE specific code path to prevent textarea being shown while dialog is visible.*/
return clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
@nicbet
nicbet / Dockerfile
Created June 27, 2019 03:00
Elixir 1.9 Releases Alpine Linux Docker Multi-Stage Build
# ---- Build Stage ----
FROM erlang:22-alpine AS app_builder
# Set environment variables for building the application
ENV MIX_ENV=prod \
TEST=1 \
LANG=C.UTF-8
# Fetch the latest version of Elixir (once the 1.9 docker image is available you won't have to do this)
RUN set -xe \
@ahsonkhan
ahsonkhan / ArrayBufferWriter.ArrayPool.cs
Created January 29, 2019 01:11
Sample implementation of ArrayBufferWriter, a class that implements IBufferWriter<byte> backed by ArrayPool<byte>.Shared.
public class ArrayBufferWriter : IBufferWriter<byte>, IDisposable
{
private byte[] _rentedBuffer;
private int _written;
private long _committed;
private const int MinimumBufferSize = 256;
public ArrayBufferWriter(int initialCapacity = MinimumBufferSize)
{
@bicycle1885
bicycle1885 / vimrc
Last active July 22, 2020 02:37
My vimrc
" General
syntax enable
set nocompatible
set noswapfile
if executable("rg")
set grepprg=rg\ --vimgrep\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
autocmd QuickFixCmdPost * copen
nnoremap <silent> <C-n> :cn<CR>
@andrwj
andrwj / .vimrc
Created November 10, 2017 04:11
vimrc
"Initialization {{{
set nocompatible
let mapleader = '\'
" }}}
"Loading Vundle Plugins: {{{
filetype on
set rtp+=~/.vim/bundle/Vundle.vim
set runtimepath+=~/.vim/bundle/ctrlp.vim
set runtimepath+=~/.vim/bundle/dart-vim-plugin
# ASCII Unit separator, purpose is to separate subrecords, etc...
set __assoc_US \31
# Groks name[key] and sets varname and key variables
function assoc._parsename -S -a raw
set -l data (string match -r '(.+)\[(.+)\]' $raw)
if [ (count $data) -lt 3 ]
echo "Invalid assocatiave array specification '$raw'"
return 1
else
{config,pkgs,...}:
let
myVim = pkgs.vim_configurable.customize {
name = "vim";
vimrcConfig = {
customRC = ''
syntax on
set nu
set foldmethod=syntax

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.

@manveru
manveru / configuration.nix
Last active July 26, 2020 23:41
Updating vim plugins for nix
{ pkgs }:
let plugins = pkgs.callPackage ./plugins.nix {};
in {
customRC = ''${builtins.readFile ./vimrc}'';
vam = {
knownPlugins = pkgs.vimPlugins // plugins;
pluginDictionaries = [{
names = [
"Tagbar"
"css-pretty"