Skip to content

Instantly share code, notes, and snippets.

View thewhodidthis's full-sized avatar
🔘

Sotiri Bakagiannis thewhodidthis

🔘
View GitHub Profile
@thewhodidthis
thewhodidthis / com.thewhodidthis.dnsmasq.plist
Created June 30, 2019 19:54
Brew dnsmasq property list clone for pkgsrc, added user option
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.thewhodidthis.dnsmasq</string>
<key>ProgramArguments</key>
<array>
<string>/opt/pkg/sbin/dnsmasq</string>
<string>--keep-in-foreground</string>
@thewhodidthis
thewhodidthis / gist:734b8eba4e809b89d3694bc45b608089
Last active September 24, 2019 09:58
Downsample images to 72dpi on macOS
sips *.jpg -s dpiHeight 72.0 -s dpiWidth 72.0
@thewhodidthis
thewhodidthis / gist:ab790849666c5dc57b2d
Last active September 24, 2019 10:11
Create animated gif from spritesheet using ImageMagick
# Resize, optimize and save sprite as looping animated gif
convert -resize 50% +repage -fuzz 1.6% -delay 8 -loop 0 *.png -layers OptimizePlus -layers OptimizeTransparency output.gif
@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 / 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.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 / index.php
Last active January 5, 2021 23:03
Simple CORS bypass
<?php
$url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL) or exit;
// This allows for catching warnings eg. when offline, or `$url` resource missing
set_error_handler(
function ($severity, $message, $file, $line) {
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
@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,
},
{