Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikael Göransson mgor

View GitHub Profile
@mgor
mgor / listen.bash
Created Apr 1, 2020
Check for open ports in a firewall
View listen.bash
#!/usr/bin/env bash
main() {
local first=$1
local last=$2
local pids=()
[[ -z "${first}" || -z "${last}" ]] && { >&2 echo "listen.sh <first> <last>"; return 1; }
for (( port=first; port <= last; port++ )); do
View gist:8bc1761d10ac36388039cb3b798e7ab2
# After gathering all the evidence:
grep -f <(grep -f <(awk '/^License Plate L337.*9$/,/^$/' vehicles | sed '/^$/d' | paste -d, - - - - - - | awk '/Honda/ && /Blue/ && /Height: 6/' | awk -F, '{print $4}' | awk -F': ' '{print $NF}') memberships/{AAA,Delta_SkyMiles,Museum_of_Bash_History,Terminal_City_Library} | awk -F: '{print $NF}' | sort | uniq -c | awk '/ 4 / {print $2" "$3}') people | awk '{gsub(/,/, "", $6); print "nl streets/"$5"_"$6" | grep "$NF}' | bash | awk -F# '{print "grep -nH \"Considered a suspect\" interviews/interview-"$NF}' | bash | awk -F'[-:]' '{print "grep -n \"SEE INTERVIEW #"$2"\" streets/*"}' | bash | awk -F'[/:]' '{gsub(/_/, " ", $2); print "grep -E \""$2".*line "$3"\" people"}' | bash | awk '{print $1" "$2}' | $(command -v md5 || command -v md5sum) | grep -qif /dev/stdin ../encoded && echo CORRECT\! GREAT WORK, GUMSHOE. || echo SORRY, TRY AGAIN.
@mgor
mgor / chartjs.background.plugin.ts
Created Oct 25, 2019
Color the chartArea for each x point.
View chartjs.background.plugin.ts
import { Easing, PluginServiceGlobalRegistration, PluginServiceRegistrationOptions } from 'chart.js';
export class BackgroundPlugin implements PluginServiceGlobalRegistration, PluginServiceRegistrationOptions {
id = 'background-plugin';
beforeDraw(chartInstance: Chart, easing: Easing, options?: any): void {
const chartOptions = chartInstance.options as any;
if (!('backgroundPlugin' in chartOptions) || !('backgroundColors' in chartOptions.backgroundPlugin)) {
return;
}
@mgor
mgor / bash
Created May 8, 2017
cURL measurements as json
View bash
↳ cat curl-format.txt
{\n
"time_namelookup": %{time_namelookup},\n
"time_connect": %{time_connect},\n
"time_appconnect": %{time_appconnect},\n
"time_pretransfer": %{time_pretransfer},\n
"time_redirect": %{time_redirect},\n
"time_starttransfer": %{time_starttransfer},\n
"time_total": %{time_total}\n
}\n
View pet-snippet.toml
[[snippets]]
description = "Get my external IP address."
command = "curl ifconfig.co"
@mgor
mgor / measure-wireless.sh
Created Mar 2, 2017
Simple script that takes 10 samples of wifi signal quality and then calculates the average.
View measure-wireless.sh
#!/usr/bin/env bash
wifi_interface="$(nmcli d | awk '$2 ~ /wifi/ {print $1}')"
description="${1:-${wifi_interface}}"
sudo true
samples=10
sequences=($(seq 1 ${samples}))
@mgor
mgor / .screenrc
Created Feb 15, 2017
.screenrc that somewhat emulated my tmux config from mgor/dotfiles, should be used togheter with .bashrc gist.
View .screenrc
startup_message off
escape ^Ss
termcapinfo rxvt-unicode ti@:te@ #enable SHIFT-PGUP / SHIFT-PGDOWN scroll
terminfo rxvt-unicode ti@:te@:
term screen-256color
setenv LC_CTYPE en_US.UTF-8
defutf8 on
nonblock on
vbell off
msgwait 10
@mgor
mgor / .bashrc
Last active Feb 15, 2017
Set screen window title based on the command that is being executed (trying to "emulate" tmux automatic set title). This will leave the window title to the last executed command though.
View .bashrc
if [[ "${TERM}" == screen* ]]; then
preexec() { :; }
screen_window_title() {
[[ -n "${COMP_LINE}" ]] && return
[[ "${BASH_COMMAND}" == "${PROMPT_COMMAND}" ]] && return
local cmd=$(HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//")
local title="${cmd}"
(( "${#title}" > 12 )) && title="${title:0:12}..."
printf '\ek%s\e\\' "${title}"
@mgor
mgor / test_unicode.sh
Last active Dec 2, 2016
test if terminal supports unicode
View test_unicode.sh
test_unicode() {
echo -ne "\xe2\x88\xb4\033[6n\033[1K\r"
# shellcheck disable=SC2034
read -d R foo
echo -ne "\033[1K\r"
echo -e "${foo}" | cut -d \[ -f 2 | cut -d";" -f 2 | (
read UNICODE
[[ $UNICODE -eq 2 ]]
) 2>/dev/null
}
View trouf.link
You can’t perform that action at this time.