Skip to content

Instantly share code, notes, and snippets.

View RAM92's full-sized avatar

Robert Airley-Moffat RAM92

View GitHub Profile
@RAM92
RAM92 / convert-flac-to-mp3.sh
Last active March 13, 2025 08:09
Script to convert flac files to 320kbps mp3
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg_5
trap 'echo "Aborting..."; exit 1' SIGINT
find . -type f -name "*.flac" -print0 | while read -d $'\0' flac_file; do
echo "Input file: $flac_file"
mp3_file="${flac_file%.flac}.mp3"
ffmpeg -nostats -loglevel 0 -nostdin -i "$flac_file" -vn -b:a 320k -acodec libmp3lame "$mp3_file" || { rm "$mp3_file"; exit; };
rm "$flac_file"
@RAM92
RAM92 / do-stuff.js
Created October 27, 2021 16:45
Get input from stdin or filename
#!/usr/bin/env node
const fs = require('fs');
function getInput() {
if (process.stdin.isTTY) {
const inputFileName = process.argv[2];
return fs.readFileSync(inputFileName, {encoding: 'utf8'});
} else {
return fs.readFileSync(0, {encoding: 'utf8'});
@RAM92
RAM92 / namespaced-api-creator.js
Created September 27, 2018 00:45
Create javascript API object by giving the paths to the value without creating object
/**
*
* @param obj Target object
* @param pathToFunc path string e.g. "foo.bar.baz"
* @param value value to place at this path
*/
function addFunction(obj, pathToFunc, value) {
const properties = pathToFunc.split('.');
function addProperty(obj, i=0) {