Skip to content

Instantly share code, notes, and snippets.

View atitan's full-sized avatar
🍡

Sh Lin atitan

🍡
View GitHub Profile
@atitan
atitan / haproxy_ssl_request_passthrough_ver2.txt
Created August 7, 2024 16:12 — forked from hxyconan/haproxy_ssl_request_passthrough_ver2.txt
Haproxy configuration for SSL request passthrough to different backend based on SNI
# Haproxy configuration for SSL request passthrough to different backend based on SNI read from Handshaking stage
# The Loadbalance will not decode the encrpted data but transparently transfer to the backend server in Private subnet.
# With such configuration, you can install multiply services with its own SSL certificate in backend in different EC2 instance, but only explosure to public internet with one Loadbalance IP. There is no need to install SSL certificate in Loadbalancer level.
# Ref:
# How to support wildcard sni: https://stackoverflow.com/questions/24839318/haproxy-reverse-proxy-sni-wildcard
# https://www.haproxy.com/blog/enhanced-ssl-load-balancing-with-server-name-indication-sni-tls-extension/
# https://stuff-things.net/2016/11/30/haproxy-sni/
@atitan
atitan / bash_strict_mode.md
Created April 25, 2023 06:36 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

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.

@atitan
atitan / globals.sql
Created February 22, 2021 02:13 — forked from wakwanza/globals.sql
Global variables update for proxysql
update global_variables set
-- UserDataMonitor
variable_value="DBMONUSER"
where variable_name='mysql-monitor_username';
update global_variables set
-- PasswordDataMonitor
variable_value="DBMONPASS"
where variable_name='mysql-monitor_password';
@atitan
atitan / install-statsd-debian.md
Created November 12, 2020 06:48 — forked from islander/install-statsd-debian.md
Install StatsD on Debian Stretch

Install StatsD on Debian Stretch

Install nodejs:

# curl -sL https://deb.nodesource.com/setup_12.x | bash -
# apt install -y nodejs

Install build dependencies:

$ sudo apt install git debhelper devscripts dh-systemd

@atitan
atitan / gist:979f522c9d1e658981ecbe52c039aeeb
Created August 8, 2020 13:57
ffmpeg rotate video without re-encode by metadata marking
ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4
@atitan
atitan / jvm.options
Created August 4, 2020 08:51
elasticsearch memory setting
# /usr/local/etc/elasticsearch/jvm.options
-Xms128m
-Xmx128m
$ openssl ecparam -name prime256v1 -genkey -noout -out private.ec.key
$ openssl ec -in private.pem -pubout -out public.pem
@atitan
atitan / gist:27d1a5e843b7168f155cc1073225fa0c
Created June 18, 2020 07:40
Convert CSV file to all string fields
awk -F ',' 'BEGIN{OFS=","} FNR != 1 {for(i=1; i<=NF; i++){ $i = "\"=\"\""$i"\"\"\"" }} {print}' input.csv > forced_string_field.csv
# ~/.bundle/config
---
BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt/[email protected]"
BUNDLE_BUILD__PUMA: "--with-opt-dir=/usr/local/opt/[email protected]"
BUNDLE_BUILD__THIN: "--with-cflags=-Wno-error=implicit-function-declaration"
BUNDLE_BUILD__FFI: "--with-cflags=-Wno-error=implicit-function-declaration"
BUNDLE_BUILD__PG: "--with-cflags=-Wno-error=implicit-function-declaration"
BUNDLE_JOBS: "8"