Skip to content

Instantly share code, notes, and snippets.

Josh Williams sjwilliams

View GitHub Profile
@sjwilliams
sjwilliams / gist:0b7345440b74087b77f8e2ea6eacb535
Created Feb 7, 2020
convert list of filenames into full URLs
View gist:0b7345440b74087b77f8e2ea6eacb535
for filename in *.mp4; do base=${filename#mp4} echo "https://youdomain.com/${filename%.mp4}-900w.mp4"; done
@sjwilliams
sjwilliams / videostack
Created Apr 19, 2019
Stack video frames onto a single image
View videostack
#!/bin/bash
# https://stackoverflow.com/questions/46145576/stack-multiple-images-in-semitransparent-layers-with-imagemagick
FRAMESDIR=frames
INPUTVIDEO=input.mp4
curl https://cdn.joshwilliams.com/projects/2019/videostack/input.mp4 -o $INPUTVIDEO
mkdir -p $FRAMESDIR
@sjwilliams
sjwilliams / grid.jsx
Created Jan 31, 2019 — forked from hughsk/grid.jsx
Generating Large Image Grids in Photoshop using Javascript
View grid.jsx
var shuffleAndValidateFiles = function(files) {
var F = new Array();
while (files.length > 0) {
var N = Math.floor(Math.random()*files.length);
if ((files[N] instanceof File) && !files[N].hidden) {
F.push(files[N]);
}
files.splice(N,1);
@sjwilliams
sjwilliams / bayphotosizes.js
Last active Feb 15, 2018
Return BayPhoto print sizes as list of height/width ratios. Markup on the https://order.bayphoto.com page.
View bayphotosizes.js
[].slice.call(document.querySelectorAll('#panel_content_4932_template li')).map(function(el){ return el.textContent.trim();}).filter(function(str){ return /^\S+x\S+$/.test(str) }).forEach(function(str){ var wh = str.split('x'); console.log(str, wh[1]/wh[0]) })
View isAutoplaySupported.js
const isAutoplaySupported = function (callback) {
var timeout;
var waitTime = 200;
var retries = 5;
var currentTry = 0;
var elem = document.createElement('video');
var elemStyle = elem.style;
function testAutoplay(arg) {
currentTry++;
@sjwilliams
sjwilliams / GIF-Screencast-OSX.md
Created Jul 14, 2017 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF
View GIF-Screencast-OSX.md

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

View js-observables-binding.md

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5
setN(10);
@sjwilliams
sjwilliams / install_ffmpeg_ubuntu.sh
Created Mar 2, 2017 — forked from xdamman/install_ffmpeg_ubuntu.sh
Install latest ffmpeg on ubuntu 12.04 or 14.04
View install_ffmpeg_ubuntu.sh
#!/bin/bash
# Bash script to install latest version of ffmpeg and its dependencies on Ubuntu 12.04 or 14.04
# Inspired from https://gist.github.com/faleev/3435377
# Remove any existing packages:
sudo apt-get -y remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
# Get the dependencies (Ubuntu Server or headless users):
sudo apt-get update
@sjwilliams
sjwilliams / amazonsum
Created Nov 27, 2016
Sum Amazon orders per page under "Your Orders"
View amazonsum
Array.prototype.slice.call(document.querySelectorAll('.a-span2 .value')).map(function(value){return Number(value.textContent.replace('$', '').trim())}).reduce(function(a,b){return a + b}, 0);
@sjwilliams
sjwilliams / uap-reboot.sh
Created Sep 26, 2016 — forked from stevejenkins/uap-reboot.sh
Simple shell script to remotely reboot a Ubiquiti UBNT UniFi Access Point (UAP, UAP-PRO, UAP-AC, etc.)
View uap-reboot.sh
#!/bin/sh
# A simple script for remotely rebooting a Ubiquiti UniFi access point
# Version 1.0 (Dec 15, 2015)
# by Steve Jenkins (http://www.stevejenkins.com/)
# Requires sshpass (https://sourceforge.net/projects/sshpass/) which
# is probably available via dnf, yum, or apt on your *nix distro.
# USAGE
You can’t perform that action at this time.