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 / guid_reaper.py
Created July 9, 2024 11:39 — forked from DanaEpp/guid_reaper.py
Tool to dump v1 GUIDs and generate a wordlist of GUIDs for use in bruteforce attacks against APIs with predictable GUIDs
#!/bin/env python3
import argparse
import datetime
import re
import sys
import uuid
###############################################################################
# Based off of Daniel Thatcher's guid tool

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.

@avkosme
avkosme / sortByDate.go
Created November 23, 2022 18:43 — forked from santiaago/sortByDate.go
Sorting an array of dates in Go
package main
import "fmt"
import "time"
import "sort"
func main() {
fmt.Println("Sorting an array of time")
const shortForm = "Jan/02/2006"
t1, _ := time.Parse(shortForm, "Feb/02/2014")
@avkosme
avkosme / .gitconfig
Created November 19, 2022 03:23 — forked from Kovrinic/.gitconfig
git global url insteadOf setup
# one or the other, NOT both
[url "https://github"]
insteadOf = git://github
# or
[url "git@github.com:"]
insteadOf = git://github
@avkosme
avkosme / gist:312c86cab0dbe8b81c1518be24d302fe
Created November 14, 2022 07:11 — forked from arunoda/gist:7790979
Installing SSHPass

Installing SSHPASS

SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.

Installing on Ubuntu

apt-get install sshpass

Installing on OS X

@avkosme
avkosme / mp4-to-gif.sh
Created June 27, 2021 08:59 — forked from Ultrabenosaurus/mp4-to-gif.sh
Simple bash script to convert MP4 videos to GIF
#!/bin/bash
#############################################
#
# mp4-to-gif
#
# Convert MP4 videos to GIF images
# Requires ffmpeg and imagemagick
#
# -g and --gifsicle options create a second optimised GIF for your consideration
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get requests by 502 code
awk '($9 ~ /502/)' /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -r
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | awk -v OFS='\t' '{"host " $2 | getline ip; print $0, ip}'
# get top requesters IP by url
@avkosme
avkosme / archlinux-virtualbox.sh
Created April 1, 2020 07:06 — forked from GabLeRoux/archlinux-virtualbox.sh
Virtualbox archlinux notes
# sudo /sbin/rcvboxdrv -h
# Unloading modules:
# Loading modules: modprobe: FATAL: Module vboxnetadp not found in directory /lib/modules/4.4.3-1-ARCH
# modprobe: FATAL: Module vboxnetflt not found in directory /lib/modules/4.4.3-1-ARCH
# modprobe: FATAL: Module vboxpci not found in directory /lib/modules/4.4.3-1-ARCH
# modprobe: FATAL: Module vboxdrv not found in directory /lib/modules/4.4.3-1-ARCH
# Solution
# from https://forum.antergos.com/topic/818/can-t-run-my-vitualbox/4
@avkosme
avkosme / answer_exercise_gotour.go
Created January 5, 2020 03:13 — forked from tetsuok/answer_exercise_gotour.go
An answer of the exercise: Loops and Functions on a tour of Go
package main
import (
"fmt"
"math"
)
const Delta = 0.0001
func isConverged(d float64) bool {