Skip to content

Instantly share code, notes, and snippets.

View zuzzas's full-sized avatar

Andrey Klimentyev zuzzas

View GitHub Profile
@zuzzas
zuzzas / jstackh.pl
Last active August 29, 2015 14:24
Easily convert nid to pid (props to http://stackoverflow.com/a/1199127). Just pipe jstack output to this script.
#!/usr/bin/perl -w
while (<>) {
if (/nid=(0x[[:xdigit:]]+)/) {
$lwp = hex($1);
s/nid=/pid=$lwp nid=/;
}
print;
}
@zuzzas
zuzzas / flock.sh
Last active August 29, 2015 14:24
Flock example
#!/bin/bash
# Function declaration
lock() {
exec 200>/var/lock/.myscript.exclusivelock
flock -n 200 \
&& return 0 \
|| return 1
@zuzzas
zuzzas / gunicorn.service
Last active August 29, 2015 14:26
gunicorn systemd unit
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
PIDFile=/var/apps/gunicorn.pid
User=apps
Group=apps
WorkingDirectory=/var/apps/bans
ExecStart=/usr/local/bin/gunicorn --pid /var/apps/gunicorn.pid --bind unix:/var/apps/apps.sock wsgi:app
#!/bin/bash
for i in `seq 1 10000`
do /bin/date +%Y-%m-%d-%H-%M-%S
mtr -n -c 600 -i 1 -r 10.147.0.46 > 10.147.0.46_$(/bin/date +%Y-%m-%d-%H-%M-%S).txt
done
@echo off
set /p HOST="Enter IP address or FQDN: "
:while
set SAVESTAMP=%DATE:/=-%@%TIME::=-%
set SAVESTAMP=%SAVESTAMP: =%
echo %SAVESTAMP%
echo Next iteration...
pathping -q 100 -n %HOST% > %SAVESTAMP%.txt
GOTO while
@zuzzas
zuzzas / hfsc-shape.sh
Created March 18, 2016 10:19 — forked from bradoaks/hfsc-shape.sh
HFSC - linux traffic shaping's best kept secret
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@zuzzas
zuzzas / debian-preseeded-iso.sh
Last active July 20, 2024 21:38
Create Debian netinstall iso with preseed file
set -e
set -u
# hat-tips:
# - http://codeghar.wordpress.com/2011/12/14/automated-customized-debian-installation-using-preseed/
# - the gist
# required packages (apt-get install)
# xorriso
@zuzzas
zuzzas / volume_backup.sh
Created July 5, 2017 14:21
Docker volume backup
#!/bin/bash
# This script allows you to backup a single volume from a container
# Data in given volume is saved in the current directory in a tar archive.
CONTAINER_NAME=$1
VOLUME_NAME=$2
usage() {
echo "Usage: $0 [container name] [volume name]"
exit 1
}
#!/bin/bash
# This script allows you to backup a single volume from a container
# Data in given volume is saved in the current directory in a tar archive.
CONTAINER_NAME=$1
VOLUME_NAME=$2
VOLUME_NAME_SANITIZED=$(echo $VOLUME_NAME | sed s#/#_#2g)
usage() {
echo "Usage: $0 [container name] [volume name]"
exit 1
@zuzzas
zuzzas / purge-multi.lua
Created August 25, 2017 14:28 — forked from titpetric/purge-multi.lua
Delete NGINX cached items with a PURGE with wildcard support
-- Tit Petric, Monotek d.o.o., Tue 03 Jan 2017 06:54:56 PM CET
--
-- Delete nginx cached assets with a PURGE request against an endpoint
-- supports extended regular expression PURGE requests (/upload/.*)
--
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
end