Skip to content

Instantly share code, notes, and snippets.

View solocommand's full-sized avatar

Josh Worden solocommand

  • Parameter1
  • Madison, WI
  • 05:55 (UTC -05:00)
View GitHub Profile
@solocommand
solocommand / DoctrineQueryLogger.php
Created June 13, 2016 21:27
Log Doctrine\MongoDB query times via event listeners and @logger svc
<?php
namespace Cygnus\ApplicationBundle\EventListener;
use Doctrine\Common\EventSubscriber;
use Doctrine\MongoDB\Event\AggregateEventArgs;
use Doctrine\MongoDB\Event\FindEventArgs;
use Doctrine\MongoDB\Event\MutableEventArgs;
use Symfony\Bridge\Monolog\Logger;
@solocommand
solocommand / ParseEmbeddedImages.php
Last active April 28, 2016 15:09
Parse out embedded images
<?php
class ParseEmbeddedImages {
public function __construct(array $doc = [])
{
$this->date = new \DateTime($doc['created']);
return $this->parse($doc['body']);
}
@solocommand
solocommand / xdebug.sh
Last active May 20, 2016 14:06
OSX XDebug CLI Toggle
#!/bin/bash
conf="/Applications/MAMP/bin/php/php5.6.10/conf/php.ini"
extension='zend_extension="/Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"'
extension_e='zend_extension="\/Applications\/MAMP\/bin\/php\/php5.6.10\/lib\/php\/extensions\/no-debug-non-zts-20131226\/xdebug.so"'
mode=$1
if [ "disable" == "$mode" ]; then
echo "Disabling Xdebug in PHP CLI configuration."
sed -i.bak s/.*zend_extension\=.*xdebug\.so.*/\;$extension_e/g $conf
exit 0
@solocommand
solocommand / xdebug.sh
Created January 15, 2016 18:18
Toggles XDebug extension for PHP CLI
#!/bin/bash
path="/Applications/MAMP/bin/php/php5.4.38/"
conf="$path/conf/php.ini"
extension='zend_extension="/Applications/MAMP/bin/php/php5.4.38/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"'
extension_e='zend_extension="\/Applications\/MAMP\/bin\/php\/php5.4.38\/lib\/php\/extensions\/no-debug-non-zts-20100525\/xdebug.so"'
mode=$1
if [ "disable" == "$mode" ]; then
echo "Disabling Xdebug in PHP CLI configuration."
sed -i.bak s/.*zend_extension\=.*xdebug\.so.*/\;$extension_e/g $conf
@solocommand
solocommand / battle.net.js
Last active November 12, 2015 18:28
Battle.net forum image loader
/**
* Automatically includes hard linked images into Battle.net forum posts
*
* @host http://us.battle.net
* @require jQuery 1.11.0
* @author solocommand <solocommand@gmail.com>
*/
$('.post-detail').each(function() {
var text = $(this).text();
var images = text.match(/https?:\/\/(?:\S){1,}\.(?:\w){2,4}\/(?:\S){1,}\.(?:\w){2,4}/ig);
@solocommand
solocommand / GH1274.php
Last active November 11, 2015 16:00
Basic models
<?php
namespace MyApp\Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
class Post
{
/**
* @MongoDB\ReferenceOne(targetDocument="User", inversedBy="posts", simple=true)
@solocommand
solocommand / LDAPConnection.php
Created October 29, 2015 17:28
LDAP\Connection.php
<?php
namespace Cygnus\Ldap;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
class Connection
{
private $params = array();
private $logger;
@solocommand
solocommand / ScriptHandler.php
Created August 11, 2015 03:04
Old CoreBundle logic
<?php
namespace Cygnus\BaseBundle\Composer;
use Composer\Script\Event;
use Sensio\Bundle\GeneratorBundle\Manipulator\KernelManipulator;
class ScriptHandler
{
#!/bin/bash
#
# Usage: ./cpimages.sh oldPath newPath
# Example: ./cpimages.sh /data/media/files/cygnus/KBDN/image /data/media/files/base/sola/kbdn/image
#
mediaPath=$1
newPath=$2
#set -x
cd $mediaPath
<?php
// ..
$start = time();
$jobs = array('processed' => array());
// For one minute, iterate over available jobs and run them.
while (time() > $start + 60) {
$query = sprintf('SELECT * FROM job WHERE status = 1 AND priority = "%s" AND (type = "onetime" OR (type = "reoccuring" AND (start is null OR NOW() >= start) AND (stop is null or NOW() < stop) AND NOW() >= DATE_ADD(last_started, INTERVAL `interval` MINUTE))) LIMIT 1;', (int) $priority);
fbl($query);