Skip to content

Instantly share code, notes, and snippets.

View csuwildcat's full-sized avatar

Daniel Buchner csuwildcat

View GitHub Profile
@csuwildcat
csuwildcat / prefix-detection.js
Last active August 29, 2015 13:57
User's browser prefix detection
var prefix = (function () {
var styles = window.getComputedStyle(document.documentElement, ''),
pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1];
return {
dom: pre == 'ms' ? 'MS' : pre,
lowercase: pre,
(function(){
var standing = '../src/images/mario-standing.png';
var marioImg = new Image();
marioImg.src = '../src/images/mario-jumping.png'; //preload the jumping image
xtag.register('x-mario', {
lifecycle: {
created: function(){
this.xtag.isSuper = this.superMario;
function(){
if (tag.shadow && this.createShadowRoot) {
var root = this.createShadowRoot();
root.appendChild(xtag.createFragment(tag.shadow));
if (CustomElements && !CustomElements.hasNative) {
Platform.ShadowCSS.shimStyles(tag.tagName, root);
}
}
}
"I was cautioning folks about email and how we have had several occasions where Congress has asked for emails and there has been an electronic search for responsive emails--so we need to be cautious about what we say in emails."
@csuwildcat
csuwildcat / service-example.js
Last active August 29, 2015 14:04
How using a standardized web service layer could work in practice
/*** General Example ***/
var googleSearch = new ServiceRequest('www.google.com', {
type: 'search',
context: 'general', // no context defaults to a 'general' search
parameters: {
query: 'origin of wolverine',
skip: 0,
take: 10
}
{
"search": {
"url": "http://www.target.com/api/search",
"cache": 600000
}
}
var fragment = xtag.createFragment(function(){/*
<dl>
<dt></dt>
<dd></dd>
</dl>
*/});
xtags.pseudo.once = {
onCompiled: function(fn){
@csuwildcat
csuwildcat / template-inflation-points.js
Last active August 29, 2015 14:07
Template inflation points for data binding and dynamic content injection
// Assume the following template:
/*
<template id="list_template">
<a>
<h2 class="title"></h2>
</a>
<ul></ul>
</template>
*/
@csuwildcat
csuwildcat / transaction-worker.js
Created October 29, 2014 01:21
Transaction Worker
var worker = new TransactionWorker({
credentials: [{}, {}, {}],
remotes: ['https://foo.com', 'https://bar.com'],
lifecycle: {
test: function(){
},
success: function(){
@csuwildcat
csuwildcat / parse-nested-parens.js
Last active August 29, 2015 14:08
Owning nested paren parsing like a boss tycoon
var matches = [],
valueFlag = 0;
key.replace(/\(|\)/g, function(match){
if (match == '(') return ++valueFlag == 1 ? '\u276A' : '(';
return !--valueFlag ? '\u276B' : ')';
}).replace(/:((\w+)\u276A(\S+?)\u276B)|:([\w-]+)/g, function(z, zz, name, value, solo){
matches.push([name || solo, value]);
});