Skip to content

Instantly share code, notes, and snippets.

View alissonsales's full-sized avatar

Alisson Sales alissonsales

  • Wellington, New Zealand
View GitHub Profile
@alissonsales
alissonsales / redis-protocol-awk
Last active August 7, 2018 03:54
Redis protocol in awk
awk '{ print "*" NF "\r"; for(i = 1; i <= NF; i++) { print "$" length($i) "\r\n" $i "\r" } }'

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.

@ursuad
ursuad / kafka-cheat-sheet.md
Last active July 22, 2024 08:40
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

@anildigital
anildigital / gist:862675ec1b7bccabc311
Created July 26, 2014 18:27
Remove dangling docker images
docker rmi $(docker images -q -f dangling=true)
@mogya
mogya / app.js
Created September 29, 2012 17:53
[titanium] webview which open any url on the web browser
var win = Titanium.UI.createWindow({
navBarHidden : true,
exitOnClose:true
});
var webView = Ti.UI.createWebView({
width:'100%'
});
webView.addEventListener('beforeload',function(e){
if (e.url.match(/^file:\/\//) ){
@trcarden
trcarden / gist:3295935
Created August 8, 2012 15:28
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@kesselborn
kesselborn / create_lxc.sh
Created August 26, 2011 09:58
creates a simple lxc container and starts bash in it
#!/bin/bash
# creates a simple lxc container and starts bash in it
# ... steps from tutorial on:
# http://www.phenona.com/blog/using-lxc-linux-containers-in-amazon-ec2/
if [ "$(whoami)" != "root" ]
then
echo "script must be executed as root!"
exit 1
fi
@rpak
rpak / Environment.m
Created June 17, 2011 22:46
Sample code for a Singleton that provides configuration or environment data
#import "Environment.h"
@implementation Environment
static Environment *sharedInstance = nil;
@synthesize myApiURL;
- (id)init
{