Skip to content

Instantly share code, notes, and snippets.

View tyler-johnson's full-sized avatar

Tyler Johnson tyler-johnson

View GitHub Profile
@tyler-johnson
tyler-johnson / handlebar-dir-precompile.js
Last active December 14, 2015 10:29
Simple directory watch and handlebar template precompile.
// DEPENDENCIES
var path = require('path'),
fs = require('fs'),
watch = require('watch'),
Handlebars = require('handlebars'),
glob = require("glob"),
_ = require('underscore');
// MAIN VARS
var exts = [ ".hbs" ],
@tyler-johnson
tyler-johnson / starter.html
Last active August 31, 2017 05:27
Basic HTML5 Starter Structure
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Page Title</title>
<link rel="stylesheet" href="" type="text/css" />
</head>
@tyler-johnson
tyler-johnson / uniqueId_base62.js
Last active December 28, 2015 01:59
Generates a unique string based on the timestamp. Scales across multiple instances if `prepend` argument is set to a unique value. Both produce a similar value, one in base 62 and the other in base 16. Preference comes down to speed and size.
// Slower, larger source, produces a 9 character string
var uniqueId = (function() {
var ALPHA_NUMERIC = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
function toAlphaNumeric(n) {
var len = ALPHA_NUMERIC.length,
digits = "";
while (n !== 0) {
var r = n % len;
@tyler-johnson
tyler-johnson / nunjucks-tpl-precompiled.js
Created December 10, 2013 18:34
nunjucks async issue
(function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["./views/question.html"] = (function() {function root(env, context, frame, runtime, cb) {
var lineno = null;
var colno = null;
var output = "";
try {
env.getTemplate("layout.html", true, function(t_2,parentTemplate) {
if(t_2) { cb(t_2); return; }
for(var t_1 in parentTemplate.blocks) {
context.addBlock(t_1, parentTemplate.blocks[t_1]);
}
@tyler-johnson
tyler-johnson / awesome-strap.sh
Last active August 29, 2015 13:57
Downloads Bootstrap and Font-Awesome, compiles less files, and copies fonts and scripts.
#!/bin/bash
echo ""
# download the latest version of bootstrap
echo "Downloading Bootstrap..."
curl -L# -o bootstrap.tar.gz https://github.com/twbs/bootstrap/archive/v3.3.2.tar.gz
mkdir bootstrap
tar -xf bootstrap.tar.gz -C bootstrap --strip-components 1
cp -R bootstrap/less/ less/
@tyler-johnson
tyler-johnson / asyncwait.js
Last active August 29, 2015 14:00
Wait on several async items to complete. Plays nice with most async JavaScript including promises.
function asyncWait(onEmpty) {
var counter = 0;
setTimeout(callback(), 0);
return callback;
function callback(cb) {
var called = false;
++counter;
return function() {

Keybase proof

I hereby claim:

  • I am tyler-johnson on github.
  • I am tylerj (https://keybase.io/tylerj) on keybase.
  • I have a public key ASCZWe4aI5q2MQsuqyVrPkWrGrZT2bqEnIhJXU1kSCqdRQo

To claim this, I am signing this object:

@tyler-johnson
tyler-johnson / asyncwhile.js
Created October 14, 2014 16:26
Asynchronous while loop for ES6 Promises.
function asyncWhile(condition, action, ctx) {
var whilst = function(data) {
return condition.call(ctx, data) ?
Promise.resolve(action.call(ctx, data)).then(whilst) :
data;
}
return whilst();
}
@tyler-johnson
tyler-johnson / README.md
Last active February 8, 2016 14:08
Simple Browserify middleware for Express with basic in-memory caching and watchify support.

Simple Browserify middleware for Express with basic in-memory caching and watchify support.

I created this as a Gist instead of Node module because Browserify bundles are one of those things better left customizable. This function, as it stands, is very limited. It has no support for things like transforms and plugins. Copy this into your app and add any desired functionality there.

Depends on:

  • Browserify - tested on v6.1, expected to work on v4.0+
  • Watchify - tested on v2.0, expected to work on v1.0+. Watchify is optional. Remove watchify require statement if not desired.
  • Express - tested with v4.9, expected to work with v3.0+

Usage

@tyler-johnson
tyler-johnson / transitionEndEventName.js
Created October 20, 2014 22:51
Determine the correct CSS3 transition end event name.
var transitionEndEventName = (function() {
var i,
undefined,
el = document.createElement('div'),
transitions = {
'transition':'transitionend',
'OTransition':'otransitionend', // oTransitionEnd in very old Opera
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
};