Skip to content

Instantly share code, notes, and snippets.

View henri's full-sized avatar
💭
hacking the mainframe

henri henri

💭
hacking the mainframe
View GitHub Profile
@henri
henri / 001.awk_cheatsheet.txt
Last active June 12, 2025 22:02
AWK Cheatsheet
# How to just buffer each line (rather than the entire input stream) when using awk / gawk to read data from a pipe.
awk '{ print $0 ; system("") }' # compatible with POSIX complient systems
gawk '{ print $0 ; system("") }' # gawk is smart and will not actually start a sub-shell
# fflush - is going to offer something similar (although you can speicify which kind of output you would like to flush).
# remove first column (using white space) keep all other columns
awk '{sub(/^[^[:space:]]+[[:space:]]+/, ""); print}'
@henri
henri / clear_arp_cache.bash
Created October 31, 2022 22:46
MacOS Clear ARP Cache Script
#!/bin/bash
# This script is used to clear the arp cache on macOS - it may even work on other operating systems
# (C)2005 Henri Shustak
# Released Under MIT Licence : http://mit-license.org
# check we are running as root
currentUser=`whoami`
if [ $currentUser != "root" ] ; then
echo This script must be run with super user privileges
@henri
henri / macOS flush dns cache
Created October 20, 2022 22:38
Flush DNS cache on macOS system
# macOS 10.15 and later
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
@henri
henri / switch_to_network_location.bash
Last active December 12, 2022 21:26
macOS switch to specific network location
#!/bin/bash
# simple script for macOS systems. It will switch to the location specified below if it is exists.
switch_to_location="Automatic"
current_location=`scselect | grep "*" | grep -v "Defined sets include: " | awk -F "(" '{print $2}' | awk -F ")" '{print $1}'`
if [ "{$current_location}" != "{$switch_to_location}" ] ; then
scselect "${switch_to_location}"
exit $?
fi
@henri
henri / macOS disable auto save.
Last active November 8, 2022 19:59
Important Tips for Old-School MacOS Users
Some programs will automatically save changes when closing files - Plan is to make a repository with a bunch of defaults which I use. For now it is a GitHub Gist.
Programs which seem to do this are listed below :
- Texttastic : https://www.textasticapp.com
More default settings now availble in a repository :
https://github.com/henri/handy-settings-macOS/
---- CLI Details ----
@henri
henri / grep_cheatsheet.txt
Last active June 12, 2025 23:58
grep_cheatsheet
# select lines which start with upper case or lower case letter at the start of the line
grep -E "^[a-z]|[A-Z]"
# enable line buffering (useful for dealing with pipes and real time loops)
grep --line-buffered "search term"
# enable highlighting for a match but do not filter output (all of these examples will have a similar effect)
ack --passthru 'hightlight-match-string'
grep "^\|highlight-match-string" --color="always"
grep "^\|highlight-match-string" --color
@henri
henri / benchmark_function_v1.bash
Last active April 6, 2023 00:38
BASH benchmarking and latency monitoring
#!/bin/bash
# (C)2020 Henri Shustak
# Relased Under MIT LICENCE
# https://mit-license.org/
# benchmark bash function
# requires gdate to be installed (part of coreutils)
# This system is very basic and has some serious limitiations.
@henri
henri / findmyfiles_bytime.bash
Created August 7, 2022 10:06
Find Files By Time Of Creation
#!/usr/bin/env bash
# find files within folder with creation time falling between 6PM and 9AM (change as required).
for f in /myfolder/* ; do
var=$(date -r "$f" '+%H')
if [ $var -gt 18 ] || [ $var -lt 9 ] ; then
ls -l "$f"
fi
done
@henri
henri / lsof_macOS_cheatsheet.txt
Last active July 4, 2022 22:50
netstat (more similar to GNU/LINUX) on macOS
# netstat (more similar to GNU/LINUX) on macOS
lsof -i -P | grep -i "listen" --line-buffered
Summary How to control (or Understand) your GIST page's files list order.
Notice not official documentation.