Skip to content

Instantly share code, notes, and snippets.

@mgor
mgor / .bashrc
Last active February 15, 2017 12:22
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.
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 / .screenrc
Created February 15, 2017 12:24
.screenrc that somewhat emulated my tmux config from mgor/dotfiles, should be used togheter with .bashrc gist.
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 / measure-wireless.sh
Created March 2, 2017 17:51
Simple script that takes 10 samples of wifi signal quality and then calculates the average.
#!/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 / pet-snippet.toml
Created March 13, 2017 19:07
description
[[snippets]]
description = "Get my external IP address."
command = "curl ifconfig.co"
@mgor
mgor / bash
Created May 8, 2017 13:31
cURL measurements as json
↳ 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
@mgor
mgor / chartjs.background.plugin.ts
Created October 25, 2019 05:05
Color the chartArea for each x point.
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;
}
# 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 / listen.bash
Created April 1, 2020 07:03
Check for open ports in a firewall
#!/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
@mgor
mgor / LudwigsPickaxe.sh
Created February 28, 2021 16:33
My son had seen a youtube clip of of someone using a pickaxe to mine 3x3x3...
# Ludwig's special pickaxe
#
# Inspired by:
# https://forums.skunity.com/threads/3x3-mining.4864/#post-18936
#
# Install https://github.com/SkriptLang/Skript/releases
# Place this file in plugins/Skript/scripts
#
# Usage:
# /lp user <user> permission set lpickaxe.use true