Skip to content

Instantly share code, notes, and snippets.

View autr's full-sized avatar
🌓

Gilbert Sinnott autr

🌓
View GitHub Profile
@autr
autr / CalculatePixels.js
Last active September 19, 2022 22:59
Calculate pixels from CSS value.
View CalculatePixels.js
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
View label.sh
# brew install folderify
# brew install imagemagick
@autr
autr / normalise.sh
Created August 3, 2021 20:12
FFMPEG normalise volume of audio files
View normalise.sh
#!/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
View PCM5102.md
@autr
autr / PCM5102A-Raspberry-Pi.md
Last active June 30, 2021 17:16
PCM5102A Audio on Raspberry Pi (Zero)
View PCM5102A-Raspberry-Pi.md

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
View processes.js
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
View timestamp.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
View move.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
View slugify.js
export default text => text.toString().toLowerCase()
.replaceAll(' ', '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
@autr
autr / download.js
Created March 18, 2021 01:54
modern node https file download (2021 and the future)
View download.js
// request is deprecated and stackoverflow is crusty
const download = async (url, dest) => {
return await new Promise((resolve, reject)=> {
const file = fs.createWriteStream(dest)
const request = https.get(url, (res) => {
if (res.statusCode !== 200) return resolve( res )
const size = res.headers[ 'content-length' ]
let pro = 0