Skip to content

Instantly share code, notes, and snippets.

View rgrove's full-sized avatar
🥧

Ryan Grove rgrove

🥧
View GitHub Profile
YUI().use('autocomplete', 'jsonp', function (Y) {
var ac = new Y.AutoComplete({
source: function (query, callback) {
Y.jsonp('http://example.com/api/autocomplete?query=' + encodeURIComponent(query) + '&callback={callback}', {
timeout: 10000 // 10 seconds,
on: {
success: callback,
failure: function () { /* ... */ },
@rgrove
rgrove / lazy-model.js
Created April 1, 2013 21:20
Super fast read-only fake Y.Model instance.
// Super fast read-only fake Model.
var GlobalEnv = YUI.namespace('Env.Model');
function LazyModel(config) {
this.data = Y.merge(config);
this.data.clientId || (this.data.clientId = this.generateClientId());
this.lists = [];
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>pie is good</title>
<style>
html { background: #fff; }
body {
var re = /a/g,
str ='foo bar biz quux';
console.log(re.exec(str)); // => ["a"]
re.lastIndex = 0;
console.log(re.exec(str)); // => ["a"] (would be null if lastIndex weren't reset)
@rgrove
rgrove / stache.js
Created November 7, 2012 01:13
An old, aborted attempt at a performant Mustache parser.
(function () {
// -- Constructor --------------------------------------------------------------
function Stache(template) {
this.parsed = false;
this._template = template;
}
// -- Static Functions ---------------------------------------------------------
Stache.render = function (template, view, partials) {
@rgrove
rgrove / property-base.js
Created September 26, 2012 20:49
WIP on an Object.defineProperty() facade for YUI (as an alternative to Y.Attribute)
function Property() {}
Property.prototype = {
// -- Public Prototype Methods ---------------------------------------------
defineProperties: function (properties) {
return Property.defineProperties(this, properties);
},
defineProperty: function (name, descriptor) {
return Property.defineProperty(this, name, descriptor);
@rgrove
rgrove / gist:3658306
Created September 6, 2012 16:38
My .jshintrc
{
// enforcing options (true means potentially more warnings)
"bitwise": true, // true if bitwise operators should not be allowed
"curly": true, // true if curly braces should be required around blocks in loops and conditionals
"eqeqeq": true, // true if === should be required (for ALL equality comparisons)
"forin": false, // true if unfiltered 'for in' statements should be forbidden
"immed": true, // true if immediate function invocations must be wrapped in parens
"newcap": true, // true if Initial Caps must be used with constructor functions
"noarg": true, // true if arguments.caller and arguments.callee should be forbidden
function (Handlebars,depth0,helpers,partials,data) {
helpers = helpers || Handlebars.helpers;
var buffer = "", stack1, foundHelper, functionType="function", escapeExpression=this.escapeExpression, self=this, blockHelperMissing=helpers.blockHelperMissing;
function program1(depth0,data) {
var buffer = "", stack1, foundHelper;
buffer += "\n <li>";
foundHelper = helpers.item;
if (foundHelper) { stack1 = foundHelper.call(depth0, {hash:{}}); }
function (data) {
var $t='';
with(data){
$t+='<ul class="'+
Y.Escape.html( classNames.list )+
'">\
';
Y.Array.each(items, function (item) {
;$t+='\
<li>'+
@rgrove
rgrove / multi-yui.js
Created August 21, 2012 17:26
Y.Multi
YUI.add('multi', function (Y) {
/**
Loads different versions of YUI in sandboxed iframes and makes them available
for use in the parent frame by exposing them as properties on a `Y.Multi`
instance.
This is primarily intended to be used for testing. You probably shouldn't use it
for anything real.