Skip to content

Instantly share code, notes, and snippets.

View chrisguitarguy's full-sized avatar

Christopher Davis chrisguitarguy

View GitHub Profile
RewriteEngine on
RewriteRule ^composer\.(lock|json)$ - [F,L]
RewriteRule ^vendor/.*$ - [F,L]
@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))))
<?php
namespace PMG\FromScratch\AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class AppBundle extends Bundle
{
// noop
}
@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
{
@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)
#!/usr/bin/env boot
(require '[clojure.string :as string])
(defn- string->int [string]
(Integer/parseInt string))
(defn- make-case [[credit num-items items]]
{:credit (string->int credit)
:items (map-indexed vector (map string->int (string/split items #"\s+")))})
@chrisguitarguy
chrisguitarguy / mongowtf.php
Last active August 29, 2015 14:28
Does $setOnInsert not work with a projection?
<?php
$mongo = new \MongoClient();
$col = $mongo->testDb->testCollection;
$col->drop();
// only returns the `_id` attribute, despite the "fields" argument
var_dump($col->findAndModify([
'test' => 'one',
@chrisguitarguy
chrisguitarguy / mongo.php
Last active August 29, 2015 14:28
Just some MongoDB PHP API Weirdness I guess?
<?php
$mongo = new \MongoClient();
$col = $mongo->testDb->testCollection;
$col->drop();
$col->insert(['test' => 'one']);
// works perfectly
var_dump(iterator_to_array($col->find([
'test' => 'one',
], ['test'])));
<?php
interface Article
{
public function getIdentifier();
public function getTitle();
public function setTitle($title);
public function getBody();
public function setBody($body);
public function getYear();
@chrisguitarguy
chrisguitarguy / remove-attachments.php
Created August 28, 2011 19:35
Ridirect Wordpress attachment pages
<?php
/*
Plugin Name: Kill Attachment Pages
Plugin URI: http://pmg.co/
Description: Redirects all attachment pages to their parent page
Version: 1.0
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: creative commons/GPL2
*/