Skip to content

Instantly share code, notes, and snippets.

View thure's full-sized avatar
🏳️‍🌈

Will Shown thure

🏳️‍🌈
View GitHub Profile
@thure
thure / opath.js
Created July 9, 2014 21:33
A function that extends an object given a path of properties, e.g. `opath(obj, 'one', 'two', 'three', null)`. Requires underscore.js to be available at `us`.
function opath(){
var args = Array.prototype.slice.call(arguments);
var object = args.shift()
, val = args.pop();
if(args.length > 0){
us.each(args, function(arg, i){
var cur;
@thure
thure / reset.less
Last active August 29, 2015 14:00
Eric Meyer's v2.0 user-agent style reset stylesheet with a .less extension, with slightly broader selectors.
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
Extended by Will Shown: gist.github.com/thure
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
@thure
thure / hash-el.amd.js
Last active August 29, 2015 14:00
An AMD module that gives a semantic string for the element that can be used in event dispatchers and/or switch statements.
define(function(){
return function(el){
var id = el.getAttribute('id');
if(id) {
return '#' + id;
}else if(typeof el.className === 'string' && el.className.length > 0){
var classes = el.className.hasOwnProperty('baseVal') ? el.className.baseVal.split(/ +/) : el.className.split(/ +/);
classes.unshift(el.tagName.toLowerCase());
return classes.join('.');
}else{
@thure
thure / router.amd.js
Created May 1, 2014 21:19
A simple router that registers callbacks for popstate events.
define(['underscore'], function(_) {
return new function() {
var self = this;
var routes = [];
var catchAllCallback = null;
this.addRoute = function(pattern, callback) {
routes.push({pattern: pattern, callback: callback});
@thure
thure / winderp.amd.js
Created May 1, 2014 21:15
A module for translating Microsoft enigmata into standard goodness. Currently only gives a JS Date from DateTime.Ticks. So… just one enigma for now.
define(function(require, exports, module){
exports.dateFromTicks = function(ticks){
try {
var sec = Math.round(ticks / 1e7);
sec -= 1.16444736e10;
return new Date(sec * 1e3);
}catch(err){
return null
}
@thure
thure / make-el.amd.js
Last active August 29, 2015 14:00
DOM element maker, which returns a pointer to the element and a promise that is resolved on insertion. Requires the additional styles to work.
define(['q', 'underscore'], function(q, _){
return function(opts){
var opts = opts || {}
, parent = opts.parent || document.body
, innerHtml = opts.html || ''
, tagName = opts.tagName || 'div'
, className = opts.className ? opts.className + ' trackInsertion' : 'trackInsertion'
, data = opts.data || {}
@thure
thure / qxhr.amd.js
Last active August 29, 2015 14:00 — forked from matthewp/gist:3099268
AJAX wrapped in Q as an AMD module with `expect` option.
define(['q'], function(Q){
return function(options) {
var deferred = Q.defer()
, req = new XMLHttpRequest();
req.open(options.method || 'GET', options.url, true);
// Set request headers if provided.
Object.keys(options.headers || {}).forEach(function (key) {
@thure
thure / find-parent.amd.js
Created May 1, 2014 18:42
Finds the first parent of an element that satisfies an iterator.
define(function(){
return function(el, iterator){
var cur = el;
while(cur.parentNode !== document.body){
if(iterator.call(null, cur)){
return cur
}else{
cur = cur.parentNode;
}
@thure
thure / Windows 8 App Platform Modernizr Output.json
Created February 15, 2013 01:35
In case you're curious, here's a JSON serialization of the development edition of Modernizr loaded into a Windows 8 Web Application.
{
"_version" : "2.6.2",
"applicationcache" : true,
"audio" : true,
"backgroundsize" : true,
"borderimage" : false,
"borderradius" : true,
"boxshadow" : true,
"canvas" : true,
"canvastext" : true,
@thure
thure / scion.windows-platform.js
Last active December 11, 2015 16:58
SCION works for Windows Store apps if you override these platform values in this way.
ajax : WinJS.xhr,
getDocumentFromUrl : function(url,cb){
this.ajax({ url: url }).then(
function (r) {
cb(null,r.responseXML);
},
function (e) {
cb(e);
}