View output.php
<?php | |
function sendFile($path, $name, $mime) { | |
$fp = @fopen($path, 'rb'); | |
if (!$fp) { | |
// error opening file; it may not exist or be readable | |
header("HTTP/1.0 404 Not Found"); | |
exit(0); | |
} | |
$size = filesize($path); |
View Prototype NodeList Object
// Prototype object that works a lot like jQuery: | |
var NodeList = Class.create(Enumerable); | |
Object.extend(NodeList.prototype, { | |
initialize: function(selector) { | |
this.elements = $$(selector); | |
}, | |
_each: function(iterator) { | |
this.elements.each(iterator); | |
return this; | |
} |
View Prototype NodeList Object.js
// Prototype object that works a lot like jQuery: | |
var NodeList = Class.create(Enumerable); | |
Object.extend(NodeList.prototype, { | |
initialize: function(selector) { | |
this.elements = $$(selector); | |
}, | |
_each: function(iterator) { | |
this.elements.each(iterator); | |
return this; | |
} |
View gist:552566
// 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. |
View install-nodejs-couchdb-on-ubuntu.sh
#! /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 |
View gist:821334
var blacklist = { | |
title: [ | |
/\bsexy?\b/i, | |
/online order/i, | |
/buy \w+ online/i, | |
/hot videos/i, | |
/earn money/i, | |
/prescription/i | |
], | |
body: [ |
View router.php
<?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 |
View app--plugins--find--models--behaviors--better_find.php
<?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 | |
* |
View curry.php
<?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]*/) { |
View 1. cleanElementChildren.js
/** | |
* 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 || {}; |
OlderNewer