Skip to content

Instantly share code, notes, and snippets.

View fzaninotto's full-sized avatar

Francois Zaninotto fzaninotto

View GitHub Profile
@fzaninotto
fzaninotto / gist:1308547
Created October 24, 2011 07:49
Inserting data to a database using Faker and PDO
<?php
$pdo = new PDO('mysql:host=hostname;dbname=defaultDbName', 'username', 'p@55w0rd');
$sql = 'INSERT INTO author (first_name, last_name, date_of_birth, email) VALUES (?, ?, ?, ?)';
$stmt = $pdo->prepare($sql);
$faker = \Faker\Factory::create();
$insertedPKs = array();
for ($i=0; $i < 100; $i++) {
$stmt->bindValue(1, $faker->firstName, PDO::PARAM_STR);
$stmt->bindValue(2, $faker->lastName, PDO::PARAM_STR);
$stmt->bindValue(1, $faker->date, PDO::PARAM_STR);
@fzaninotto
fzaninotto / gist:1308553
Created October 24, 2011 07:55
Inserting data to a database using Faker and Propel
<?php
$faker = \Faker\Factory::create();
$insertedPKs = array();
for ($i=0; $i < 100; $i++) {
$author = new Author();
$author->setFirstName($faker->firstName);
$author->setLastName($faker->lastName);
$author->setDateOfBirth($faker->date);
$author->setEmail($faker->email);
$author->save();
@fzaninotto
fzaninotto / gist:1308655
Created October 24, 2011 09:25
Inserting data to a database using Faker Populator and Propel
<?php
$faker = \Faker\Factory::create();
$populator = new \Faker\ORM\Propel\Populator($faker);
$populator->addEntity('Author', 100);
$insertedPKs = $populator->execute();
@fzaninotto
fzaninotto / gist:1308697
Created October 24, 2011 09:58
Inserting data to several tables using Faker Populator and Propel
<?php
$faker = \Faker\Factory::create();
$populator = new \Faker\ORM\Propel\Populator($faker);
$populator->addEntity('Author', 10000);
$populator->addEntity('Book', 100000);
$populator->addEntity('Review', 1000000);
$insertedPKs = $populator->execute();
@fzaninotto
fzaninotto / gist:1308714
Created October 24, 2011 10:11
Inserting data to several tables using Faker Populator, a custom formatter, and Propel
<?php
$faker = \Faker\Factory::create();
$populator = new \Faker\ORM\Propel\Populator($faker);
$populator->addEntity('Author', 10000);
$populator->addEntity('Book', 100000, $customColumnFormatters = array(
'ISBN' => function () use ($generator) { return $generator->randomNumber(13); },
));
$populator->addEntity('Review', 1000000);
$insertedPKs = $populator->execute();
@fzaninotto
fzaninotto / ExceptionInterface.php
Created December 20, 2011 19:31
Catch Interface
<?php
interface Bar {}
class Foo extends Exception implements Bar {}
try
{
throw new Foo();
} catch (Bar $e) {
var fs = require('fs');
var request = require('request');
var async = require('async');
var apiUrl = 'http://api.flickr.com/services/upload/';
var filenames = fs.readdirSync(path);
async.forEach(filenames, function(filename, callback) {
// open a file stream on the local image
var fileStream = fs.createReadStream(path + filename);
// read from the file and write to the HTTP request
<?php
sleep(10);
header('Content-Type: text/css');
echo 'h1 { color: red; }';
# Ruby / Bundler / Diaspora
# Fork https://github.com/diaspora/diaspora
# Repeat 5 times
time sh -c 'git clone https://github.com/fzaninotto/diaspora.git;cd sandbox;bundle install --deployment'
rm -Rf diaspora
# commit dependencies
git clone https://github.com/fzaninotto/diaspora.git