Skip to content

Instantly share code, notes, and snippets.

[alias]
st = status
br = branch
co = checkout
unstage = reset HEAD
[color]
ui = auto
@flevour
flevour / Person.php
Created May 4, 2011 18:50
__toString example implementation
<?php
class Person
{
protected $name = NULL, $surname = NULL;
public function __construct($name, $surname)
{
$this->name = $name;
$this->surname = $surname;
}
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
class UserController extends Controller
{
/**
* @extra:Template()
*/
public function indexAction()
{
#!/bin/bash
# This script copies your publick key to server passed as first argument and makes your life happier. Send me a nice thought. Francesco Levorato
if [ $# -ne 1 ]; then
echo Usage: $0 username@server
exit
fi
cat ~/.ssh/id_dsa.pub | ssh $@ 'mkdir -p .ssh; cat >> .ssh/authorized_keys; chmod 700 .ssh; chmod 600 .ssh/authorized_keys'
@flevour
flevour / GOOD-2_tests_2_methods.php
Created February 28, 2011 14:56
Testing 2 things with 2 test methods.
<?php
public function testIteratesOverOneElementArraysUsingValues()
{
$iterator = new ArrayIterator(array('foo'));
foreach ($iterator as $element) {
$this->assertEquals('foo', $element);
}
}
public function testIteratesOneTimeOverOneElementArrays()
{
@flevour
flevour / BAD-2_tests_in_1.php
Created February 28, 2011 14:55
Testing 2 things in the same test method.
<?php
public function testIteratesOverOneElementArrays()
{
$iterator = new ArrayIterator(array('foo'));
$i = 0;
foreach ($iterator as $element) {
$this->assertEquals('foo', $element);
$i++;
}
$this->assertEquals(1, $i);
<?php
class Doctrine_Ticket_DC329_TestCase extends Doctrine_UnitTestCase
{
public function prepareTables()
{
$this->tables[] = "Ticket_DC329_Document";
$this->tables[] = "Ticket_DC329_DocumentRelation";
parent::prepareTables();
}
@flevour
flevour / worseRecursiveOrdering.php
Created February 11, 2011 20:56
Making a worse ordering algo
<?php
$array = array(5, 3, 2, 1, 7);
function worse_recursive_ordering($array) {
if (count($array) <= 1) {
return $array;
}
// Find minimum
$minimum = $array[0];
@flevour
flevour / ArrayRecursiveOrdering.php
Created February 11, 2011 16:36
A self-created exercise on bad algo for array ordering.
<?php
$array = array(5, 3, 2, 1, 7);
function recursive_ordering($array) {
if (count($array) <= 1) {
return $array;
}
// Find minimum
$minumum_id = 0;
<?php
/**
* Carica un prodotto in base al modello. Ispirato da uc_ajax_cart_add_item()
* @param unknown_type $model
* @return unknown_type
*/
function uc_product_load_by_model($model) {
$product = db_fetch_object(db_query('SELECT vid, model, list_price, cost, sell_price, weight, weight_units, length, width, height, length_units, pkg_qty, default_qty, unique_hash, ordering, shippable FROM {uc_products} WHERE model = "%s"', $model));
$node = node_load(array('vid' => $product->vid));
uc_product_load($node);