Skip to content

Instantly share code, notes, and snippets.

View chrisguitarguy's full-sized avatar

Christopher Davis chrisguitarguy

View GitHub Profile
@chrisguitarguy
chrisguitarguy / countries.php
Created August 18, 2015 21:12
A PHP array of ISO country codes to names
<?php
return array(
'AD' => 'Andorra',
'AE' => 'United Arab Emirates',
'AF' => 'Afghanistan',
'AG' => 'Antigua and Barbuda',
'AI' => 'Anguilla',
'AL' => 'Albania',
'AM' => 'Armenia',
'AO' => 'Angola',
@chrisguitarguy
chrisguitarguy / EnableSavepointsListener.php
Created August 12, 2015 21:56
Doctrine savepoints in Symfony
<?php
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Event\ConnectionEventArgs;
final class EnableSavepointsListener implements EventSubscriber
{
/**
* {@inheritdoc}
@chrisguitarguy
chrisguitarguy / notokay.php
Last active August 29, 2015 14:26
Weird PHP-ism. `notokay.php` produces an error. `ok.php` is just fine.
<?php
interface Ham
{
public function halp(\stdClass $obj=null);
}
class Spam implements Ham
{
public function halp(\stdClass $obj)
@chrisguitarguy
chrisguitarguy / form.html.twig
Last active February 10, 2017 15:33
How to use Bootstrap input groups (http://getbootstrap.com/components/#input-groups) in a Symfony form theme
{% form_theme form 'theme.html.twig' %}
{# the theme above will take care of rendering the input group #}
{{ form(form) }}
@chrisguitarguy
chrisguitarguy / gist:e969cf584a809b859691
Created July 17, 2015 00:43
How I like to do objects in WordPress plugins
<?php
/**
* The idea here is that there's a singleton-esque thing. We don't want to cause
* side effects like adding actions/filters in a constructor, so we delegate that
* to the `hook` method. `instance` provides a way for things that need to un-hook
* things to get a reference to the "global" instance.
*/
abstract class Base
{
<?php
namespace PMG\FromScratch\AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class AppBundle extends Bundle
{
// noop
}
@chrisguitarguy
chrisguitarguy / example.clj
Last active August 29, 2015 14:21
PMG 2015-05-13 dev "challenge"
(loop [rng (range 10)]
(when-let [i (first rng)]
(println (apply str (repeat i i)))
(recur (rest rng))))
RewriteEngine on
RewriteRule ^composer\.(lock|json)$ - [F,L]
RewriteRule ^vendor/.*$ - [F,L]
@chrisguitarguy
chrisguitarguy / bad_traversable.php
Last active August 29, 2015 14:19
Some example code for a blog post on https://www.pmg.com/blog/
<?php
interface Spam extends \Traversable
{
// ...
}
final class Ham implements Spam, \IteratorAggregate
{
public function getIterator()
@chrisguitarguy
chrisguitarguy / with.php
Created April 13, 2015 01:26
A *with* statement in PHP?
<?php
/*
Ideally this would be part of the language:
with (createAnObject() as $object) {
$object->doStuff();
}
This is just sugar for: