Skip to content

Instantly share code, notes, and snippets.

@kribblo
kribblo / full-album-to-youtube.sh
Last active March 3, 2021 22:44
Rip CD, make uploadable to Youtube with one image on Ubuntu with abcde and ffmpeg
# Not sure exacty which are needed, this worked
sudo apt install abcde id3 id3v2 eyed3 normalize-audio vorbisgain mkcue ffmpeg flac
# Rip CD, output a cue file with timestamps
abcde -1 -o flac -a default,cue,playlist
# -vf pad is if ffmpeg complains about image not having proportions divisible by 2, adds one pixel black padding
ffmpeg -loop 1 -i IMAGE.jpg -i ALBUM.flac -c:v libx264 -c:a copy -shortest -vf pad="width=ceil(iw/2)*2:height=ceil(ih/2)*2" -strict -2 ALBUM.mp4
@kribblo
kribblo / image-loader.js
Created March 19, 2019 10:38
Minimal image loader with promises
const imageLoader = {
/**
* Load a list of img URLs then resolve a Promise
*
* @param {String[]} urls images to load
* @param {Number} [retries=0] number of times to retry on img.onerror
* @return {Promise<HTMLImageElement[]|String>} return the loaded image elements in preserved order, or the first URL to fail on rejection
*/
loadImages(urls, retries = 0) {
@kribblo
kribblo / check-size.js
Last active February 27, 2019 12:40
Check minimum size of a file on command line (node) or in npm run scripts
#!/usr/bin/env node
const fs = require('fs');
if(process.argv.length < 4) {
console.error('Usage:', 'node check-size.js file size');
process.exit(1);
}
const file = process.argv[2];
@kribblo
kribblo / cbz.sh
Created February 5, 2019 14:28
CBZ a bunch of directories (Chapter[01-21]) to comic archives
for i in {01..21}; do zip -j -r "ComicName$i.cbz" "Chapter$i"; done
@kribblo
kribblo / npm-unpublish-range.sh
Created March 19, 2018 10:09
npm unpublish a range of versions
# Example: npm unpublish the-package from 0.5.31 to 0.5.41
for i in $(seq 31 41); do npm unpublish "the-package@0.5.$i"; done
# list available versions of the-package:
npm show the-package versions
@kribblo
kribblo / scale-css.pl
Created September 20, 2017 15:03
Quick one-off hack in Perl to scale some CSS properties
perl -pi -e 's/(width|height|margin-?\w*|padding-?\w*|font-size): ([\d+\.])(vw|vh|%|px)/"$1: ".sprintf("%.2f", $2*(1\/0.85)).$3/e' file.css
@kribblo
kribblo / git-pull-all.sh
Last active October 31, 2018 14:14
Shell script to pull all git repositories in one directory or workspace
#!/bin/sh
/usr/bin/find ~/Workspace -mindepth 1 -maxdepth 1 -type d -print -exec /usr/bin/git -C {} pull --ff-only --all \;
@kribblo
kribblo / SiteLocalIp.java
Last active May 10, 2019 02:30
Get site local ip in Java, skipping loopback, docker etc
package io.github.kribblo.ip;
import java.net.*;
import java.util.Collections;
public class SiteLocalIp {
public static String getSiteLocalIp() throws SocketException, UnknownHostException {
return Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
.filter(SiteLocalIp::isValidInterface)
.flatMap(i -> Collections.list(i.getInetAddresses()).stream())
@kribblo
kribblo / CamelCase.velocity
Last active February 15, 2017 19:15
IntelliJ File & Code Templates
## Inspired by https://gist.github.com/Pencroff/69ebdd4d57ad11b2eaba
## file name transformation
## file-name => FileName
## Sources:
## http://stackoverflow.com/questions/6998412/velocity-string-function
## http://stackoverflow.com/questions/21288687/using-velocity-split-to-split-a-string-into-an-array-doesnt-seem-to-work
## http://velocity.apache.org/engine/releases/velocity-1.7/apidocs/org/apache/velocity/util/StringUtils.html#split(java.lang.String, java.lang.String)
## File and Code Templates -> Includes -> Save as "CamelCase"
#set( $camelCaseName = "" )
@kribblo
kribblo / size-helper.js
Last active September 25, 2016 20:08
Helper to fit a given size into another, preserving aspect ratio
'use strict';
/**
* @exports sizeFactory
* @private
*
* @param {{width: number, height: number}} size
* @returns {sizeHelper}
*/
function sizeFactory(size) {