Skip to content

Instantly share code, notes, and snippets.

View gnepud's full-sized avatar

Peng Du gnepud

  • Grenoble, France
View GitHub Profile
import React, { Component } from 'react'
import { TransitionGroup, CSSTransition } from 'react-transition-group'
import {
BrowserRouter as Router,
Switch,
Route,
Link,
Redirect
} from 'react-router-dom'
@clarkbw
clarkbw / redux-performance-mark.js
Last active February 8, 2024 05:03
A User Timing middleware for redux to create performance markers for dispatched actions
const timing = store => next => action => {
performance.mark(`${action.type}_start`);
let result = next(action);
performance.mark(`${action.type}_end`);
performance.measure(
`${action.type}`,
`${action.type}_start`,
`${action.type}_end`
);
return result;

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.

@Joris-van-der-Wel
Joris-van-der-Wel / build.sh
Last active March 3, 2023 14:47
GNU Solfege on OS X
# Download and extract from https://www.gnu.org/software/solfege/ for example "solfege-3.22.2.tar.gz"
brew install librsvg texinfo pygtk timidity
export PATH=`brew --prefix`/opt/gettext/bin:$PATH
export PKG_CONFIG_PATH=`brew --prefix`/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH
./configure
make
@hallettj
hallettj / Makefile
Last active December 10, 2023 13:32
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
# Makefile for transpiling with Babel in a Node app, or in a client- or
# server-side shared library.
.PHONY: all clean
# Install `babel-cli` in a project to get the transpiler.
babel := node_modules/.bin/babel
# Identify modules to be transpiled by recursively searching the `src/`
# directory.
@notheotherben
notheotherben / README.md
Last active September 9, 2021 07:50
Fix Postgres 9.x Sequences

PostgreSQL 9.x Sequence Fixing Script

This script is intended to automatically fix the sequence numbers for all tables in the current database.

This is accomplished through the use of the setval() command, which we provide with the next ID value we wish to make use of. We use the setval(sequence, number, is_called) overload and set is_called = false in conjunction with COALESCE(MAX + 1, 1) to ensure that, with an empty table, the next sequence value is 1 as expected.

@tcotav
tcotav / prom_nodex_coreos.md
Created April 18, 2016 19:44
Running Prometheus's node_exporter in Docker container for use with CoreOS nodes

ref: (prometheus/node_exporter#66)

docker pull prom/node-exporter
docker run -d -p 9100:9100 -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --net="host" prom/node-exporter -collector.procfs /host/proc -collector.sysfs /host/proc -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
@brennanMKE
brennanMKE / hero.ts
Last active April 1, 2024 16:16
Example of Mongoose with TypeScript and MongoDb
import * as mongoose from 'mongoose';
export let Schema = mongoose.Schema;
export let ObjectId = mongoose.Schema.Types.ObjectId;
export let Mixed = mongoose.Schema.Types.Mixed;
export interface IHeroModel extends mongoose.Document {
name: string;
power: string;
@shreyaskarnik
shreyaskarnik / Instructions.md
Last active March 24, 2023 15:35
Route Docker Logs to ELK Stack
  • With Docker 1.8.0 shipped new log-driver for GELF via UDP, this means that the logs from Docker Container(s) can be shipped directly to the ELK stack for further analysis.
  • This tutorial will illustrate how to use the GELF log-driver with Docker engine.
  • Step 1: Setup ELK Stack:
    • docker run -d --name es elasticsearch
    • docker run -d --name logstash --link es:elasticsearch logstash -v /tmp/logstash.conf:/config-dir/logstash.conf logstash logstash -f /config-dir/logstash.conf
    • Note the config for Logstash can be found at this link
    • docker run --link es:elasticsearch -d kibana
  • Once the ELK stack is up now let's fire up our nginx container which ships its logs to ELK stack.
  • LOGSTASH_ADDRESS=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' logstash)
  • `docker run -d --net=host --log-driver=gelf --log-opt gelf-address=u
@mattes
mattes / gist:a482deab3b1b3a2f1ddc
Created May 20, 2015 04:57
boot2docker top command
tce-load -wi ncurses
TERM=vt100 top -c