Skip to content

Instantly share code, notes, and snippets.

View saga420's full-sized avatar
😀
Working from home

saga420 saga420

😀
Working from home
  • HOOLI XYZ
  • Making the world a better place
View GitHub Profile
! ===== Encrypted/HTTPDNS endpoints to BLOCK =====
||api.yuedu.dns.iqiyi.com^$important
||apidns.kwd.inkuai.com^$important
||bj.vip.waf.dns.iqiyi.com^$important
||data.video.dns.iqiyi.com^$important
||dns.alidns.com^$important
||dns.iqiyi.com^$important
||dns.jd.com^$important
||dns.jd.com.gslb.qianxun.com^$important
||dns.qiyipic.iqiyi.com^$important
! Apple allowlist for AdGuard (focus on service continuity; include ads/metrics).
! Syntax: AdGuard/Adblock-style whitelist rules.
! NOTE: Final section includes “catch-all” root zones to future-proof new subdomains.
! =========================
! Core / Identity / CDN
! =========================
@@||apple.com^
@@||cdn-apple.com^
@@||aaplimg.com^
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# init-cloud.sh - Unified Linux Cloud Server Initialization Script
# Combines cfg.sh and edge-sysctl-upgrade.sh with improvements
#
# Features:
# • Non-interactive / idempotent / fault-tolerant
# • Auto-detects system architecture (x86_64/ARM)
# • Configurable swap size (default 5GB)
# • Removes UFW, relies on iptables-nft or nftables
@saga420
saga420 / cfg.sh
Last active July 25, 2025 01:48
Server setup script
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# Debian 12 bootstrap – high-concurrency proxy / forwarding host
#
# • Non-interactive / idempotent / fault-tolerant
# • Removes UFW, relies on iptables-nft or nftables
# • Installs tool-chain + shadowsocks-rust (auto-latest, idempotent)
# • Enables kernel forwarding & high-performance sysctl profile
# • Creates / resizes 5 GiB swapfile if required
#
package main
import (
"github.com/gin-gonic/gin"
"net"
"net/http"
"os/exec"
)
var privateNetworks []*net.IPNet
@saga420
saga420 / aws_delete-default-vpc.sh
Created March 27, 2021 11:43 — forked from jokeru/aws_delete-default-vpc.sh
Script to delete all AWS default VPCs from all regions using AWS CLI
#!/usr/bin/env bash
if [ "$AWS_PROFILE" = "" ]; then
  echo "No AWS_PROFILE set"
  exit 1
fi
for region in $(aws ec2 describe-regions --region eu-west-1 | jq -r .Regions[].RegionName); do
@saga420
saga420 / atomic-versioned-deploys.py
Last active June 11, 2020 13:01
atomic-versioned-deploys.py
#!/usr/bin/python
import os
import boto3
import pathlib
import datetime
import subprocess
import mimetypes
'''
@saga420
saga420 / Effectively using AWS Reserved Instances.md
Last active December 8, 2018 23:45
Effectively using AWS Reserved Instances

Effectively using AWS Reserved Instances

Learn how Stripe uses AWS Reserved Instances and capacity planning to effectively manage a dynamic, scalable cloud infrastructure: https://stripe.com/blog/aws-reserved-instances

Usage

Included are three files:

  • Makefile: This generates our Python environment for running the ETL.
curl 'https://www.arin.net/waitinglist.html?_=1538680982940' -H 'Cookie: _ga=GA1.2.1630349111.1538174262; __utmc=224776645; _gid=GA1.2.1603603287.1538405341; __utmz=224776645.1538430987.6.4.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __utma=224776645.1630349111.1538174262.1538616731.1538680963.14; __utmt=1; __utmb=224776645.1.10.1538680963; sjSE=169' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en,zh;q=0.9,zh-CN;q=0.8,zh-TW;q=0.7' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' -H 'Accept: text/html, */*; q=0.01' -H 'Referer: https://www.arin.net/resources/request/waiting_list.html' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --compressed

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.