Skip to content

Instantly share code, notes, and snippets.

View joshwnj's full-sized avatar

Josh Johnston joshwnj

View GitHub Profile
@joshwnj
joshwnj / duration.php
Created January 30, 2012 22:27
Creating ISO 8601 durations
<?php
$parts = secondsToDuration(61);
assert($parts['hours'] === 0);
assert($parts['minutes'] === 1);
assert($parts['seconds'] === 1);
assert('PT0H1M1S' === formatDuration($parts));
$parts = secondsToDuration(7202);
assert($parts['hours'] === 2);
@joshwnj
joshwnj / gist:1089055
Created July 18, 2011 09:53
Setting up heroized locally
For apache virtualhost you just need something simple like this:
<VirtualHost *:80>
ServerName heroized
DocumentRoot /vagrant/heroized
<Directory /vagrant/heroized>
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
/**
* Generic behaviour for an object which can observe objects
* @param {array | object} items
*/
Xteam.Observer = function(items) {
items = items || [];
// wrap items in an array
if (typeof items.length == "undefined") {
items = [items];
#!/bin/sh
PWD=`dirname $0`
cd $PWD
## memcached
~/src/term.sh -t memcached
## couchdb
~/src/term.sh -t sudo -i -u couchdb couchdb
@joshwnj
joshwnj / test
Created February 10, 2011 22:46
#content {
background: blue;
}
<?php
chdir(dirname(__FILE__));
require_once '../app/setup.php';
$username = $argv[1];
if (!$username) {
echo "usage {$argv[0]} {username} {new_email}\n";
exit;
}
@joshwnj
joshwnj / text_overflow.js
Created October 18, 2010 23:18
detect text overflow and crop, inserting an ellipsis
var TextOverflow = {
crop: function(elm) {
var w = elm.width(),
t = elm.text(),
child;
elm.html('<span style="overflow: hidden; white-space: nowrap">'+t+'</span>');
child = elm.children(":first-child");
while (t.length > 0 && child.width() > w) {
t = t.substr(0, t.length - 1);
@joshwnj
joshwnj / hijack.js
Created October 14, 2010 01:19
hijack a js function
/**
* Hijack a function with custom behaviour
* @param {object} Context object
* @param {string} Name of the context object's function
* @param {function} Override function
* @return {function} Original function
*/
function hijack(object, funcName, override) {
var original = object[funcName];
object[funcName] = override(original);
<?php
/**
* Instead of adding each js file one by one to a page,
* we define a chain of dependencies and then just include the top-level components.
*
* This makes it easier to see what components are being used on a page,
* and easier to add/remove/replace components.
*/
<?php
echo '
<ul>';
for($a=0;$a<count($this->xmlobj->entry);$a++) {
$attr = $this->xmlobj->entry[$a]->attributes();
$class = '';
if("{$attr['link']}" == "{$fbc['item_a']}") {
$class = 'selected ';
}
if($a == 0 && $fbc['item_a'] == '') {