Skip to content

Instantly share code, notes, and snippets.

View connordavison's full-sized avatar

C. Davison connordavison

View GitHub Profile
<?php
/**
* A helper class for cronjobs.
*
* @author C. Davison
*/
class CronHelper
{
/**
* Valid & unique date format strings for each type of cron part.
<?php
use JMS\Serializer\Annotation as JMS;
use JMS\Serializer\SerializerBuilder;
class A {
/**
* @JMS\Type("integer")
*/
protected $x;
@connordavison
connordavison / whatson.sh
Created November 7, 2016 10:54
whatson.sh
# Lists all unique branches merged into given branch, assuming regular commit message given
#
# Params:
# - Name of branch to assess
#
function whatson() {
git log --oneline $1 | grep "Merge branch.*$1" | cut -d' ' -f4 | sort | uniq
}
@connordavison
connordavison / xdebug
Last active January 18, 2017 10:55
Toggle Xdebug
#!/bin/bash
XDEBUG='zend_extension.*=.*xdebug'
function xdebug_on {
if grep -q "^;$XDEBUG" $1; then
echo "Enabling Xdebug $1"
cat $1 | sudo sed -i.bak "s|^;\($XDEBUG\)|\1|g" $1
fi
}
~/symfony/ $ # Ensure COMPOSER_HOME='~/.composer/'
~/symfony/ $ composer global require psy/psysh
~/symfony/ $ # Obtain sysh script
~/symfony/ $ chmod +x sysh
~/symfony/ $ mkdir -p ~/.composer/bin/
~/symfony/ $ mv sysh ~/.composer/bin/
~/symfony/ $ # Add ~/.composer/bin to path if necessary
~/symfony/ $ sysh
Psy Shell v0.7.2 (PHP 5.6.20-1+deb.sury.org~precise+1 — cli) by Justin Hileman
#!/bin/sh
WEBROOT=~/www/
if [ ! -d $WEBROOT ]; then
mkdir $WEBROOT -p
fi
cd $WEBROOT
# Attempt to update the repo
@connordavison
connordavison / inject.js
Created December 31, 2015 14:06
Inject MathJax into the page (protocol agnostic).
(function () {
var cdn, config;
if (typeof MathJax !== "undefined" && MathJax !== null) {
return;
}
config = document.createElement('script');
config.setAttribute('type', 'text/x-mathjax-config');
config.innerHTML = "MathJax.Hub.Config({\n tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}\n});";
@connordavison
connordavison / bootstrap.php
Created December 7, 2015 21:41
PsySH bootstrap for finding the nearest autoloader. Doesn't pollute the global scope.
<?php
call_user_func(function () {
$autoloader = 'vendor/autoload.php';
do {
if (is_readable($autoloader)) {
require_once $autoloader;
echo "Autoloader loaded: $autoloader.\n";
break;
}
var TodoList = React.createClass({
render: function () {
return <ul>
{this.props.items.map(function (v) { return <li>{v}</li>; })}
</ul>;
}
});
var Todo = React.createClass({
@connordavison
connordavison / JSONResponse.php
Last active November 11, 2015 14:48
A JSend compliant JSONResponse class. https://labs.omniti.com/labs/jsend
<?php
class JSONResponse implements JSend, Sendable
{
private $data;
public function error($message, $code = 0, $data = null)
{
$this->data = array(
'status' => self::STATUS_ERROR,