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 / 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.

@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 "[email protected]:"]
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

# Modify commit message
git commit --amend -m "New commit message"
systemd-run --scope -p CPUQuota=100% skypeforlinux.
@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
CREATE TABLE <NEW.NAME.TABLE> LIKE <TABLE.CRASHED>;
INSERT INTO <NEW.NAME.TABLE> SELECT * FROM <TABLE.CRASHED>;
Rename NEW.NAME.TABLE and TABLE.CRASH
RENAME TABLE <TABLE.CRASHED> TO <TABLE.CRASHED.BACKUP>;
RENAME TABLE <NEW.NAME.TABLE> TO <TABLE.CRASHED>;
After work well, delete
DROP TABLE <TABLE.CRASHED.BACKUP>;
@avkosme
avkosme / gist:d8675e8bdc504123b6236aa27e170ee9
Created February 25, 2021 05:51
Алиас для запуска any-connect
alias any-connect="echo "<ваш пароль>" | sudo openconnect --no-dtls --user <имя пользователя> --passwd-on-stdin <адрес сервера> --authgroup=ANYVPN"