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 / gcrgc.sh
Created November 19, 2019 05:47 — forked from ahmetb/gcrgc.sh
Script to clean up Google Container Registry images pushed before a particular date
#!/bin/bash
# Copyright © 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@atitan
atitan / mysql2-mojave.md
Created September 2, 2019 04:08 — forked from fernandoaleman/mysql2-mojave.md
Install mysql2 on MacOS Mojave

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

brew install openssl
@atitan
atitan / with_active_support.rb
Created March 8, 2019 07:07 — forked from mbyczkowski/with_active_support.rb
session cookie decrypter for Rails 4.2+
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)[0, ActiveSupport::MessageEncryptor.key_len]
@atitan
atitan / aws-ec2-redis-cli.md
Created March 6, 2019 08:20 — forked from todgru/aws-ec2-redis-cli.md
AWS redis-cli on EC2
@atitan
atitan / jq to filter by value.md
Created December 5, 2018 07:32 — forked from ipbastola/jq to filter by value.md
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)