Skip to content

Instantly share code, notes, and snippets.

View thewhodidthis's full-sized avatar
🔘

Sotiri Bakagiannis thewhodidthis

🔘
View GitHub Profile
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:22
Numerical string to number convert
// "1.2" -> 1.2
console.assert(convert('1.2') === 1.2)
// " " -> " " (not a number)
console.assert(isNaN(convert(' ')))
console.assert(isNaN(convert('')))
// "12a" -> "12a" (not a number)
console.assert(convert('12a') === '12a')
console.assert(isNaN(convert('12a')))
// null -> null (not a number)
console.assert(convert(null) === null)
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:22
Super basic text diff probe via terser
'use strict'
const { exec } = require('child_process')
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const util = require('util')
const { minify } = require('terser')
const readFile = util.promisify(fs.readFile)
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:23
Find the median value in array of numbers
const assert = require('assert')
// I'm trusting R's built in helper for calculating expected values
// https://repl.it/repls/IroncladLightpinkBookmark
const samples = [
{
input: [187],
expected: 187,
},
{
@thewhodidthis
thewhodidthis / app.webmanifest
Last active September 13, 2023 19:52
This site is down
{
"background_color": "#fff",
"description": "Web dev job gone south.",
"display": "fullscreen",
"icons": [
{
"purpose": "maskable",
"sizes": "192x192",
"src": "icon.png",
"type": "image/png"
@thewhodidthis
thewhodidthis / index.html
Last active September 24, 2020 05:37
Select all
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Select all to reveal page content">
<title>Select all</title>
<style>
html {
color: white;
display: flex;
@thewhodidthis
thewhodidthis / randint.js
Last active August 8, 2021 16:23
Towards a NumPy inspired bound random integer producer
const assert = require('assert');
// Produce random (signed) integers from min inclusive to max exclusive
function randint(min = 0, max) {
let lo = min;
let hi = max;
if (typeof max === 'undefined') {
hi = lo;
lo = 0;
@thewhodidthis
thewhodidthis / index.js
Created October 14, 2019 13:37
Batch create fragmented mp4 copies using bento4
#!/usr/bin/env node --use-strict
const path = require('path')
const { exec, execSync } = require('child_process')
const { readdir } = require('fs')
const bento4 = require('bento4-installer')
const assets = path.join(__dirname, './assets')
readdir(assets, async (error, filesMaybe) => {
@thewhodidthis
thewhodidthis / index.js
Last active October 14, 2019 13:36
Get blob duration
// Adapted from,
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadedmetadata_event
async function getBlobDuration(blob) {
const buffer = document.createElement('video')
const result = new Promise((resolve, reject) => {
buffer.onerror = reject
buffer.onloadedmetadata = () => {
resolve(buffer.duration)
}
})
@thewhodidthis
thewhodidthis / gicns
Created September 24, 2019 10:36
Generate iconset for png on macOS
#!/bin/sh
# Helps produce iconsets
# Usage:
# ./gicns input.png output.icns
# Reference:
# http://stackoverflow.com/questions/12306223/how-to-manually-create-icns-files-using-iconutil
# Shortcut
@thewhodidthis
thewhodidthis / gfilm
Last active October 9, 2019 08:46
Turn mp4 video into gif strip using ffmpeg and IM
#!/bin/sh
# Helps turn videos into gif strips
# Usage:
# ./gfilm input.mp4 output.gif
# Reference:
# https://imagemagick.org/script/montage.php
# Shortcut