This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if($userSchools[0]){ | |
| $school_ids = array(); | |
| foreach($userSchools as $school) { | |
| $school_ids[$school['school_id']] = $school['school_id']; | |
| } | |
| $school_ids = array_filter($school_ids); | |
| if(count($school_ids) > 0) { | |
| $schools = "school_id IN ("; | |
| $schools .= implode(',', $school_ids); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Run this on http://elections.nytimes.com/2012/results/president/big-board | |
| $('.bucket tbody').each(function(){ | |
| var bucket = $(this); | |
| var sum = 0, dem = 0, rep = 0, ct = 0, report = 0; | |
| bucket.find('tr').each(function(){ | |
| if($(this).find('.ev-cell').length > 0) { | |
| ct++; | |
| var ev = parseInt($(this).find('.ev-cell').text()); | |
| dempct = parseInt($(this).find('.nytint-pct-dem').text()); | |
| reppct = parseInt($(this).find('.nytint-pct-rep').text()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Only accept even arguments in the URL | |
| */ | |
| $app->route('even', new Regex('#^/number/(?P<number>[0-9]+)/?$#'), function(){ | |
| echo "The number was even."; | |
| })->validate(function($request) { return $request['number'] % 2 == 0;}); | |
| /** | |
| * Only accept odd arguments in the URL | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function seive($candidates, $min = 0, $max = 0) { | |
| $primes = array(); | |
| $last = ($max == 0) ? floor(end($candidates) / 2) : $max; | |
| $i = ($min == 0) ? reset($candidates) : $min; | |
| while($i <= $last) { | |
| $candidates = array_filter($candidates, function($n) use ($i, &$primes) { | |
| if($n < $i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ); | |
| } |