Skip to content

Instantly share code, notes, and snippets.

View makeusabrew's full-sized avatar
💭
I may be slow to respond.

Nick Payne makeusabrew

💭
I may be slow to respond.
View GitHub Profile
@makeusabrew
makeusabrew / gist:772540
Created January 10, 2011 08:34
Test to see if an object can execute a dynamically passed function name
var MyObject = {
invokeMethod: function(method, args) {
if (typeof MyObject[method] == "function") {
MyObject[method](args);
} else {
throw new TypeError("MyObject has no function "+method);
}
},
someMethod: function(args) {
@makeusabrew
makeusabrew / gist:796449
Created January 26, 2011 09:10
php date validation issues
<?php
/**
@see http://www.php.net/manual/en/datetime.createfromformat.php for clarification as to what 'Y-m-d'
should be and what we'd expect this to return
*/
$date = DateTime::createFromFormat("Y-m-d", "10-01-01");
if ($date !== false) {
echo "PHP is mildly retarded";
} else {
/**
* Determine whether the supplied value's datatype is Number
* @param {Mixed} value Could be a true number: 123, 12.00, or eg: "123", "12.00"
* @return {Boolean} Whether value's type is Number, eg: "123" would be false whereas 123 would be true.
*/
function isNumber(data)
{
var num = parseFloat(data);
return ! isNaN(parseFloat(data)) && num.toString() === data.toString();
}
@makeusabrew
makeusabrew / .gitignore
Created March 11, 2011 14:30
i just wanted to fork this mother. and everyone loves typoeof
event-proxy.js
groupable-model.js
test.html
@makeusabrew
makeusabrew / label-to-placeholder.js
Created May 22, 2011 18:32
Simple jQuery snippet to convert form labels into inline placeholders
$("form :input").each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents("form").find("label[for="+eId+"]")).length == 1) {
$(elem).attr("placeholder", $(label).html());
$(label).remove();
}
});
@makeusabrew
makeusabrew / keypress.js
Created September 27, 2011 13:28
keypress nav
<script>
$(function() {
// let's make a bespoke handler for a keypress, so we can potentially
// do something like animate the A or whatever
$("li.prev a, li.next a").bind('keynav', function(e) {
// $(this) is the A element at this point
// for now, just go to the href, but we could do more fun stuff here
window.location = $(this).attr("href");
});
@makeusabrew
makeusabrew / table-columns-basic.php
Created October 5, 2011 20:50
Jaoss - Basic Table Column Declaration
<?php
class People extends Table {
protected $meta = array(
'columns' => array(
'forename' => array(
'type' => 'text',
'required' => true,
),
'surname' => array(
'type' => 'text',
@makeusabrew
makeusabrew / paths-simple.php
Created October 5, 2011 20:55
Jaoss - Simple Path Declaration
<?php
PathManager::loadPaths(
array("/about", "about")
);
@makeusabrew
makeusabrew / basic-controller.php
Created October 5, 2011 20:57
Jaoss - Basic Controller
<?php
class StaticController extends Controller {
public function about() {
// any controller logic would take place here
$title = "Hello About Page!";
// assign the value of $title to the view, where it will be accessible as $pageTitle
$this->assign("pageTitle", $title);
}
@makeusabrew
makeusabrew / simple-view.tpl
Created October 5, 2011 20:59
Jaoss - Basic View
<h1>{$pageTitle}</h1>
<p>This is my first application page!</p>