Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
jeremykendall / Bridge.php
Last active December 1, 2015 19:52
Slim/Pimple bridge concept
<?php
// See http://pimple.sensiolabs.org/#extending-a-container
final class Bridge implements ServiceProviderInterface
{
public function __construct(PimpleContainer $container)
{
$this->container = $container;
}
@jeremykendall
jeremykendall / YourContainerProvider.php
Created December 1, 2015 18:56
Using Slim\Container::register()
use Pimple\Container;
use Pimple\ServiceProviderInterface;
final class YourContainerProvider implements ServiceProviderInterface
{
public function __construct(Container $yourExistingPimpleContainer)
{
$this->container = $yourExistingPimpleContainer;
}
@jeremykendall
jeremykendall / Forms.php
Created November 12, 2015 20:02
I've come a long way
<?php
function giganti_form_begin ( $name, $action, $method='post', $onSubmit='', $enctype='' ) {
echo "<form name=\"$name\" action=\"$action\" method=\"$method\" onSubmit=\"$onSubmit\" enctype=\"$enctype\">\n";
}
function giganti_form_div ( $formlabel, $formw ) {
@jeremykendall
jeremykendall / parentheses-do-something-awesome.markdown
Created October 30, 2015 02:42
What is this technique called?

I was talking to a friend tonight about a particular flavor of syntax error in another language. It reminded me of the below behavior in PHP. I know there's a name for this technique/syntax/idiom, but I have no idea what that name is. Anyone?

$ php -a
Interactive shell

php > echo new DateTime()->format('Ymd');
PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in php shell code on line 1

Parse error: syntax error, unexpected '-&gt;' (T_OBJECT_OPERATOR), expecting ',' or ';' in php shell code on line 1
@jeremykendall
jeremykendall / postgres-dump-restore.markdown
Last active April 27, 2021 20:27
PostgreSQL: dump and restore (to db with different name and roles even)

Postgres Export and Import

Export

pg_dump -U [superuser] -Fc [dbname] > db.dump

Import

@jeremykendall
jeremykendall / DoctrineConfig.php
Last active August 29, 2015 14:27
Doctrine2 EntityManager via Aura.Di using wrapper and factory
<?php
namespace Namespace\Di;
use Aura\Di\Config;
use Aura\Di\Container;
use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
use Doctrine\ORM\Configuration;
@jeremykendall
jeremykendall / JavaProperties.php
Created July 31, 2015 00:03
Java Config Writer
<?php
namespace Whatevs\Config\Writer;
use Zend\Config\Writer\WriterInterface;
class JavaProperties implements WriterInterface
{
/**
* Who cares. Funkatron is going to have to fix it regardless.
@jeremykendall
jeremykendall / example.js
Created February 27, 2015 16:38
Graph Story Neo4j nodejs example - seraph
// Run from the command line with `node example.js`
// Replace the example URL with your own from https://console.graphstory.com/graphs/list
var db_url = "https://user:pass@example-url.do-stories.graphstory.com:7473";
var db = require("seraph")(db_url);
db.save({ name: "Test-Man", age: 40 }, function(err, node) {
if (err) throw err;
console.log("Test-Man inserted.");
db.delete(node, function(err) {
@jeremykendall
jeremykendall / user.php
Last active August 29, 2015 14:14
Westin Shafer Brain Teaser
<?php
// Original post: https://www.facebook.com/groups/2204685680/permalink/10153079722090681/
// Run from the CLI using `php -f user.php`
// Always turn error reporting all the way up in dev
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
@jeremykendall
jeremykendall / auth.php
Last active August 29, 2015 14:11
DoctrineModule stand-alone auth configuration (see https://github.com/doctrine/DoctrineModule)
<?php
// ... snip ...
use DoctrineModule\Authentication\Adapter\ObjectRepository as AuthenticationAdapter;
use DoctrineModule\Authentication\Storage\ObjectRepository as AuthenticationStorage;
use DoctrineModule\Options\Authentication as AuthenticationOptions;
use JeremyKendall\Slim\Auth\Bootstrap;
use Zend\Authentication\Storage\Session as SessionStorage;