Skip to content

Instantly share code, notes, and snippets.

View kriswallsmith's full-sized avatar

Kris Wallsmith kriswallsmith

  • Portland, Oregon USA
  • 12:24 (UTC -07:00)
View GitHub Profile
@kriswallsmith
kriswallsmith / Chain.php
Last active February 13, 2024 15:07
Symfony Messenger message chaining
<?php
declare(strict_types=1);
namespace App\Messenger\Chain;
use App\Messenger\Chain\Stamp\ChainStamp;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Stamp\StampInterface;
<?php
class WidgetManager
{
private $em;
private $factory;
private $manipulator;
private $dispatcher;
public function __construct(ObjectManager $em, SnapshotFactory $factory, WidgetManipulator $manipulator, EventDispatcherInterface $dispatcher)
@kriswallsmith
kriswallsmith / 01_mixins_Secure.js
Last active August 29, 2015 14:16
My first bit of React code worth sharing.
var React = require('react');
var Router = require('react-router');
var SessionStore = require('../stores/SessionStore');
var Stash = require('../utils/Stash');
function authentication(transition) {
if (!SessionStore.isLoggedIn()) {
Stash.set('onLogin', transition.retry);
transition.redirect('login');
return false;
@kriswallsmith
kriswallsmith / gist:4e7ea1cb1ec83f5203e1
Last active August 29, 2015 14:02
These are the Neo4j Cypher queries Assetic would run
// what to recompile when as asset changes
MATCH (changed)<-[:INCLUDES*]-(recompile)
WHERE changed.source = "..." AND recompile.target <> NULL
RETURN recompile
// determine an asset's aggregate mtime
MATCH (root)-[:INCLUDES*]->(include)
WHERE root.source = "..."
RETURN max(collect(include.mtime) + root.mtime)
@kriswallsmith
kriswallsmith / default.vcl.erb
Created February 27, 2014 21:42
Here's a decent Chef workaround for Varnish's lack of support for ACL behind a proxy.
sub vcl_recv {
if (req.url ~ "(?i)^/admin" && req.http.x-forwarded-for !~ "\b(<%= @ips.map{ |ip| Regexp.escape(ip) }.join('|') %>)$") {
error 750 "Moved Temporarily";
}
}
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = "/";
set obj.status = 302;
@kriswallsmith
kriswallsmith / 01_before.php
Created September 10, 2013 19:54
I could really go for an array_index() function right now.
<?php
$widgets = array_combine(
array_map(
function($widget) {
return $widget->getId();
},
$widgets
),
$widgets
@kriswallsmith
kriswallsmith / test.php
Last active December 20, 2015 00:29
A test harness for your Symfony2 project. Runs functional tests in chunks.
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput as Input;
use Symfony\Component\Console\Input\InputOption as Option;
require_once __DIR__.'/../vendor/autoload.php';
/** Outputs and runs a command. */
@kriswallsmith
kriswallsmith / gist:5819198
Last active December 18, 2015 17:29
How do you walk a paginated API?
<?php
function walk($callback)
{
$page = 1;
do {
$results = fetch($page++, 100);
foreach ($results as $result) {
call_user_func($callback, $result);
@kriswallsmith
kriswallsmith / QSAListener.php
Created August 8, 2012 18:23
implements QSA on Symfony2 redirects
<?php
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
/** @DI\Service */
class QSAListener
{
private $blacklist;
<?php
namespace OpenSky\Bundle\MainBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* Listens to kernel.request after the router and checks required role.