Skip to content

Instantly share code, notes, and snippets.

Rgate is a simple API Gateway which routes HTTP traffic to configured upstreams.

For example, given the below config:

rgate:
  routes:
    - path_prefix: /public-api/posts
      backend: https://gorest.co.in
  default_response:
 body: "This is not reachable"

create a slackbot to fetch text events from an internal api and send it to a dedicated slack channel

slack bot api can be found from:

https://slack.dev/python-slack-sdk/web/index.html#messaging

our internal api has two endpoints:

  1. /api/events/latest (a GET api to get a list of latest events, not acked)

create a slackbot to fetch text events from an internal api and send it to a dedicated slack channel

slack bot api can be found from:

https://slack.dev/python-slack-sdk/web/index.html#messaging

our internal api has two endpoints:

  1. /api/events/latest (a GET api to get a list of latest events, not acked)
@fivesheep
fivesheep / histogram.go
Created April 13, 2019 00:15
promethues histograms with negative bounds
package main
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"io/ioutil"
"log"
"math/rand"
"net/http"
@fivesheep
fivesheep / .block
Created May 20, 2018 06:54 — forked from mbostock/.block
Line Transition
license: gpl-3.0
@fivesheep
fivesheep / understanding-word-vectors.ipynb
Created March 2, 2018 21:27 — forked from aparrish/understanding-word-vectors.ipynb
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fivesheep
fivesheep / watchdog.md
Created October 31, 2017 19:07 — forked from Spindel/watchdog.md
Showing off the systemd watchdog in Python

Watchdogged

Place the service file (or a link to it) in /etc/systemd/system/ Place the watchdogged.py file somewhere ( and change the ExecStart portion in the .service to point at the file )

then do systemctl daemon-reload followed by systemctl start watchdogged.service

After this you can watch the progress using journalctl --follow -u watchdogged.service change the PROBABILITY variable to something else to watch it faster/later or succeed.

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.

@fivesheep
fivesheep / CachingSingletonAppender .java
Created November 3, 2016 17:29 — forked from kengelke/CachingSingletonAppender .java
A custom log appender for log4j that allows one to catch log messages generated by log4j from within the application.
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.log4j.spi.LoggingEvent;
public class CachingSingletonAppender {
private static final CachingSingletonAppender theInstance = new CachingSingletonAppender();
private List<LogEventListener> listeners;
private List<LogEvent> eventCache;
@fivesheep
fivesheep / springer-free-maths-books.md
Created December 28, 2015 23:15 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links