Skip to content

Instantly share code, notes, and snippets.

Ján Sáreník jsarenik

Block or report user

Report or block jsarenik

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsarenik
jsarenik / renameat2.c
Created Jul 14, 2017 — forked from eatnumber1/renameat2.c
Command-line tool to call renameat2(2)
View renameat2.c
#define _GNU_SOURCE
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <getopt.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
@jsarenik
jsarenik / mtu-linux.sh
Last active Jun 28, 2017
Find MTU on Linux as root.
View mtu-linux.sh
#!/bin/sh -x
PL=1500
myping() {
ping -c1 -w1 -W1 -nM do -s$1 jasan.tk >/dev/null 2>&1
}
until myping $PL; do PL=$(($PL-10)); done
while PL=$((PL+2)); myping $PL; do : ; done
@jsarenik
jsarenik / memstat-new.sh
Last active Jun 18, 2017
Memstat script rewritten for POSIX shell and busybox tools. Heavily optimized compared to the original one.
View memstat-new.sh
#!/bin/sh
#Source : http://www.linoxide.com/linux-shell-script/linux-memory-usage-program/
#Parent : http://www.linoxide.com/guide/scripts-pdf.html
tabw=8
mark=40
test $(id -u) -eq 0 || {
echo "This script must be run as root" 1>&2
exit 1
@jsarenik
jsarenik / args.sh
Created Jun 9, 2017
Quoted arguments in shell
View args.sh
for i in $(seq $#)
do
ARGS="$ARGS \"$(eval $(echo echo \$$i))\""
done
echo $ARGS
@jsarenik
jsarenik / nginx-configure.sh
Created Oct 27, 2016
Configure NGINX with Musl libc
View nginx-configure.sh
export PATH=/usr/local/musl/bin:$PATH
sed -i bck 's/configure --disable-shared $PCRE_CONF_OPT/configure --disable-shared --disable-cpp $PCRE_CONF_OPT/' auto/lib/pcre/make
./configure --with-cc="musl-gcc" --with-ld-opt="-static" --with-pcre=$HOME/pcre-8.39 --with-http_v2_module --with-openssl=$HOME/openssl-1.0.2j --without-http_scgi_module --without-http_uwsgi_module --without-http_fastcgi_module
@jsarenik
jsarenik / myip-linux.sh
Created Aug 24, 2016
Script to find one configured IP address used for communication via default route on Linux using ip command
View myip-linux.sh
#!/bin/sh
DEV=$(ip route list | sed -n '/^default/s/.*dev \(\S\+\).*/\1/p')
IP=$(ip route list | sed -n '/^default/s/.*src \(\S\+\).*/\1/p')
ip address list dev $DEV | grep -m1 -o "$IP/[0-9]\+"
@jsarenik
jsarenik / caesar.sh
Last active Aug 11, 2016
Caesar cipher in POSIX shell using cut and tr
View caesar.sh
#!/bin/sh
#
# https://en.wikipedia.org/wiki/Caesar_cipher
KEY=${1:-3}
A=abcdefghijklmnopqrstuvwxyz
B=$(echo $A | cut -b${KEY}- | tr -d '\n'; echo $A | cut -b-$[KEY-1])
AU=$(echo $A | tr '[a-z]' '[A-Z]')
BU=$(echo $B | tr '[a-z]' '[A-Z]')
@jsarenik
jsarenik / swap.c
Created Jul 14, 2016
Change endianess (e.g. 01101 to 10110 bit-wise)
View swap.c
#include <stdio.h>
unsigned int reverse(unsigned char b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
int
@jsarenik
jsarenik / GNU_Social
Created Jun 14, 2016
[SDF] let SDF help GNU!
View GNU_Social
Date: Sun, 14 Feb 2016 09:53:21 GMT
From: membership@sdf.org
Subject: [SDF] let SDF help GNU!
Want to take back the internet?
No, wait a second. I'm serious. Do you remember a thing called USENET? Do
you remember how cool it was when you posted something and someone at
hawaii.edu or telebit.com responded? GNU Social is reviving this idea. Much
of the internet for the general public these days is not only just focused
on http/https but a key number of central sites. When SDF was (uh, it still
@jsarenik
jsarenik / busyroot.sh
Last active Mar 31, 2017
chroot hack
View busyroot.sh
#!/bin/sh
CHROOT=${1:-"myroot"}
ARCH=${2:-"armv5l"}
test -n "$UNSHARE" || {
export UNSHARE="unshare --fork --pid --mount"
exec $UNSHARE $0 $CHROOT
}
You can’t perform that action at this time.