Skip to content

Instantly share code, notes, and snippets.

View cjsaylor's full-sized avatar

Chris Saylor cjsaylor

View GitHub Profile
@cjsaylor
cjsaylor / xdebug.ini
Created October 20, 2012 15:23
Xdebug configuration for MacGDBp
[xdebug]
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
@cjsaylor
cjsaylor / 5.1.js
Created December 3, 2012 02:53
m101 - Mongo HW 5
db.posts.aggregate( [ { $project : { 'comments.author': 1 } }, { $unwind : "$comments" }, { $group : { _id : { comments : "$comments" }, n : { $sum : 1 } } }, { $sort: {"n": -1} } ] )
<script src="/user/emails" type="text/javascript"></script>
@cjsaylor
cjsaylor / old.php
Created July 10, 2013 02:09
Google Visualization CakePHP refactor
<?php
protected function loadDataAndLabels($data, $graph_type) {
$o = '';
foreach($data['labels'] as $label) {
foreach($label as $type => $label_name) {
$o.= "data.addColumn('$type', '$label_name');\n";
}
}
$data_count = count($data['data']);
@cjsaylor
cjsaylor / example.php
Last active December 19, 2015 15:19
Google Visualization Example and HTML output
<?php
$data = array(
'labels' => array(
array('string' => 'Sample'),
array('number' => 'Piston 1'),
array('number' => 'Piston 2')
),
'data' => array(
array('S1', 74.01, 74.03),
@cjsaylor
cjsaylor / mixed_resource_testcase.php
Last active December 27, 2015 01:09
Utilizing Mongounit's trait to allow for mongo datasources in addition to mysql datasources.
<?php
use \Zumba\PHPUnit\Extensions\Mongo\TestTrait as MongoTest;
class DatabaseTestCase extends \PHPUnit_Extensions_Database_TestCase {
use MongoTest {
MongoTest::setUp as mongoSetUp;
MongoTest::tearDown as mongoTearDown;
}
@cjsaylor
cjsaylor / category_aggregate.js
Last active December 27, 2015 12:09
Category aggregate query
var getTopCategory = function(category, callback) {
var sorter = {};
sorter[category] = -1;
this.collection('results').aggregate([
{ $sort: sorter },
{ $project: {
_id: 0,
name: 1,
category_value: '$' + category
}},
@cjsaylor
cjsaylor / flyer.js
Created November 21, 2013 19:03
Eliminate those pesky flyers
// Find a flyer that's at the maximum range
var flyer = _.find(roundInfo.getMobs(), function(mob) {
return mob.type === 'flyer' && mob.position === 5;
});
if (flyer) {
commander.target(flyer.id);
commander.attackMode('ranged');
return;
}
@cjsaylor
cjsaylor / pre-commit
Created April 11, 2014 21:34
Pre-commit hook that checks code sniffer rules on PHP files
#!/bin/sh
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
@cjsaylor
cjsaylor / sample_class.php
Created November 22, 2012 14:36
Convenient PHPUnit mocking of Singleton Classes
<?php
class Sample {
public __construct() {
}
public function sayHello($name) {
return Someclass::getInstance()->hello($name);
}