Skip to content

Instantly share code, notes, and snippets.

View chanmix51's full-sized avatar

Grégoire HUBERT chanmix51

View GitHub Profile
@chanmix51
chanmix51 / generate_model.php
Last active September 28, 2015 23:08
generate model files in Silex
<?php
function help()
{
printf("Usage:\n");
printf("generate_model schema environment\n");
printf("\nschema is the database schema you want to scan.\n");
printf("environment set the database connection that will be used (default: dev).\n");
exit(1);
}
@chanmix51
chanmix51 / gobai.sql
Created December 21, 2011 15:30
product reference generator in pl/pgsql
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
@chanmix51
chanmix51 / gist:1501377
Created December 20, 2011 12:14
tmux.conf
# Make it use C-a, similar to screen..
unbind C-b
unbind l
set -g prefix C-a
bind-key a send-prefix
bind-key C-a last-window
# Remove default binding for split
unbind %
@chanmix51
chanmix51 / 1_create_schema.sql
Last active September 28, 2015 03:57
SQL schema
CREATE TYPE transformer_winding AS (voltage NUMERIC(5,1), current NUMERIC(5,3));
CREATE TABLE power_supply_transformer(reference CHAR(6) PRIMARY KEY, pri transformer_winding NOT NULL, secs transformer_winding[] NOT NULL, size_reference VARCHAR(5) NOT NULL);
@chanmix51
chanmix51 / PostMap.php
Last active September 28, 2015 03:48
Overloading the selectFields method in your model
<?php
namespace YourDb\Blog;
use YourDb\Blog\Base\PostMap as BasePostMap;
use Pomm\Exception\Exception;
use Pomm\Query\Where;
class PostMap extends BasePostMap
{
@chanmix51
chanmix51 / controller.php
Last active September 28, 2015 03:48
Using the where class to dynamically build your query
<?php
//...
$cars = $database
->createConnection()
->getMapFor('YourDb\Garage\Car')
->getSportAndColors(array('blue', 'red', 'yellow'))
;
@chanmix51
chanmix51 / get_instances.php
Last active September 28, 2015 03:48
Retrieving model class instances
<?php
//...
$transformers = $database
->getConnection()
->getMapFor('YourDb\Online\PowerSupplyTransformer')
->findWhere('stock > $* and voltage = $*', array(5, 220));
foreach($transformers as $transformer)
@chanmix51
chanmix51 / generate_model.php
Last active September 28, 2015 03:48
Generating model files in /tmp with Pomm
<?php
$loader = require __DIR__."/../vendor/autoload.php";
$database = new Pomm\Connection\Database(array('dsn' => 'pgsql://user:password@host:port/db_name'));
$scan = new Pomm\Tools\ScanSchemaTool(array(
'schema' => 'public',
'database' => $database,
'prefix_dir' => '/tmp'
@chanmix51
chanmix51 / gist:1338974
Created November 4, 2011 09:13
install PHPUnit
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear channel-update pear.symfony-project.com
pear upgrade
pear install pear.phpunit.de/PHPUnit
https://github.com/sebastianbergmann/phpunit
@chanmix51
chanmix51 / services.yml
Created October 20, 2011 16:23
Registering twig sandbox in SF2
parameters:
policy.tags: [if]
policy.filters: [upper]
policy.methods: { Article: [getTitle]}
policy.properties: { Article: [excerpt]}
policy.function: [range]
services:
twig.extension.sandbox.policy:
class: Twig_Sandbox_SecurityPolicy