Skip to content

Instantly share code, notes, and snippets.

View gmac's full-sized avatar

Greg MacWilliam gmac

View GitHub Profile
@gmac
gmac / tree.json
Last active September 28, 2015 22:23
[
{
"id": "a",
"parent": null
},
{
"id": "b",
"parent": "a"
},
{
@gmac
gmac / assign.sh
Created March 4, 2015 23:37
Assign files to all students
# Copy assignment into each student's folder
# Run this from the day's folder
# example:
# `~/Dev/wdi/homework/week_01/d_01`
# `assign`
assign(){
# path to assignment. defaults to assignment folder.
assignment=${1:-"ASSIGNMENT_FILES/"}
# get list of directories
@gmac
gmac / expression-parser
Last active December 17, 2015 17:28
Simple lexical analysis for a JavaScript expression. Written as a prototype for pre-parsing JavaScript bindings (Epoxy.js). Will alphabetically sort the order of object property lists while removing all non-string whitespace. Example expression: 'text: all("a", "x", "c"), css:{fontWeight:"bold", color:["#f00, \\"#fee", "#00f"]}, html:firstName'
function parseBindings(bindings, sorted) {
var attrs = [];
var token = '';
bindings += ',';
for (var i = 0, len = bindings.length; i < len; i++) {
var c = bindings.charAt(i);
// Comma: chunk off tokens at list delimiter.
if (c == ',') {
@gmac
gmac / simple-ajax
Last active December 17, 2015 15:10
API: ajax('url', callbackFunction?, postData?); --> returns: a handle object with an ".abort();" method for canceling the request.
var ajax = (function( root ) {
function getRequest() {
if (root.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
else if (root.XMLHttpRequest) return new XMLHttpRequest();
else return null;
}
return function(url, callback, post) {
post = post || "";
@gmac
gmac / csv-parser
Last active December 17, 2015 13:59
CSV Parser
function parseCSV(csv, delimiter) {
delimiter = (delimiter || ",");
var pattern = new RegExp("(\\"+ delimiter +"|\\r?\\n|\\r|^)"+"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|"+"([^\"\\"+ delimiter +"\\r\\n]*))", "gi");
var quote = new RegExp("\"\"", "g");
var data = [[]];
var matches = null;
var val, d;
while (matches = pattern.exec(csv)) {
@gmac
gmac / Nixable Controller
Created February 13, 2013 22:55
Click-off dismissal behavior for a component that should close upon any mouse click, touch, or resize.
require("nixable", [
"jquery",
"underscore"
], function( $, _ ) {
return {
nixable: function( closeTest, closeCall, context ) {
var self = this;
// Clear any outstanding nix call: