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 / 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 / openvpn-docker-setup.md
Last active March 29, 2023 12:32
A simple OpenVPN-setup with Docker.
@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 / 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 / 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 / remove-all-sharing.js
Last active May 9, 2023 09:28
This is a script that will traverse all your Google Drive files and remove all sharing (owner access only).
// Ensure you've installed gdrive first: https://github.com/glotlabs/gdrive
import { spawnSync } from 'child_process';
const delimiter = ';;;';
let files = [];
function getRawFiles(parent) {
const args = ['files', 'list', `--field-separator=${delimiter}`];
if (parent) {
args.push(`--parent=${parent}`);
@deviationist
deviationist / audio-file-extension-check.sh
Created June 2, 2023 22:10
File counter grouped by file extension, tailored for audio files.
#!/usr/bin/env bash
echo "File type count:"
fileExtensions=( aiff mp3 wav m4a flac alac )
totalFileCount=$(find . -name "*.aiff" -o -name "*.mp3" -o -name "*.wav" -o -name "*.m4a" -o -name "*.flac" -o -name "*.alac" | wc -l)
for fileExtension in "${fileExtensions[@]}"
do
fileCount=$(find . -name "*.${fileExtension}" | wc -l)
@deviationist
deviationist / useEffectNonInit.ts
Last active March 11, 2024 15:45
React's useEffect, but it does not run on initial render. Now with TypeScript-support.
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useRef, DependencyList } from 'react';
export const useEffectNonInit = (effect: Function, deps: DependencyList = []) => {
const isInitial = useRef<boolean>(true);
useEffect(() => {
if (isInitial.current) {
isInitial.current = false;
return;
}
effect();
@deviationist
deviationist / shallow-router.tsx
Created June 30, 2023 10:09
A bare simple class made for Next.js with static methods to use as a shallow router (triggering changes in the URL without Next acting on them).
export class ShallowRouter {
static push(url: string): void {
window.history.pushState({ ...window.history.state, as: url, url }, '', url);
}
static replace(url: string): void {
window.history.replaceState({ ...window.history.state, as: url, url }, '', url);
}
}
@deviationist
deviationist / gist:51cf2caf8d8e7db117d87cb2a1a5d23a
Created November 12, 2023 12:16
Downsample an AIFF-file using FFMPEG.
ffmpeg -y -nostdin -i a.aiff -ar 44100 -write_id3v2 1 -c:v copy b.aiff