Skip to content

Instantly share code, notes, and snippets.

View pinkerton's full-sized avatar

Stephen Pinkerton pinkerton

View GitHub Profile
@nadavrot
nadavrot / Matrix.md
Last active July 1, 2024 17:31
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

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.

@mcescalante
mcescalante / .tmux.conf
Created November 8, 2016 21:07
My OSX/macOS tmux configuration, tested on 10.11.x
#allow mousing
set -g mouse-utf8 on
set -g mouse on
# Return pre-2.1 mousing behaviour
# https://github.com/tmux/tmux/issues/145
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
# Use vim keybindings in copy mode
@waldher
waldher / gist:5453355
Created April 24, 2013 16:09
NodeJS code for using UNIX sockets at 'tmp/socket' for production environments, and port 3000 for development.
var listenOn = 3000;
if(process.env.NODE_ENV == 'production'){
listenOn = "tmp/socket";
}
var startServer = function(){
app.listen(listenOn, undefined, undefined, function(){
console.log("Listening on " + listenOn);
if(typeof(listenOn) == 'string'){
fs.chmod(listenOn, 0777);
@DanGe42
DanGe42 / server.sh
Last active December 16, 2015 07:39
Python "one-liner" to start a server to serve static files from a directory
# Start an HTTP server from a directory, optionally specifying the port
function server() {
# Default to port 8000
local port="${1:-8000}"
# Since the one-liner blocks, we open the browser beforehand. However, we want to
# wait just a couple of seconds since the server will not be ready just yet.
# Also, I think Linux users should be able to use 'xdg-open' ('open' is for OS X).
( sleep 2; open "http://localhost:${port}/" ) &
# -------------- netcatlib.py -----------------------------------
import socket
class Netcat:
# TODO: ip and port should be optionaly, and an open() method should be added
# TODO: specify a timeout argument as well?
def __init__(self, ip, port):
self.buff = ""
self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.soc.connect((ip, port))
@jgrahamc
jgrahamc / slide10.go
Last active December 15, 2015 12:48
The code associated with this talk: http://www.slideshare.net/jgrahamc/go-oncurrency
func worker(die chan bool) {
for {
select {
// ... do stuff cases
case <- die:
return
}
}
}
@Nurdok
Nurdok / python_conversion.md
Last active December 16, 2022 03:45
Python Conversion

Python Number Conversion Chart

From To Expression
@soffes
soffes / perferences.json
Created August 22, 2012 05:35
My Sublime Text 2 config
{
"bold_folder_labels": true,
"color_scheme": "Packages/User/Espresso Soda.tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".gitkeep",
"dump.rdb"
],
@jonsterling
jonsterling / Tasky.py
Created August 19, 2012 01:23
A very simple curses-style TaskWarrior client
#!/usr/bin/python
# -*- coding: latin-1 -*-
import urwid
import json
import subprocess
class TaskWarrior(object):
def pending_tasks(self):