Skip to content

Instantly share code, notes, and snippets.

View jozic's full-sized avatar
🇺🇦
Stand With Ukraine

Eugene Platonov jozic

🇺🇦
Stand With Ukraine
View GitHub Profile
@jozic
jozic / gist:238d07d5ca0224ba4895a1a5a053bc17
Last active October 24, 2019 13:21
netcat: listen 2 statsd packets w/ nc
while true; do nc -ulw 0 8125; echo; done
@jozic
jozic / gist:4f781632d52e868e986217866024d82e
Last active August 18, 2023 08:45
netcat: listen to a request and return 200 HTTP response
## test is the program that returns response body
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; sh test; } | nc -l 8909; done
## test sample
#!/bin/bash
echo "************PRINT SOME TEXT***************\n"
echo "Hello World!!!"
echo "\n"
@jozic
jozic / gist:5595c0840b487e0494a74fa5656961ca
Created October 19, 2016 15:19
docker: remove all images without tags
docker images | grep \<none\> | awk '{print $3}' | xargs docker rmi
@jozic
jozic / gist:1d2f0b67f5b015f3d9313236905e0e2b
Created October 20, 2016 12:27
netcat-statsd: send statsd counter
echo "sample.count:10|c" | nc -v -u -w 0 localhost 8125
@jozic
jozic / gist:b772c35d739e6fbd21c219fdabf0823b
Created November 4, 2016 16:53
docker-netcat-statsd: send docker stats to statsd
STATSD_HOST="${STATSD_HOST:-localhost}"
STATSD_PORT="${STATSD_PORT:-8125}"
STATSD_PREFIX="${STATSD_PREFIX:-"docker"}"
INTERVAL="${STATS_COLLECT_INTERVAL:-2}"
while sleep "$INTERVAL"; do
docker stats --no-stream $(docker ps | awk '{if(NR>1) print $NF}') | tail -n+2 | while read line;
do
echo "line: " $line;
echo $line | awk '{printf("'${STATSD_PREFIX}'.%s.cpu:%.2f|c", $1, substr($2, 1, length($2)-1))}' | xargs echo | nc -v -u -w 0 $STATSD_HOST $STATSD_PORT;
psgrep() { ps aux | grep -v "grep" | egrep "%CPU"\|$1; }
alias intellij-memory="find ~/apps -iname '*.vmoptions' | xargs sed -i 's/-Xms.*$/-Xms2g/g;s/-Xmx.*$/-Xmx4g/g'"
## gitr - returns verbose output for remotes
## gitr joe - adds remote joe as a fork of this repo
## gitr -joe - removes remote joe
gitr() {
if [[ $# == 1 ]]; then
local name=$1
if [[ $name == -* ]]; then # starts with -, e.g. "-joe"
name=${name:1};
echo "removing remote $name";
# downloads a file specified by first parameter, puts it to /usr/local/bin (or second parameter) and gives it +x permissions
curl_install() {
if [[ $# == 0 ]]; then
echo "At least one parameter (url) is required"
return
elif [[ $# == 1 ]]; then
local url=$1
local file="/usr/local/bin/"${url##*/}
elif [[ $# == 2 ]] ; then
local url=$1
# expects single url parameter, returns url following redirects
resolve_url() {
curl -w "%{url_effective}\n" -I -L -s -S $1 -o /dev/null
}