Skip to content

Instantly share code, notes, and snippets.

View michaeltwofish's full-sized avatar

Michael C. Harris michaeltwofish

  • South Australia, Australia
View GitHub Profile
@michaeltwofish
michaeltwofish / gist:1702154
Created January 30, 2012 02:45
Get the last PHP error
lasterror() {
logpath=/usr/local/www-conf/logs/$1-phplog;
error=(${(f)$(awk -F: '/PHP Fatal error|\[error\]/ { lines[last] = NR } END { print lines[last] }' $logpath)});
[[ -n $error ]] && tail -n +$error $logpath
}
$test = Test::create();
$form1 = new Form(array('name' => 'Form 1'));
$form2 = new Form(array('name' => 'Form 2'));
$form3 = new Form(array('name' => 'Form 3'));
$test->forms = array($form1,$form2,$form3);
$test->save();
@michaeltwofish
michaeltwofish / gist:1777704
Created February 9, 2012 05:53 — forked from ringmaster/gist:1777673
Get all items from a test
db.tests.remove({slug: "foo"})
db.tests.insert({slug: "foo", forms: [ {slug: "section 1", clusters: [
{slug: "cluster 1", items: [1,2,3]},
{slug: "cluster 2", items: [4,5,6]}
]}]});
var map = function() {
this.forms.forEach(function(form){
form.clusters.forEach(function(cluster){
cluster.items.forEach(function(item){
@michaeltwofish
michaeltwofish / gist:1784787
Created February 10, 2012 00:30
Lithium MongoDB map reduce example
$map = 'function() {
this.forms.forEach(function(form){
form.clusters.forEach(function(cluster){
cluster.items.forEach(function(item){
emit(item, item);
})
})
})
}';
News::applyFilter('find', function($self, $params, $chain) {
$result = $chain->next($self, $params, $chain);
$function = function($item) {
$item->content = nl2br(htmlspecialchars($item->content, ENT_QUOTES, 'UTF-8'));
$item->date_updated_pretty_date = date('j F Y', strtotime($item->date_updated));
$item->date_updated_pretty_time = date('H:i', strtotime($item->date_updated));
$item->date_created = date('F jS, Y', strtotime($item->date_created));
$item->date_updated = date('F jS, Y', strtotime($item->date_updated));
$item->dealer_groups = explode(';', $item->dealer_groups);
<?php
$input = 'some stuff <?= $this->foo ?> blah';
echo $input."\n";
echo preg_replace('/\<\?=\s*\$this->(.+?)\s*;?\s*\?>/msx', '<?php echo $this->$1; ?>', $input)."\n";
// Should output:
some stuff <?= $this->foo ?> blah
some stuff <?php echo $this->foo; ?> blah
?>
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
[epel-debuginfo]
[root@phoenix ~]# puppet agent --no-daemonize --verbose
notice: Starting Puppet client version 2.7.9
err: Could not retrieve catalog from remote server: certificate verify failed. This is often because the time is out of sync on the server or client
info: Not using expired catalog for phoenix from cache; expired at Tue Mar 13 19:26:10 +0000 2012
notice: Using cached catalog
err: Could not retrieve catalog; skipping run
err: Could not send report: certificate verify failed. This is often because the time is out of sync on the server or client
Warning: SimpleXMLElement::__construct(): Entity: line 3: parser error : Extra content at the end of the document in user/plugins/tests/tests.plugin.php line 64
user/plugins/tests/tests.plugin.php line 64:
SimpleXMLElement->__construct( …1 arg… )
[core] line 0:
TestsPlugin->action_admin_theme_get_tests( …1 args… )
system/classes/plugins.php line 80:
call_user_func_array( …1 args… )
system/handlers/adminhandler.php line 143:
Plugins::act( …1 args… )
system/handlers/actionhandler.php line 68:
@michaeltwofish
michaeltwofish / gist:2144979
Created March 21, 2012 05:52
Adding jquery to a theme
<head>
<title><?php Options::out( 'title' ); ?></title>
<meta charset="utf-8" />
<meta name="generator" content="Habari">
<!--[if IE]>
<script src="<?php Site::out_url( 'theme' ); ?>/html5.js"></script>
<![endif]-->
<?php Stack::add('template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery');?>