This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains 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
function defineMyPlugin($) { | |
/*...*/ | |
} | |
if (typeof define == 'function') { | |
define('MyPlugin', ['jquery'], defineMyPlugin); | |
} | |
else { | |
defineMyPlugin(jQuery); | |
} |
This file contains 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 | |
// DEFAULT OPTIONS | |
$GLOBALS['ppr_mode'] = 'screen'; // mode = screen | popup | email | log | off | |
$GLOBALS['ppr_char_limit'] = 200;//1024 * 500; | |
$GLOBALS['ppr_str_limit'] = 1024 * 4; | |
$GLOBALS['ppr_backtrace_str_limit'] = 100; | |
$GLOBALS['ppr_backtrace_array_limit'] = 6; | |
$GLOBALS['ppr_backtrace_arg_limit'] = 5; | |
$GLOBALS['ppr_mailto'] = @$_SERVER['SERVER_ADMIN']; |
This file contains 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
/** | |
* Given a DOM node, clean children so the node is suitable for pasting in a rich text area | |
* @param {HTMLElement} root The DOM node to clean | |
* @param {Object} [options] Cleaning options | |
* @param {object} [options.classMap] A map of tagName to CSS class for assigning classes | |
* @returns {undefined} | |
*/ | |
function cleanElementChildren(root, options) { | |
// options may or may not be given | |
options = options || {}; |
This file contains 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 CurriedFunction { | |
public function __construct($callback/*[, $arg1][, $arg2][, $argN]*/) { | |
$this->args = func_get_args(); | |
$this->callback = array_shift($this->args); | |
} | |
public function __invoke(/*[, $arg1][, $arg2][, $argN]*/) { |
This file contains 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 | |
/** | |
* Add custom find types to your model (CakePHP 1.3) | |
*/ | |
class BetterFindBehavior extends ModelBehavior { | |
/** | |
* Trick to register methods in this class as custom find types | |
* |
This file contains 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 | |
function getViewPath($routes, $requestUri) { | |
// extract the path part of our url (e.g. '/news/3/1') | |
// and trim slashes | |
$url = trim( parse_url($requestUri, PHP_URL_PATH), '/'); | |
if ($url == '') { | |
return 'views/home.php'; | |
} | |
// get the values sent in the url |
This file contains 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
var blacklist = { | |
title: [ | |
/\bsexy?\b/i, | |
/online order/i, | |
/buy \w+ online/i, | |
/hot videos/i, | |
/earn money/i, | |
/prescription/i | |
], | |
body: [ |
This file contains 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
#! /bin/sh | |
# oops need to first install http://packages.debian.org/sid/i386/libmozjs2d/download | |
# then http://packages.debian.org/sid/i386/libmozjs-dev/download | |
# init | |
mkdir nodejs-couchdb | |
cd nodejs-couchdb | |
# nodejs |
This file contains 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
// Truncate a string to the closest word | |
String.prototype.truncateToWord = function(len) { | |
return (len = Number(len)) >= 0 ? | |
this.match(new RegExp('^([\\s\\S]{0,' + len + '})(:?\\s|$)'))[1] : | |
undefined; | |
}; | |
// Examples | |
// The "v" marks the first character out of bounds. |