Skip to content

Instantly share code, notes, and snippets.

@tystr
tystr / phpunit_bootstrap.php
Created August 8, 2011 23:56
Symfony2 PHPUnit Bootstrap
<?php
// include symfony2 bootstrap
include 'bootstrap.php.cache';
abstract class BaseTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
{
protected $client;
public function setUp()
@tystr
tystr / deploy.sh
Created March 3, 2012 00:53
Symfony2 deploy script
#!/bin/bash
# Script variables
SF2_ENVIRONMENT=prod
REPOSITORY=
DEPLOY_BASE_DIR=/var/www
DEPLOY_DIR=$DEPLOY_BASE_DIR/`date +%s`
USAGE="Usage: $0 install|update [git_repository_url]"
# Commands
@tystr
tystr / deps
Created March 13, 2012 00:11
Pagerfanta entries for Symfony 2.0.x deps file
[pagerfanta]
git=http://github.com/whiteoctober/Pagerfanta.git
[WhiteOctoberPagerfantaBundle]
git=http://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.git
target=/bundles/WhiteOctober/PagerfantaBundle
version=origin/symfony2.0
@tystr
tystr / gist:2154747
Created March 22, 2012 00:44
response listener
/**
* @param FilterResponseEvent $event
*/
public function onResponse(FilterResponseEvent $event)
{
$cookie = new Cookie('my_id', 1);
$response = $event->getResponse();
$response->headers->setCookie($cookie);
}
@tystr
tystr / autoload.php
Created March 30, 2012 22:09
phpunit autoload
<?php
// autloload.php.dist
$vendorDir = __DIR__.'/../../../../../vendor';
echo realpath($vendorDir);
require_once $vendorDir.'/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
{
"name": "my/custom-name",
"autoload": {
"psr-0": { "": "src/" }
},
"repositories": [
{"type": "composer", "url": "http://192.168.11.5/satis/web" },
{"type" : "pear", "url": "pear.amazonwebservices.com"}
],
"require": {
@tystr
tystr / DoctrineFormHandler.php
Last active March 27, 2016 22:26
Doctrine Symfony2 Form Handler
<?php
namespace Form\Handler;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use Form\Handler\FormHandlerInterface;
/**
@tystr
tystr / gist:3171977
Created July 24, 2012 19:12
Implementation of Vose's Alias Method
<?php
/**
* Implementation of Vose's Alias Method
*
* @param array $probabilities An array of probabilities
*
* @return int
*/
public function aliasMethod(array $probabilities)
@tystr
tystr / alias.php
Last active December 22, 2015 02:34
PHP Implementation of Vose's Alias Method
<?php
/**
* Implementation of Vose's Alias Method
*
* @param array $probabilities An array of probabilities
*
* @return int
*/
public function aliasMethod(array $probabilities)
{
@tystr
tystr / deploy.rb
Created October 8, 2012 22:41
Use puppet facts to retrieve a list of servers that should be deployed to via capifony
# ...
# This method fetches a list of servers to deploy to from the puppetmaster
def get_servers(system_role)
require 'net/https'
http = Net::HTTP.new("puppetmaster.hostname", 8140)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.get2("/production/facts_search/search?facts.system_role=#{system_role}", "Accept" => "yaml")
require 'yaml'