Skip to content

Instantly share code, notes, and snippets.

View deviationist's full-sized avatar

Robert S. deviationist

  • Oslo-area, Norway
View GitHub Profile
@deviationist
deviationist / disk-monitor.sh
Last active November 26, 2023 03:41
Disk usage monitor for a single disk that posts to Slack if the usage percent surpasses a configurable threshold.
#!/bin/bash
PERCENT_THRESHOLD=95
DISK_NAME=/dev/sda1
DISK_PERCENTAGE=$(df -hl $DISK_NAME | sed 1d | awk 'BEGIN{print "Use%"} {percent+=$5;} END{print percent}' | column -t | sed 1d);
if (( $PERCENT_THRESHOLD <= $DISK_PERCENTAGE )); then
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Disk is almost full - $DISK_PERCENTAGE% used on $DISK_NAME. Threshold set to $PERCENT_THRESHOLD%.\"}" https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXX
fi
@deviationist
deviationist / attribute-as-variable.cshtml
Created January 5, 2023 13:04
How to print an attribute as a variable in a CSHTML-file.
var ariaCurrent = true ? "aria-current=\"page\"" : "";
<a href="https://foo.bar" @Html.Raw(ariaCurrent)>Foo</a>
var ariaCurrent2 = true ? @"aria-current=""page""" : "";
<a href="https://foo.bar" @Html.Raw(ariaCurrent2)>Foo</a>
@deviationist
deviationist / prevent-rekordbox-start-automatically.sh
Last active February 22, 2023 11:07
Prevent Rekordbox (v6.6.8) from starting on boot (for macOS)
# To prevent Rekordbox from starting during boot
: > ~/Library/LaunchAgents/com.pioneerdj.rekordboxdj.agent.plist && chflags uchg ~/Library/LaunchAgents/com.pioneerdj.rekordboxdj.agent.plist
# To undo the change
chflags nouchg ~/Library/LaunchAgents/com.pioneerdj.rekordboxdj.agent.plist
@deviationist
deviationist / socks5-cli-control
Last active January 10, 2023 13:19
CLI tool for maintaining a SOCKS5 tunnel through a Cisco AnyConnect VPN tunnel (for macOS)
# This script will allow you to open/close a SOCKS5 tunnel as well as checking the status.
# The tunnel is created by using the bind address-option in the SSH client.
# The script will also terminate the tunnel if the connection is interrupted, and re-establish it when the connection is available again.
# Written and tested for macOS.
# Requirements:
# Install screen: https://formulae.brew.sh/formula/screen
# Usage
# socks5 open - Checks if your Cisco AnyConnect client is connected, if so it will attempt to set up a SOCKS5 tunnel to the remote server
@deviationist
deviationist / read-env-file.sh
Last active November 26, 2023 03:44
Read .env-files in bash
if [ -f .env ]
then
# export $(cat .env | grep 'DB_HOST' | xargs) # Read specific line
# export $(cat .env | grep 'DB_HOST|DB_USERNAME|DB_PASSWORD' | xargs) # Read specific lines
export $(cat .env | xargs) # Read all lines
else
echo "Error: could not read .env-file" && exit 1
fi
@deviationist
deviationist / iphone-11-to-14-media-queries.txt
Created November 9, 2022 21:09
iPhone 11-14 media queries
iPhone 14 Pro
@media only screen
and (device-width: 390px)
and (device-height: 844px)
and (-webkit-device-pixel-ratio: 3) { }
iPhone 14 Pro Max
@media only screen
and (device-width: 428px)
and (device-height: 926px)
wsl -- ip -o -4 -json addr list eth0 `
| ConvertFrom-Json `
| %{ $_.addr_info.local } `
| ?{ $_ }
@deviationist
deviationist / open-port-from-wsl-to-local-network.sh
Last active December 23, 2022 13:58
Open port from WSL to local network
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=192.168.0.69
@deviationist
deviationist / JSON-data for testing
Created April 13, 2022 10:17
json-test-data.json
[
{
"name": "Ima Prohaska",
"email": "[email protected]",
"phone": "+17273931388",
"company": "Sawayn-Mueller",
"company_email": "[email protected]",
"company_phone": "1-540-346-3726",
"project_url": "pfeffer.com",
"address": "7185 Considine Shore\nNew Justyn, ID 15204"
@deviationist
deviationist / curl-get-request-only-headers.sh
Last active December 23, 2022 13:58
cURL GET-request returning only headers
curl -v -s http://awesome-site.com 1> /dev/null