Skip to content

Instantly share code, notes, and snippets.

View autr's full-sized avatar
🌓

Gilbert Sinnott autr

🌓
View GitHub Profile
# Svelte 5 Explorations
I have been using Svelte 5 to refactor a creative coding toolkit previously written in Svelte 4.
The major change in coding style is to take full advantage of reactivity in JS classes (ie. .svelte.js files), and move logic out of components into JS clasees, with the component file only handling HTML/CSS rendering of a reactive Svelte object.
To do this, I uses a dual .svelte.js file to each .svelte file, and various base classes to handle singleton patterns with Map.
In doing so, the main unknown has been what pattern to use when syncronising a component's props with the attendant JS object.
@autr
autr / CalculatePixels.js
Last active September 19, 2022 22:59
Calculate pixels from CSS value.
export function CalculatePixels( str, el ) {
try {
const value = parseFloat( str )
const unit = str.replace(value, '').toLowerCase()
const { innerWidth, innerHeight } = window
const run = {
['%']: () => (el.offsetWidth * (value/100)),
px: () => value,
vw: () => (innerWidth * (value/100)),
@autr
autr / label.sh
Created September 14, 2021 17:24
Automatically label a folder on MacOS / OSX
# brew install folderify
# brew install imagemagick
@autr
autr / normalise.sh
Created August 3, 2021 20:12
FFMPEG normalise volume of audio files
#!/bin/bash
# Using pip install ffmpeg-normalize
for f in ${1}*.wav
do
echo $f
ffmpeg-normalize ${f} -of ${1}normalized/ -ext wav
done
@autr
autr / PCM5102.md
Last active July 27, 2021 09:14
PCM5102 DAC / Hifiberry DAC with Raspberry Pi Zero / 3B+ / 4
@autr
autr / PCM5102A-Raspberry-Pi.md
Last active June 30, 2021 17:16
PCM5102A Audio on Raspberry Pi (Zero)

Circuits

Any PCM5102A board connected up to pins:

VIN = 3.3V (NOT 5V)
GND = GND
LCK = GPIO19/35 (PCM FS)
DIN = GPIO21/40 (PCM DOUT)
BCK = GPIO18/12 (PCM CLK)
@autr
autr / processes.js
Created April 30, 2021 17:26
SvelteJS store for system statuses
import { writable, get } from 'svelte/store'
const ERROR = 'error'
const SUCCESS = 'success'
const TRY = 'try'
function init() {
const { subscribe, set, update, get } = writable({
log: [],
@autr
autr / timestamp.js
Created April 30, 2021 16:23
UNIX Timestamps w/ JS
const timestamp = e => Math.floor(Date.now() / 1000)
const date = timestamp => new Date( timestamp * 1000 )
@autr
autr / move.js
Created April 27, 2021 15:42
Move item in an array JS
const moveInArray = (arr, from, to) => {
if (to >= arr.length) {
var k = to - arr.length + 1
while (k--) {
arr.push(undefined)
}
}
arr.splice(to, 0, arr.splice(from, 1)[0])
return arr
}
@autr
autr / slugify.js
Created April 2, 2021 02:12
Turn a bit of text into a URL-friendly slug
export default text => text.toString().toLowerCase()
.replaceAll(' ', '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -