Skip to content

Instantly share code, notes, and snippets.

View ringmaster's full-sized avatar

Owen Winkler ringmaster

View GitHub Profile
@ringmaster
ringmaster / ttt.php
Created October 23, 2012 20:23
Tic Tac Toe
<?php
function checkwin($board, $pos, $who) {
$set = '';
foreach($pos as $pt) {
$set .= $board[$pt[1]][$pt[0]];
}
if($set == str_repeat($who, 3)) return true;
return false;
}
@ringmaster
ringmaster / gist:3621673
Created September 4, 2012 14:30
Speaker Bio
Owen started coding at age eight and even then knew that it was his calling. After a 10+ year stint as a commercial desktop application developer in the oil industry, he turned to using his code knowledge for good by contributing to open source projects such as WordPress. As one of the founders of the Habari Project, he helps coders gain collaborative experience via open source. Owen now applies this cumulative coding and management experience in his internet consultancy, Critical Hit. In his spare time, Owen brews beer and teaches his two kids to play euro-style board games.
@ringmaster
ringmaster / gist:3491426
Created August 27, 2012 19:14
User::identify()
/**
* Check for the existence of a cookie, and return a user object of the user, if successful
* @return User user object, or false if no valid cookie exists
*/
public static function identify()
{
$out = false;
// Let plugins set the user
if ( $out = Plugins::filter('user_identify', $out) ) {
self::$identity = $out;
@ringmaster
ringmaster / gist:3397748
Created August 19, 2012 21:12
Assert Associative Equality
public function assert_associative_equal($value1, $value2, $message = 'Assertion failed', $output = null)
{
$fn = function($value1, $value2) use (&$fn) {
foreach($value1 as $k => $v) {
if(is_scalar($v)) {
if(!is_scalar($value2[$k]) || $value2[$k] != $v) {
return false;
}
}
elseif(is_object($v)) {
@ringmaster
ringmaster / test.plugin.php
Created August 6, 2012 04:23
habari test plugin
<?php
class Test extends Plugin
{
public function action_init()
{
// Not sure what the heck this was for.
$this->add_template('block.pbi', dirname( __FILE__ ) . '/block.pbi.php' );
$this->add_rule(
@ringmaster
ringmaster / gist:3219593
Created July 31, 2012 19:08
Filter on postinfo debate == '0' and content type == 'entry'
public function act_display($paramarray = array( 'user_filters'=> array() )) {
$user_filters = array('all:info' => array( 'debate' => '0' ), 'content_type' => 'entry');
$paramarray['user_filters'] = array_merge($user_filters, $paramarray['user_filters']);
parent::act_display( $paramarray );
}
@ringmaster
ringmaster / gist:3199354
Created July 29, 2012 14:54
Exclude posts with info debate != 0 from the home display
public function filter_posts_get_update_preset($preset_parameters, $presetname, $paramarray) {
switch($presetname) {
case 'home':
$notallinfo = isset($preset_parameters['not:all:info']) ? Utils::single_array($preset_parameters['not:all:info']) : array();
$notallinfo['debate'] = 0;
$preset_parameters['not:all:info'] = $notallinfo;
break;
}
return $preset_parameters;
}
@ringmaster
ringmaster / gist:3165682
Created July 23, 2012 19:31
Habari shorttags
public static function filter_post_content_out_7( $content, $post )
{
$regex = '%\[(\w+?)(?:\s+(.+?))?/\]|\[(\w+?)(?:\s+(.+?))?(?<!/)](?:(.*?)\[/(\w+?)])%si';
if(preg_match($regex, $content, $matches)) {
$matches = array_pad($matches, 6, '');
$code = $matches[1] . $matches[3];
$attrs = $matches[2] . $matches[4];
$code_contents = $matches[5];
preg_match_all('#(\w+)\s*=\s*(?:(["\'])?(.*?)\2|(\S+))#i', $attrs, $attr_match, PREG_SET_ORDER);
@ringmaster
ringmaster / casbah.css
Created June 22, 2012 17:49
Casbah CSS
/*Created by http://freehtml5templates.com
reset*/
* {
margin: 0;
padding: 0;
}
@font-face {
font-family: AdamskySFRegular;
src: url('adma-webfont.eot');
src: url('adma-webfont.eot?#iefix') format('embedded-opentype'), url('adma-webfont.woff') format('woff'), url('adma-webfont.ttf') format('truetype'), url('adma-webfont.svg#AdamskySFRegular') format('svg');
@ringmaster
ringmaster / gist:2838993
Created May 30, 2012 21:10
Get a post, find posts with any of the same tags that match
<?php
$post = Posts::get(array('slug' => 'habari', 'fetch_fn' => 'get_row'));
$related = Posts::get( array( 'vocabulary' => array( 'any:tags' => $post->tags) ) );
Utils::debug($post->title, $related);
?>