Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Currying in PHP 5.2.x for simple variables
* @author Zack Douglas <zack.douglas@wellspringsoftware.net>
*/
/**
* e.g.
* $arr = Array(1, 2, 3);
* $le2 = curry_left('ge', 2);
@zackdouglas
zackdouglas / PHP tap()
Created February 23, 2011 01:53
A rudimentary implementation of Ruby's tap(), generally useful for basic debugging.
/*
* To be used with
* <https://github.com/wellspringworldwide/PHP-ClassMixer>
*/
abstract class Tapable_Mixin {
public function tap($var_of_this, $eval) {
$$var_of_this = $this;
eval($eval);
}
}
@zackdouglas
zackdouglas / gist:856497
Created March 5, 2011 16:49
Simple Email Validation with DNS Check
<?php
/**
* checks syntax and optionally DNS records for the provided email address string
*/
function validateEmail($email, $and_dns=true) {
if (!filter_var($em, FILTER_VALIDATE_EMAIL)) {
return false;
}
if (!$and_dns) {
return true;
select ?person ?authship ?publication
where
{
?person rdf:type foaf:Person .
?person core:authorInAuthorship ?authship .
?authship core:linkedInformationResource ?publication
}
limit 10
@zackdouglas
zackdouglas / ExpandableClass.php
Created April 14, 2011 05:52
A simple PHP logger for ease of use with the decorator design pattern. This contains the abstract base class which should be extended in the least implementing _BaseLogger::resolveMessage(). As an example, this includes a sample stream logger.
<?php
/*******************************************************************************
* Expandable Class
*
* Authors:: anthony.gallagher@wellspringworldwide.com
*
* Copyright:: Copyright 2009, Wellspring Worldwide, LLC Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@zackdouglas
zackdouglas / bash_regex.sh
Created November 18, 2011 00:02
BASH variable regexp
#!/usr/bin/bash
FOO='the scarecow walks at midnight'
if [ 'the scarecrow walks at midnight' = ${FOO/scarecow/scarecrow/} ] ; then
echo 'your shell supports regex on variable retrieval'
fi
@zackdouglas
zackdouglas / app
Created January 5, 2012 14:00
A working example of a two-teired ListView in Sproutcore 1.x (Tested in 1.6.x)
Test = SC.Application.create({ NAMESPACE: 'Test', VERSION: '0.1.0', store: SC.Store.create().from(SC.Record.fixtures) }) ;
Test.Top = SC.Record.extend({
middles: SC.Record.toMany(
SC.Record.extend({
bottoms: SC.Record.toMany(
SC.Record,
{
isNested: YES,
isMaster: NO
@zackdouglas
zackdouglas / gist:1598898
Created January 12, 2012 05:06
Convoluted JS Switch Statement
var r = [ ( function (l, r) { return l + r; } ),
( function (a, b) { return '' + a + b; } )]
[ [ 0, 1 ].indexOf( 0 + /PHPSESSID/.test(document.cookie) ) ](1,2);
@zackdouglas
zackdouglas / Usage.js
Created January 19, 2012 05:59
Partials, Memoes, and Bindings
var
myObject = {
myfield: 'Not empty'
},
validations = {
myfield: Namespace.Validators.getNotEmpty('myfield', 'My Field')(myObject)
};
@zackdouglas
zackdouglas / safechars.js
Created February 2, 2012 14:49
A RegExp to identify normally safe international characters
;new RegExp('a-z:_\\s\\\\-\\\\.0-9\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u010000-\\u0EFFF\u00B7\\u0300-\\u036F\\u203F-\\u2040');