Skip to content

Instantly share code, notes, and snippets.

@deviationist
deviationist / audio-file-extension-check-v2.sh
Created March 10, 2025 20:43
File counter grouped by file extension (v2), tailored for audio files. Will now ignore files and folders starting with a dot (.).
#!/usr/bin/env bash
echo "File type count:"
fileExtensions=( aiff mp3 wav m4a flac alac )
totalFileCount=$(find . -type f \( -name "*.aiff" -o -name "*.mp3" -o -name "*.wav" -o -name "*.m4a" -o -name "*.flac" -o -name "*.alac" \) -not -path "*/\.*" | wc -l)
for fileExtension in "${fileExtensions[@]}"
do
fileCount=$(find . -type f -name "*.${fileExtension}" -not -path "*/\.*" | wc -l)
@deviationist
deviationist / nas-control.sh
Created February 19, 2025 12:00
A simple shell-script that will allow you to power down/up your NAS in tandem with Plex, to prevent Plex from wiping the library when the files are absent (NAS offline)
#!/bin/bash
# Configuration
NAS_HOSTNAME="your_nas_hostname" # Replace with your NAS hostname
NAS_MAC="XX:XX:XX:XX:XX:XX" # Replace with your NAS MAC address
NAS_USER="your_username" # Replace with your SSH username
PLEX_CONTAINER="plex-linuxserver" # Replace with your Plex container name
# Function to check if NAS is responding
check_nas_available() {
@deviationist
deviationist / init.lua
Last active January 13, 2025 12:15
Hammerspoon Lua-script for disabling/enabling Bluetooth when the lid is closed/opened
require "string"
-- Make sure to install Hammerspoon (brew install --cask hammerspoon) and blueutil (brew install blueutil).
-- Ensure to give sufficient access in macOS so that the commands can be ran:
-- -- System Settings -> Privacy & Security -> Accessibility -> Allow Hammerspoon
-- -- System Settings -> Privacy & Security -> Bluetooth -> Select app "Hammerspoon"
-- Place this file in your home folder, then open Hammerspoon and click "Reload config"
function checkBluetoothResult(rc, stdout, stderr)
-- Use for debugging
@deviationist
deviationist / init.lua
Last active January 13, 2025 12:14
Hammerspoon Lua-script for disconnecting/connecting to a Bluetooth device when the lid is closed/opened
require "string"
-- Make sure to install Hammerspoon (brew install --cask hammerspoon) and blueutil (brew install blueutil).
-- Ensure to give sufficient access in macOS so that the commands can be ran:
-- -- System Settings -> Privacy & Security -> Accessibility -> Allow Hammerspoon
-- -- System Settings -> Privacy & Security -> Bluetooth -> Select app "Hammerspoon"
-- Get the MAC address of your bluetooth device (use command "blueutil --paired")
-- Place this file in your home folder, then open Hammerspoon and click "Reload config"
macAddress="" -- Bluetooth Device MAC Address
@deviationist
deviationist / ffmpeg-audio-helpers.sh
Last active October 11, 2024 10:24
Useful FFMPEG Audio bash functions
function flactoaiff() {
if [[ $1 != *.flac ]]; then
echo "Please provide a FLAC-file"
return 1
fi
newFilePath="${1/%.flac/.aiff}"
ffmpeg -y -nostdin -i $1 -write_id3v2 1 -c:v copy $newFilePath
}
function downsample() {
@deviationist
deviationist / file.md
Created October 7, 2024 14:00
Revert recently deleted files on Ubuntu/Debian
@deviationist
deviationist / Sanity-RichDate-example-object.js
Last active August 23, 2024 06:48
An example of how a value for a richDate-field looks like in Sanity.
{
exampleField: {
_type: 'richDate',
local: '2024-03-12T00:00:00+01:00',
offset: 60,
utc: '2024-03-11T23:00:00.000Z',
timezone: 'Europe/Oslo'
}
}
@deviationist
deviationist / laravel-console-symfony-progress-indicator.php
Created July 8, 2024 17:35
How to use Symfony's ProgressIndicator-class in a Laravel Console command.
$indicator = new \Symfony\Component\Console\Helper\ProgressIndicator($this->output);
$indicator->start('Starting the process...');
foreach (range(0, 10) as $i) {
usleep(5 * 10000);
$indicator->advance();
}
$indicator->finish('Process complete!');
@deviationist
deviationist / TextFit.tsx
Last active April 7, 2024 12:49
A function-based React-component that will scale font size up/down to use all available space inside a container. Uses Tailwind CSS.
import React, { useEffect, useState, useRef, useCallback } from 'react';
type Props = {
text: string
maxSize?: number
minSize?: number
maxHeight?: number
fontStepSize?: number
containerWidthMargin?: number
initialHidden?: boolean
@deviationist
deviationist / heic2jpeg.ts
Last active March 12, 2024 17:27
A simple HEIC to JPEG-implementation for Node using libheif-js (https://www.npmjs.com/package/libheif-js) and canvas (https://www.npmjs.com/package/canvas). Not type safe, should be refined. Based of catdad-experiments/heic-convert.
import libheif from 'libheif-js';
import { ImageData, Canvas, createCanvas } from 'canvas'
type Props = {
buffer: Buffer;
quality: number;
};
const processSingleImage = (image: any): Promise<any> => {
return new Promise((resolve, reject) => {