Skip to content

Instantly share code, notes, and snippets.

View jrevillas's full-sized avatar
💭
Hey there! I am using WhatsApp.

Javier Revillas jrevillas

💭
Hey there! I am using WhatsApp.
View GitHub Profile
@mildsunrise
mildsunrise / fnmt_handle.py
Last active September 19, 2023 09:11
🔐 Open source implementation of FNMT's certificate configurator v1.0.1 (https://twitter.com/mild_sunrise/status/1585611873860440067)
#!/usr/bin/env python3
'''
Open source implementation of FNMT's certificate configurator v1.0.1
<https://www.sede.fnmt.gob.es/descargas/descarga-software/instalacion-software-generacion-de-claves>
No warranty provided; use this ONLY if you know what you're doing.
Usage: ./fnmt_handle.py <fnmtcr URL>
Fulfills the request indicated by the URL, sending request to answer operation as completed if there are no errors.
For the fnmtcr://request phase, the generated private key is written to "privkey.pem" in current directory.
@gordonmurray
gordonmurray / aws_ecs_cluster.sh
Last active November 24, 2019 11:26
Create an AWS ECS Cluster
# Moved to a Repo here instead and added some additional files
https://github.com/gordonmurray/ecs_cluster_using_aws_cli

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.

@divan
divan / main.go
Created March 21, 2017 15:01
Golang database/sql+http example (postgres)
// Run PostgreSQL server:
// docker run -e POSTGRES_PASSWORD="" -p 5432:5432 postgres
// Monitor running processes:
// watch -n 1 'echo "select pid,query_start,state,query from pg_stat_activity;" | psql -h localhost -U postgres
//
// For all handlers, call to db takes 5 seconds,
//
// Three endpoints:
// - "/" - take 5 seconds
// - "/ctx" - take 1 seconds, due to 1 second cancellation policy
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@akutz
akutz / README.md
Last active March 3, 2019 18:31
Testing TCP Endpoints with Go

This gist demonstrates how to test the availability of a TCP endponit using Golang. The following example checks if an endpoint is available and responding to both TCP and TLS connections. To run the example, simply open a command line and execute the following:

$ curl -sSL https://goo.gl/ENx9d8 > tcp-tls-ping.go && go run tcp-tls-ping.go
tcp success
tls success

The program shows that the specified endpoint (defaults to google.com:443) is available and responding to TCP and TLS connection attempts. To illustrate the error that occurs when an endpoint presents an invalid TLS certificate, execute the following:

@kekru
kekru / Docker connect to remote server.md
Last active June 14, 2024 09:00
Connect to another host with your docker client, without modifying your local Docker installation

Run commands on remote Docker host

This is how to connect to another host with your docker client, without modifying your local Docker installation or when you don't have a local Docker installation.

Enable Docker Remote API

First be sure to enable the Docker Remote API on the remote host.

This can easily be done with a container.
For HTTP connection use jarkt/docker-remote-api.

Kafka installation with systemd

0. Create kafka user

sudo adduser kafka
sudo adduser kafka sudo
su -l kafka

1. Download and Install kafka archive