Skip to content

Instantly share code, notes, and snippets.

daemon --name=mms-agent --user=mongod --pidfile=/var/run/mongodb/mms-agent.pid "/usr/bin/python /usr/local/lib/mms-agent/agent.py > /var/log/mongo/mms-agent.log 2>&1 &"
<?php
namespace MyNamespace\Controller;
use JMS\DiExtraBundle\Annotation\Inject;
class PostsController
{
/**
* @Inject("my_namespace.post_repository")
@tystr
tystr / services.xml
Created April 11, 2013 17:20
twig string loader
<services>
<service id="my_bundle.twig.string.loader" class="Twig_Loader_String" />
<service id="my_bundle.twig.string" class="Twig_Environment">
<argument type="service" id="my_bundle.twig.string.loader" />
</service>
</services>
@tystr
tystr / WebTestCase.php
Created March 29, 2013 19:34
A simple base WebTestCase class
<?php
namespace ...\Bundle\MyBuyndle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* @author Tyler Stroud <tyler@tylerstroud.com>
*/
@tystr
tystr / deploy.rb
Created February 21, 2013 22:20
Clearing APC cache when deploying a symfony2 application
# Clear APC caches
after "deploy:finalize_update" do
pretty_print "--> Clearing APC caches"
run "cd #{release_path} && php app/console apc:clear --env=prod"
puts_ok
end
@tystr
tystr / DoctrineMongoDBODMTrait.php
Last active December 12, 2015 03:48
Simple trait for bootstrapping the Doctrine ODM in unit tests.
<?php
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\MongoDB\Connection;
/**
@tystr
tystr / forms.xml
Created January 18, 2013 05:47
An example of symfony2 forms as services
<parameters>
<parameter key="my_bundle.my_model.form.type.class">My\Bundle\RestBundle\Form\Type\MyModelFormType</parameter>
<parameter key="my_bundle.my_model.form.handler.class">My\Bundle\RestBundle\Form\Handler\MyModelFormHandler</parameter>
</parameters>
<services>
<service id="my_bundle.my_model.form.type" class="%my_bundle.my_model.form.type.class%"/>
<service id="my_bundle.my_model.form" factory-method="create" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="my_bundle.my_model.form.type"/>
</service>
@tystr
tystr / getErrorsForForm.php
Created January 18, 2013 05:33
Gets symfony2 form errors as an array.
<?php
protected function getErrorsForForm(Form $form)
{
$errors = [];
foreach ($form->all() as $child) {
foreach ($child->getErrors() as $error) {
$errors[$child->getName()][] = $error->getMessage();
}
if ($child->count() > 0) {
$childErrors = $this->getErrorsForForm($child);
@tystr
tystr / build.xml
Created December 18, 2012 23:52
Sample ant build.xml file for a Symfony 2.1.x application
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="build">
<target name="build" depends="prepare,install-dependencies,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpdoc,phpunit,phpcb"/>
<target name="build-parallel" depends="prepare,lint,tools-parallel,phpunit,phpcb"/>
<target name="tools-parallel" description="Run tools in parallel">
<parallel threadCount="2">
<sequential>
from daemon import runner
from time import sleep
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/hello_world_daemon.pid'
self.pidfile_timeout = 5