Skip to content

Instantly share code, notes, and snippets.

View PhazeonPhoenix's full-sized avatar

Phazeon Phoenix PhazeonPhoenix

View GitHub Profile
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<style>
body {
background: #fff;
margin: 0;
padding: 0;
}
{# Widgets #}
{% block form_widget %}
{% spaceless %}
<!-- form_widget -->
{% if compound %}
{{ block('form_widget_compound') }}
{% else %}
{{ block('form_widget_simple') }}
{% endif %}
@PhazeonPhoenix
PhazeonPhoenix / AppKernel.php
Created November 28, 2012 01:00
Enable MongoDB in symfony2
public function init() {
parent::init();
if ($this->debug) {
// Disable deprecated warnings so Doctrine\MongoDB will work
error_reporting(E_ALL & ~E_DEPRECATED );
}
}
@PhazeonPhoenix
PhazeonPhoenix / myhome.py
Created September 20, 2012 17:06
Get user's home path in *nix and Windows
import os
if "HOME" in os.environ:
myhome = os.environ['HOME']
elif "HOMEPATH" in os.environ:
myhome = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])
print myhome
@PhazeonPhoenix
PhazeonPhoenix / gist:2408452
Created April 17, 2012 19:29
Symfony: Objectless Form
<?php
namespace Acme\DemoBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Validator\Constraints as Assert;
class DemoType extends AbstractType
{
@PhazeonPhoenix
PhazeonPhoenix / gist:2161689
Created March 22, 2012 18:48
PHP: dump HTTP headers
<?php
echo "<ul>\n";
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
echo "<li>" . htmlspecialchars("$h = $v") . " </li>\n";
echo "</ul>\n";
@PhazeonPhoenix
PhazeonPhoenix / gist:2032519
Created March 13, 2012 23:13
Symfony: Normal Controller
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use JMS\SecurityExtraBundle\Annotation\Secure;
use JMS\SecurityExtraBundle\Annotation\SecureParam;
@PhazeonPhoenix
PhazeonPhoenix / gist:2009117
Created March 9, 2012 22:46
Symfony: Doctrine Ordered Fixture
<?php
namespace Acme\DemoBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Acme\DemoBundle\Entity\MyEntity;
class LoadMyEntityData extends AbstractFixture implements OrderedFixtureInterface
{
@PhazeonPhoenix
PhazeonPhoenix / gist:2008475
Created March 9, 2012 20:21
RegEx: US & Canadian Zip Code
# http://regexlib.com/REDetails.aspx?regexp_id=122
# This expression matches three different formats of postal codes: 5 digit US ZIP code, 5 digit US ZIP code + 4, and 6 digit alphanumeric Canadian Postal Code. The first one must be 5 numeric digits. The ZIP+4 must be 5 numeric digits, a hyphen, and then 4 numeric digits. The Canadian postal code must be of the form ANA NAN where A is any uppercase alphabetic character and N is a numeric digit from 0 to 9.
^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$
@PhazeonPhoenix
PhazeonPhoenix / gist:2008449
Created March 9, 2012 20:17
RegEx: State Abbreviations
# http://regexlib.com/REDetails.aspx?regexp_id=471
# Match U.S. state abbreviation used by the U.S. Post Office.
^(?-i:A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$