This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.extend(_.templateSettings, { | |
encode: /<%=([\s\S]+?)%>/g, | |
interpolate : /<%==([\s\S]+?)%>/g | |
}); | |
_.extend(_, { | |
// Taken from Backbone.js's escapeHTML() | |
escape: function(string) { | |
return (''+string).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/'); | |
}, | |
template: function(str, data) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Chainable { | |
private $obj; | |
private $result; | |
public function __construct($obj){ | |
$this->obj = $obj; | |
} | |
public function __call($method, $args) { | |
if (substr($method, 0, 1) == '_') { | |
array_unshift($args, $this->result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A wrapper class for PHP resourcse. | |
* | |
* Used for wrapping PHP resources in an object, and working with them in an | |
* Object-Oriented manner. | |
* | |
* Some methods are prefixed with `_` even though they're public to avoid | |
* clashes with resource-related functions. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. See | |
* http://sam.zoy.org/wtfpl/COPYING for more details. */ | |
// Written by Shesek, http://www.shesek.info/php/toodledo-api | |
class Toodledo { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.setDefault = function (args) { | |
for (var i = args.length + 1; i<arguments.length; i++) { | |
args[i-1] = arguments[i]; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works with `global` instead of `window` when available (nodejs environment), no Backbone dependency, | |
# no ev[ai]l for rendering variables and a shorter `{...}` syntax. | |
(global or window).t = (id, vars = {}) -> | |
(i18n[__locale][id] or i18n.en[id] or "(?) #{id}") | |
.replace /\{(\w+)\}/g, (a, k) -> vars[k] or "?#{k}" | |
### | |
i18n= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require 'underscore' | |
{Assign, Value, Literal, Access, Block, Class, Op, Obj, Arr, For, Index, Call, Return, If, Throw} = nodes = require '../nodes' | |
exports.originals = originals = {} | |
exports.codeblock = codeblock = (block) -> | |
return block unless block? | |
if typeof block is 'function' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inject = (args..., fn) -> | |
script = document.createElement 'script' | |
script.innerHTML = """ | |
Array.prototype.pop.call(document.getElementsByTagName('script')).innerText = JSON.stringify(function() { | |
try { return #{ fn.toString() }.apply(window, #{ JSON.stringify args }); } | |
catch(e) { return {isException: true, exception: e.toString()}; } | |
}()); | |
""" | |
document.body.appendChild script | |
response = JSON.parse script.innerText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
autocompleteFormat = (url) -> (request, response) -> $.get (url.replace '%s', encodeURIComponent request.term), response, 'json' | |
# Usage | |
$('#search').autocomplete | |
source: autocompleteFormat '/search/%s.json' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults = writable: true, enumerable: true, configurable: true | |
initializer = (key) -> (val) -> | |
prop = Object.create defaults | |
prop[key] = val | |
prop | |
value = initializer 'value' | |
getter = initializer 'get' | |
setter = initializer 'set' |
OlderNewer