Skip to content

Instantly share code, notes, and snippets.

@twalker
twalker / config.js
Created October 15, 2015 17:20
a fetch abstraction for RESTful calls to a single api
/**
* minimal configuration object.
*/
import assign from 'object-assign'
// default configuration is based on the hostname.
const cfg = {
'localhost': {
// mocks
baseApiUrl: '//localhost:3001/api/'
@twalker
twalker / minimal-env-config.js
Created June 14, 2015 22:34
minimal-env-config.js
export default {
'localhost': {
baseApiUrl: 'http://localhost:3001/api/'
},
'mytestserver.com': {
baseApiUrl: 'http://mytestapi.com/'
},
'myprod.com': {
baseApiUrl: 'http://myprod.api/'
}
@twalker
twalker / cp.js
Created April 4, 2015 22:19
cp.js
#!/usr/bin/env node
/*
An OS-agnostic file/dir copy (cp).
// copy a single file to a new location
./cp.js foo/existing.txt foo/newname.txt
// copy contents of a directory into another
./cp.js foo/ bar/
*/
@twalker
twalker / count-by-filetype.sh
Created February 12, 2015 03:19
count-by-filetype.sh
find . -type f | sed 's/.*\.//' | sort | uniq -c
@twalker
twalker / read-template
Last active August 29, 2015 14:14
read-template
// using stringify
// import foo from './foo.html'
// using brfs:
// var foo = require('fs').readFileSync('foo.html', 'utf8')
import fs from 'fs'
export default function read(path){
return fs.readFileSync(path, 'utf8')
}
@twalker
twalker / post-deploy-replace-urls.sh
Created January 23, 2015 01:07
post-deploy-replace-urls.sh
#!/bin/sh
# tbe source directory
# i.e. dev -- //sta-vs-wfmedia1/media/tbe/
SRC_DIR="$HOME/projects/Wordfly/Website/tms/nodeapp/test/file-fixtures/tbe"
# tbe destination parent directory
# i.e. staging/prod -- NEED PATH
DEST_DIR="$HOME/tmp"
echo "Copying tbe directory into destination"
@twalker
twalker / kuatos-hack.md
Last active August 29, 2015 14:13
A hack to toggle the visibility of different email content in different email clients.

Kuato's hack

The purpose of Kuato's hack is to show either :~) email content, or :~( email content, depending on the email client. MS Outlook 2007, 2010, 2013, and Outlook.com are targeted to see the :~( content. All other email clients see the :~) content.

The following email client quirks are strategically composed:

  • MS Outlook 2007, 2010, 2013 parse and adhere to mso conditional comments.
@twalker
twalker / email-conditional
Last active August 29, 2015 14:13
email-conditional
<!--[if !mso]><!-->
GOOD
<script type="text/plain">
<!--<![endif]-->
BAD
<!--[if !mso]><!-->
</script>
<!--<![endif]-->
@twalker
twalker / parse-attr-options.js
Last active August 29, 2015 14:13
Parses a string of semi-colon delimited options into a plain object.
/**
* parseAttrOptions
* Parses a string of semi-colon delimited options into a plain object.
*
* @example
* parseAttrOptions('align: center; width: 300; neat: true; yagni: [1,2,3]');
* >> {align: 'center', width: 300, neat: true, yagni: [1,2,3]}
*/
export default function parseAttrOptions(sOptions){
var opts = {};
/**
* Consolidates routes into a single router for using.
*
* Nearly all routes re-use the single page application (spa) view;
* Specific routes are to use different middleware per url (i.e. restrictTo, title, bootstrap).
*
*/
var express = require('express');
var router = express.Router();
var middle = require('../middleware');