Skip to content

Instantly share code, notes, and snippets.

View chanmix51's full-sized avatar

Grégoire HUBERT chanmix51

View GitHub Profile
@chanmix51
chanmix51 / search.sql
Created November 6, 2012 10:35
FT search with I18N in Postgresql
-- search
-- Perform a full text search in I18N using HStore
-- @param text $1 the language to search
-- @param text $2 the search string
-- @return int4 id The identifier of the searched table
-- @return float4 rank The ranking function result.
-- @return text excerpt An extract of text containing the searched words surrounded with <strong>.</strong>.
CREATE OR REPLACE FUNCTION test.search(text, text) RETURNS TABLE (id int4, rank float4, excerpt text) LANGUAGE sql AS $_$
SELECT
[alias]
st = status
mylog = "log --graph --pretty=format:'%h %C(bold white)%d%Creset - %C(green)%an%Creset, %C(bold red)%ar%Creset - %C(bold yellow)%s%Creset'"
@chanmix51
chanmix51 / SessionMap.php
Created October 25, 2012 13:17
REST API with Silex and Pomm
<?php
namespace Taf\Member;
use Taf\Member\Base\SessionMap as BaseSessionMap;
use Taf\Member\Session;
use \Pomm\Exception\Exception;
use \Pomm\Query\Where;
use \Pomm\Object\BaseObject;
@chanmix51
chanmix51 / application.php
Created October 25, 2012 13:09
How to validate POST data in Silex with Pomm
<?php application.php
// ...
$app->post('/tasks/new', function() use ($app) {
$task_map = $app['pomm.connection']
->getMapFor('\Taf\Task\Task');
$new_task = new Validation\NewTask($app['request']->request->get('new_task'));
$new_task->worker_id = $app['taf.session']->getWorkerId();
if (count($app['validator']->validate($new_task)) == 0)
During this session we will explore Postgresql's unique features like writeable CTEs, window functions, Json, XML and key-value support and much more. We will see how with Pomm's elastic objects it makes web developers able to have a model layer decoupled from the underlying data structure with a minimal complexity data preparation code.
Postgresql 9.2 is probably the most known version of Postgres since it exists. This can be partly explained by the fuss about web oriented features like Json and HStore data types and javascript v8 support for stored functions. But it is not the only reason. Its rich types sets allow programers to think data as objects in their SQL queries.
Today's ORMs link static classes to tables, preventing the developers from creating their own business oriented data sets. They must then prepare the data to format them the right way in the model layer before applying business rules.
Pomm is a model manager. It maps PHP elastic classes to data sets provided either by tables, views or…
@chanmix51
chanmix51 / create-pomm-silex.sh
Last active February 25, 2018 17:11
Silex project bootstrap with Pomm
#!/bin/bash
mkdir -p bin sources/{config,twig,sql,lib/{Model,Controller}} web/{css,images,js} tests documentation log
chmod 777 log
> web/favicon.ico
cat > bin/generate_model.php <<"EOF"
<?php // bin/generate_model.php
$app = require(__DIR__."/../sources/bootstrap.php");
@chanmix51
chanmix51 / create_table.sql
Created August 1, 2012 09:12
Recursive tree browsing in Postgres SQL
CREATE TABLE node (name varchar PRIMARY KEY, is_child_of varchar REFERENCES node (name), some_int integer NOT NULL);
CREATE INDEX node_is_child_of_idx ON node (is_child_of);
-- Fill the table with nice big random tree
WITH RECURSIVE
path_node AS (
SELECT
md5(chr(CAST(floor(random() * 223) AS integer) + 32) || random()) AS name,
NULL AS is_child_of,
0 AS some_int,
@chanmix51
chanmix51 / sqlpostgres.vim
Created May 21, 2012 15:34
SQL postgres vim syntax file
" Vim syntax file
" Language: SQL, PGSQL (postgres 9.1)
" Last Change: 2012 May 21st
" Maintainer: Grégoire Hubert <greg DOT hubert AT gmail DOT com>
" Based on the work of Paul Moore <pf_moore AT yahoo.co.uk>
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
@chanmix51
chanmix51 / 6Z38P_6S19P_push_pull_amplifier.asc
Created May 11, 2012 19:59
LTSpice schematic for a 6S19P push pull amplifier
Version 4
SHEET 1 1188 920
WIRE -176 -480 -176 -560
WIRE -1136 -432 -1200 -432
WIRE -992 -432 -1056 -432
WIRE 448 -400 320 -400
WIRE -576 -352 -896 -352
WIRE -176 -352 -176 -400
WIRE -176 -352 -512 -352
WIRE 320 -336 320 -400
@chanmix51
chanmix51 / tmux.sh
Created March 28, 2012 08:54
Tmux bash functions
function splitw() {
tmux split-window "$*";
}
function neww() {
tmux new-window "$*";
}