Skip to content

Instantly share code, notes, and snippets.

View avkosme's full-sized avatar
👨‍💻
in k8s clouds

Andrei Kostiuchenko avkosme

👨‍💻
in k8s clouds
View GitHub Profile
@avkosme
avkosme / gist:be7ebbaf11c5a80fc4c8b8fdca2e6675
Created December 4, 2023 06:40
Curl show total time http
curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://example.com/
SELECT
table_name,
column_name,
data_type
FROM
information_schema.columns
WHERE
table_name = '<table name>';
openssl rsa -in privkey.pem -out privkey.key
export GOOS=linux
export GOARCH=arm64
go build -o bin/main cmd/main.go
go tool dist list
go tool dist list | grep linux
tcpdump port 3001 -v -nn
kill -9 $(ps aux | grep 'fast' | awk '{print $2}')
SELECT * FROM pg_stat_activity;
@avkosme
avkosme / search_count
Last active January 30, 2023 18:16
Search files, count
# Recursive search
find . -type f -name '*.log' -printf x | wc -c
# Non-recursive search
find . -maxdepth 1 -type f -name '*.log' -printf x | wc -c
# Delete by .ext
find /path/ -maxdepth 3 -type f -name "*.xlsx" -delete
@avkosme
avkosme / clean.sh
Created January 9, 2023 04:29
Remove the one table from big sql dump file
#!/bin/bash
# https://stackoverflow.com/questions/19653245/use-ignore-table-with-mysql-while-execute-sql-file
sed '/INSERT INTO `big_log`/ d' ${1} > dumpLog

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.