Skip to content

Instantly share code, notes, and snippets.

View mjf's full-sized avatar

Matouš Jan Fialka mjf

View GitHub Profile
@mjf
mjf / practice_chinese_numbers.sh
Created September 9, 2012 16:19
Practice Chinese Numbers from 0 to 10
#! /bin/sh
# Practice Chinese Numbers from 0 to 10 (in Pinyin)
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
#
# Note: requires UTF-8 ANSI-compatible terminal (XTerm)
hanzi[0]='零'
hanzi[1]='一'
@mjf
mjf / asciips
Created October 11, 2012 10:49
ASCIIPS - ASCII file to PostScript Converter
#! /bin/sh
# ASCIIPS - ASCII file to PostScript Converter
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
ASCIIPS_CREATOR=${ASCIIPS_CREATOR:-ASCIIPS}
ASCIIPS_FONT=${ASCIIPS_FONT:-Courier}
ASCIIPS_FONTSIZE=${ASCIIPS_FONTSIZE:-12}
@mjf
mjf / ascii.h
Created October 25, 2012 00:09
ascii.h - Macros and constants for 7-bit ASCII
/**
* ascii.h - Macros and constants for 7-bit ASCII
* Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
* Released under the terms of The MIT License
*/
#ifndef ASCII_H
#define ASCII_H
#define is_7bit(x) ((x & 0x80) == 0)
@mjf
mjf / pingfmt
Created November 29, 2012 01:45
pingfmt
#! /usr/bin/awk -f
# PINGFMT - Format output of the ping(1) program
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
BEGIN {
# ----- HELP SCREEN -----
help = help "Usage: pingfmt [-h|-help|-usage] [+[no][show]<opt>[=<val>]]\n"
@mjf
mjf / ifchanged.sh
Last active December 10, 2015 21:08
IfChanged - returns 0 if file changed, 127 otherwise
#! /bin/sh
# IfChanged - returns 0 if file changed, 127 otherwise
# Copyright (C) 2013 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
fpath="$(realpath 2>/dev/null ""$1"")" || {
echo "Error: realpath $1 failed" 1>&2
exit 1
}
@mjf
mjf / preen
Last active August 25, 2021 06:15
PREEN - Preen current path by file type
#! /bin/sh
# PREEN - Preen current/working directory by file type
# Copyright (C) 2013,2018,2020 Matous J. Fialka, <https://mjf.cz/>
# Released under the terms of The MIT License
PREENDIR="${PREENDIR:-.preen}"
PREENRC="${PREENRC:-.preenrc}"
for util in which find file test mkdir ln
@mjf
mjf / changed
Created March 28, 2013 10:58
Shell script to detect file or directory has changed using ls, sha1sum, mv and cmp
#! /bin/sh
checksum=`echo $@ | sha1sum - | cut -d ' ' -f 1`
if ! [ -e /tmp/$checksum.ls-ZlaR ]
then
if ! ls -ZlaR $@ > /tmp/$checksum.ls-ZlaR
then
echo changed: could not create /tmp/$checksum.ls-ZlaR 1>&2
exit 1
@mjf
mjf / ip6rev.sh
Last active January 11, 2019 10:23
Simple IPv6 PTR helper
#! /bin/sh
# ip6rev - Generate IPv6 PTR DNS RR
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of "The MIT License"
if [ $# -lt 1 -o -$# -gt 3 ]; then
cat <<- EOT
ip6rev ip6 rev [oct]
@mjf
mjf / vendor.sh
Last active December 15, 2015 19:19
Get MAC vendor according to the oui.txt by IEEE
#! /bin/sh
# Hint: paragraph and mac can be found in my gists as well.
# Cron: 30 4 * * * rm ~/.oui.txt && /usr/local/bin/vendor >/dev/null
if ! [ -f ~/.oui.txt ]
then
wget -qO ~/.oui.txt http://standards.ieee.org/develop/regauth/oui/oui.txt
fi
@mjf
mjf / grep_priv_ip4.sed
Last active December 17, 2015 01:58
Match lines containing IPv4 private addresses. TODO: aggregate into single regular expression
#! /bin/sed -f
# 10.0.0.0/8
# 127.0.0.0/8
/1\(0\|27\)\(\.\([0-9]\|[1-9][0-9]\|10[0-9]\|1[1-9][0-9]\|25[0-5]\|2[0-4][0-9]\)\)\{3\}/ p
# 172.16.0.0/19
# 192.168.0.0/16