Skip to content

Instantly share code, notes, and snippets.

View kriswallsmith's full-sized avatar

Kris Wallsmith kriswallsmith

  • Portland, Oregon USA
  • 05:29 (UTC -07:00)
View GitHub Profile
@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 / 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 / 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;
<?php
class BaseDoctrineForm extends sfFormDoctrine
{
// ...
protected function getRequiredFields(sfValidatorSchema $validatorSchema = null,
$format = null)
{
if (is_null($validatorSchema))
<?php
class RequiredLabelsFormatterTable extends sfWidgetFormSchemaFormatterTable
{
protected
$requiredLabelClass = 'required';
public function generateLabel($name, $attributes = array())
{
// loop up to find the "required_fields" option
<?php
class BaseDoctrineForm extends sfFormDoctrine
{
public function __construct($object = null, $options = array(), $CSRFSecret = null)
{
// ...
$this->widgetSchema->addFormFormatter('table',
new RequiredLabelsFormatterTable($this->widgetSchema)
<?php
class BaseDoctrineForm extends sfFormDoctrine
{
public function __construct($object = null, $options = array(), $CSRFSecret = null)
{
parent::__construct($object, $options, $CSRFSecret);
// tell the widget schema which fields are required
$this->widgetSchema->addOption('required_fields', $this->getRequiredFields());
<?php
class BaseDoctrineForm extends sfFormDoctrine
{
public function __construct($object = null, $options = array(), $CSRFSecret = null)
{
parent::__construct($object, $options, $CSRFSecret);
// tell the widget schema which fields are required
$this->widgetSchema->addOption(
#!/usr/bin/env php
<?php
$username = $argv[1];
$password = $argv[2];
// copied from http://fabien.potencier.org/article/20/tweeting-from-php
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
<?php
// Doctrine/DataDict/Mysql.php
if ($length <= 1) {
return 'TINYINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3) {
return 'MEDIUMINT';
} elseif ($length == 4) {