Skip to content

Instantly share code, notes, and snippets.

View sjwilliams's full-sized avatar

Josh Williams sjwilliams

View GitHub Profile
@sjwilliams
sjwilliams / gist:5137855
Created March 11, 2013 21:19
Unix Tricks
Source: http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt
I have marked with a * those which I think are absolutely essential
Items for each section are sorted by oldest to newest. Come back soon for more!
BASH
* In bash, 'ctrl-r' searches your command history as you type
- Input from the commandline as if it were a file by replacing
'command < file.in' with 'command <<< "some input text"'
- '^' is a sed-like operator to replace chars from last command

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@sjwilliams
sjwilliams / imagesToMp4
Created January 20, 2014 22:41
rename a folder of image to be sequential, then convert to an mp4
find . -name '*.JPG' | awk 'BEGIN{ a=1 }{ printf "mv %s %04d.jpg\n", $0, a++ }' | bash;
ffmpeg -r 24 -f image2 -s 1920x1280 -i %4d.jpg -vcodec libx264 -crf 15 test.mp4
umd(function(require, exports, module) {
//...
},'my-module');function umd(fn,n){
if(typeof define=='function')return define(fn); // AMD
if(typeof module=='object')return fn(require,exports,module); // CommonJS
var m={exports:{}};window[n]=fn(function(n){return window[n];},m.exports,m)||m.exports; // window
}
@sjwilliams
sjwilliams / imgix_purge_node.js
Created May 3, 2016 23:23
Purging Imgix CDN with node.js
var Curl = require( 'node-libcurl' ).Curl;
var querystring = require( 'querystring' );
var IMGIX_API_KEY = '';
function imgixPurge(url){
var curl = new Curl();
curl.setOpt(Curl.option.URL, 'https://api.imgix.com/v2/image/purger');
curl.setOpt('HTTPAUTH', Curl.auth.BASIC);
curl.setOpt(Curl.option.USERNAME, IMGIX_API_KEY);
curl.setOpt(Curl.option.TIMEOUT, 20);
@sjwilliams
sjwilliams / amazonsum
Created November 27, 2016 01:58
Sum Amazon orders per page under "Your Orders"
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 / install_ffmpeg_ubuntu.sh
Created March 2, 2017 03:20 — forked from xdamman/install_ffmpeg_ubuntu.sh
Install latest ffmpeg on ubuntu 12.04 or 14.04
#!/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 / js-observables-binding.md
Created April 18, 2017 17:50 — forked from austinhyde/js-observables-binding.md
Vanilla JavaScript Data Binding

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 / GIF-Screencast-OSX.md
Created July 14, 2017 14:50 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

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:

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++;