Skip to content

Instantly share code, notes, and snippets.

View sterlingwes's full-sized avatar
🍉

Wes Johnson sterlingwes

🍉
View GitHub Profile
@sterlingwes
sterlingwes / ngx_http_autoindex_module.c
Created August 28, 2012 01:06
Nginx Module: Autoindex in JSON Format
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
* Borrowed from: Zed A. Shaw
* Background: http://serverfault.com/questions/123529/how-can-i-get-json-from-nginx-autoindex
*/
#include <ngx_config.h>
@sterlingwes
sterlingwes / tourney.html
Created December 3, 2012 23:42
Tournament Bracket Generator (Javascript + CSS, no tables)
<!DOCTYPE html>
<html>
<head>
<title>Tournament Bracket Generator</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script>
$(document).on('ready', function() {
var knownBrackets = [2,4,8,16,32], // brackets with "perfect" proportions (full fields, no byes)
@sterlingwes
sterlingwes / webplatform.js
Created March 6, 2013 05:30
BlackBerry WebWorks Native Javascript Wrapper exposed at platform:///webplatform.js by webviews
(function () {
/*
Copyright 2012 Research In Motion Limited.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@sterlingwes
sterlingwes / StorytimeParser.js
Last active December 31, 2015 23:00
WIP Parser for Storytime Data
var DEFAULT_UNITS = 'hours'
var HOURS_FROM_MILLISECONDS = 3600000
var MINUTES_FROM_MILLISECONDS = HOURS_FROM_MILLISECONDS / 60
var m = require('moment')
/*
* allows for manipulating the raw data stored by Storytime
*
* filepath (string) - expects a json file relative to the execution context
@sterlingwes
sterlingwes / injected.snippet.js
Created January 3, 2016 21:06
Squarespace Parse Query String and Prefill Email Field in Contact Form
function parseSearchString () {
var qs = window.location.search
qs = qs.replace(/^\?/,'')
var parts = qs.split('&')
var params = {}
parts.forEach(function (part) {
var pair = part.split('=')
params[pair[0]] = decodeURIComponent(pair[1])
})
return params
@sterlingwes
sterlingwes / README.md
Created January 31, 2016 02:05
Converting a scanned PDF to EPUB ebook (or other format)

Caveat

You're not going to get a beautiful EPUB out the other end - if that's what you're looking for, expect to do some manual clean-up work yourself.

Basic order of operations:

  • Convert your PDF to an OCR-friendly format
  • OCR that shit into plaintext
  • Convert that plaintext into your format of choice (in this case, an EPUB)
@sterlingwes
sterlingwes / keybase.md
Created February 8, 2016 17:49
keybase.md

Keybase proof

I hereby claim:

  • I am sterlingwes on github.
  • I am sterlingwes (https://keybase.io/sterlingwes) on keybase.
  • I have a public key whose fingerprint is 85ED 9BAF 923C 814E A02C 2775 F61C 0CD9 87CB D962

To claim this, I am signing this object:

@sterlingwes
sterlingwes / README.md
Created January 5, 2017 16:53
Convert video to optimized GIF with libav (avconv)

Prerequisites

  • avconv
  • gifsicle

If you're on Ubuntu:

  • apt-get install gifsicle libav-tools

Command

@sterlingwes
sterlingwes / README.md
Last active April 4, 2018 06:05
Getting past cross-origin Web Worker exception

Cross-origin web worker scripts

If you're like me and wanted to serve your main app script from a CDN and still load a web worker, you may have encountered the following error:

Uncaught DOMException: Failed to construct 'Worker': Script at 'http://cdn.example.com/worker.js' cannot be accessed from origin 'http://example.com'

You can get around this fairly simply with importScripts by making the script you instantiate your worker with load the actual worker script from the CDN.