Skip to content

Instantly share code, notes, and snippets.

View blockjon's full-sized avatar

Jonathan Block blockjon

  • San Francisco, CA
View GitHub Profile
@blockjon
blockjon / gist:fb3682acfc9db76ae8f7
Created February 24, 2015 09:49
register_shutdown_function() handler we use with PHPUnit
register_shutdown_function(function() {
$error = error_get_last();
if( $error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
// only log fatal-type errors; all other errors will be handled by set_error_handler() above.
if (!($errno & E_USER_ERROR || $errno & E_COMPILE_ERROR || $errno & E_PARSE || $errno & E_ERROR)) {
return;
// Get a detached document from cache
$someDude = ....; // Pull a detached document from the cache with name "John"
// Use the postupdate annotation feature to trigger a call to sayMyName()
// which simply echo's this persons name to stdout.
$someDude->queuePostUpdateEvent(
$someDude,
'sayMyName',
array()
);
@blockjon
blockjon / gist:8946114
Created February 11, 2014 23:00
This is how I'm trying to create a lazy loaded service.
$rollbarServiceDefinition = new \Symfony\Component\DependencyInjection\Definition('\RollbarNotifier');
$rollbarServiceDefinition->addArgument($config['rollbarnotifier']);
$rollbarServiceDefinition->setLazy(true);
$container->setDefinition('foo.service.rollbarnotifier', $rollbarServiceDefinition);
... later on when I do a $container->get('foo.service.rollbarnotifier'), I see it invoking my __construct() function of \RollbarNotifier
@blockjon
blockjon / gist:8830229
Created February 5, 2014 18:36
Apparent evidence PHP json_encode not returning FALSE on error
/**
* Evidence that PHP json_encode is not returning FALSE on error.
* (Reference: http://us1.php.net/json_encode)
*
* Env:
*
* PHP 5.3.10-1ubuntu3.9 with Suhosin-Patch (cli) (built: Dec 12 2013 04:27:25)
* Copyright (c) 1997-2012 The PHP Group
* Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
* with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
@blockjon
blockjon / gist:6430064
Last active June 11, 2017 21:19
The results set for problem #2 in our SQL coding challenge.
+----------------+-------+---------------------+---------------------+
| sender_user_id | name | num_users_contacted | num_users_responded |
+----------------+-------+---------------------+---------------------+
| 3 | Greg | 1 | 1 |
| 1 | John | 4 | 0 |
| 7 | Linda | 1 | 1 |
| 6 | Sue | 2 | 2 |
+----------------+-------+---------------------+---------------------+
@blockjon
blockjon / gist:6430052
Last active December 22, 2015 06:19
The correct results set for problem #1 in our SQL challenge.
+----+-------+-------------------------------+
| id | name | total_cold_inquiries_received |
+----+-------+-------------------------------+
| 2 | Mike | 1 |
| 4 | Bill | 2 |
| 5 | Kate | 1 |
| 6 | Sue | 1 |
| 7 | Linda | 2 |
| 8 | Mary | 1 |
+----+-------+-------------------------------+
@blockjon
blockjon / gist:6430015
Last active December 22, 2015 06:19
This script sets up the tables and example rows for our SQL coding challenge at RockThePost.
-- Setup some tables.
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1;
CREATE TABLE `internal_messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_user_id` int(11) DEFAULT NULL,
@blockjon
blockjon / gist:5662740
Last active December 17, 2015 19:49
What sql query will produce the results set below using just a single table scan?
What sql query will produce the results set below using just a single table scan?
animals
-----------------
| size | color |
-----------------
| big | red |
| small | red |
| small | green |
-----------------
@blockjon
blockjon / JonsMergeConflict
Created October 17, 2012 21:22
Why am I getting merge conflicts like this?
<<<<<<< HEAD
<?php
namespace Ipf\Orm;
/**
* Basic hydrator.
*/
abstract class Hydrator extends \Doctrine\ORM\Internal\Hydration\AbstractHydrator
{
/**
var express = require('express');
var NotifyClass = require('./NotifyService').NotifyService;
var notifyService = new NotifyClass();
var app = express();
app.use(express.bodyParser());
// all environments
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);