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 / 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)
@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 / 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 / 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 / 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 / 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 / useEffectNonInit.js
Last active June 27, 2023 15:31
React's useEffect, but it does not run on initial render.
import React from 'react';
export function useEffectNonInit(effect: Function, deps: React.DependencyList) {
const isInitial = React.useRef(true);
React.useEffect(() => {
if (isInitial.current) {
isInitial.current = false;
return;
}
effect();
}, deps);
@deviationist
deviationist / wordpress-url-exception-regex.txt
Created March 4, 2023 16:35
Regex to match all but native WordPress URL's - useful when wanting to redirect all traffic, except on WordPress-related URLs
^(?!\/(wp-admin|wp-content|wp-includes|wp-json|wp-login.php)).*$
@deviationist
deviationist / pioneer-xdj-cdj-fix-e-8307.md
Last active November 19, 2023 15:38
Pioneer CDJ/XDJ error fix "E-8307: DEVICE NO RESPONSE"

So after an export from Rekordbox to my USB stick (Corsair Flash Voyager GTX 512GB USB 3.1) it randomly stopped working, I got error "E-8307" on my Pioneer XDJ-RX2. Tried updating the firmware to latest version on the RX2, no luck. Tried reformatting it with macOS and Windows tools, no luck. I even attempted to update the firmware on the USB stick itself, but no luck.

What I had luck with was Gparted, a Linux-based disk tool. Easiest way to access this software is either to use a Linux-based computer (and installing Gparted using apt-get), or create a USB-stick (not the broken one, so you need a spare stick) that has a portable Debian-based OS on it, which you can boot into. This gives you access to Gparted and other useful tools to manipulate disks. See steps below for how I got the USB stick working again:

For a more comprehensive guide on making the bootable Gparted USB stick use this guide: https://www.partitionwizard.com/resizepartition/how-to-use-gparted.html. It covers step 1-5 below.

Steps:

  1. Down
@deviationist
deviationist / Cookies.js
Last active April 12, 2023 14:09
A Node class used for storing cookies in a JSON-file.
import { readFileSync, writeFileSync, existsSync, statSync } from 'fs';
export default class Cookies {
static filePath = './cookies.json';
static get() {
const dataStream = readFileSync(Cookies.filePath, 'utf-8');
return JSON.parse(Buffer.from(dataStream));
}