Skip to content

Instantly share code, notes, and snippets.

@deviationist
deviationist / Code.gs
Last active May 2, 2023 07:21
A set of functions for Google Sheets to sum columns by text formatting. Currently supports font weight, line-through, underline.
// These functions let's you sum columns based on their text formatting.
// The only flaw is that there's no text formatting change event, so you have to update the value of a field to trigger recalculation.
// styleRangeString (string) - The range where the text formatting should be evaluated. Example: A10:A20
// sumRangeString (string) - The range where the numerical values will be summed. Should correspond with styleRangeString unless you only specify column. Example: B10:B20
// attribute (string) - The text formatting attribute for conditional check during sum.
// Note: styleRangeString and sumRangeString must be passed as a STRING, meaning it has to be wrapped in quotes ("A10:A20").
// Example:
@deviationist
deviationist / node-disk-cache.js
Last active April 12, 2023 20:13
A simple file-based cache driver for Node with expiration-support. No external packages needed.
import fs from 'fs';
export default class DiskCache {
static basePath = './.cache';
static prettyPrintJson = false;
#filePath;
#cacheName;
#data = {};
constructor(cacheName) {
@deviationist
deviationist / fb-event-redirect.php
Last active March 27, 2023 13:25
Facebook event app opener - do you have your own redirect in front of your Fb-event? Then it will most likely not open the app since the first request must be to a facebook-domain. But this lil' script attempts to open the app (only on mobile), if not it will redirects you as a fallback.
<?php $fbId = isset($_GET['fb_id']) ? $_GET['fb_id'] : false; ?>
<?php $whitelistedIds = ['your-event-id']; ?>
<?php if ($fbId && (count($whitelistedIds) == 0 || in_array($fbId, $whitelistedIds))) { ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
@deviationist
deviationist / openvpn-docker-setup.md
Last active March 29, 2023 12:32
A simple OpenVPN-setup with Docker.
@deviationist
deviationist / cloudflare-ddns-update.sh
Created March 22, 2023 17:10
Cloudflare DDNS client in bash
#!/bin/bash
# A bash script to update a Cloudflare DNS A record with the external IP of the source machine
# Used to provide DDNS service for my home
# Needs the DNS record pre-creating on Cloudflare
# Proxy - uncomment and provide details if using a proxy
#export https_proxy=http://<proxyuser>:<proxypassword>@<proxyip>:<proxyport>
# Cloudflare zone is the zone which holds the record
@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));
}
@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 / 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 / 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 / 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