Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / Version20121011141021.php
Created October 11, 2012 20:53
Doctrine DBAL and Migrations Example
<?php
/*
* /path/to/migrations/directory/Version20121011141021.php
*/
namespace ExampleMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class Version20121011141021 extends AbstractMigration
@ziadoz
ziadoz / app-silex.php
Last active April 26, 2020 12:37
Slim Framework Controller Strategies (Simple/Silex)
<?php
// Silex Style Controllers
class App extends \Slim\Slim
{
public function mount($controller)
{
if (! is_object($controller)) {
throw new \InvalidArgumentException('Controller must be an object.');
}
@ziadoz
ziadoz / fizzbuzz.php
Last active December 10, 2015 05:48
The Fizz Buzz problem solved in PHP.
<?php
// http://content.codersdojo.org/code-kata-catalogue/fizz-buzz/
foreach (range(1, 100) as $i) {
$x = '';
$x .= ($i % 3 === 0 ? 'Fizz' : '');
$x .= ($i % 5 === 0 ? 'Buzz' : '');
echo $i . ' ' . (empty($x) ? $i : $x) . "\n";
}
@ziadoz
ziadoz / index.html
Last active February 14, 2021 09:13
HTML5 Webcam / CSS3 Image Filter Experiment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Image from Webcam</title>
<style type="text/css">
video { display: block; margin: 0 auto; border: 10px solid #ccc; }
.button { margin: 10px auto; padding: 10px; background: #ccc; color: white; text-align: center; width: 200px; cursor: pointer; }
#container,
@ziadoz
ziadoz / OpenStruct.php
Last active August 2, 2019 10:35
OpenStruct and Struct in PHP
<?php
class OpenStruct extends ArrayObject
{
public function __construct($input = array())
{
parent::__construct($input, static::ARRAY_AS_PROPS);
}
public function offsetSet($key, $value)
{
@ziadoz
ziadoz / repl.php
Last active August 16, 2022 15:16
Simple PHP REPL
#!/usr/bin/env php
<?php
if (php_sapi_name() !== 'cli') {
exit(1);
}
function input() {
return fgets(STDIN);
}
@ziadoz
ziadoz / checklist.class.php
Last active December 11, 2015 03:58
Perch Checkbox List Field Type
<?php
/**
* Checklist Field Type.
*
* File: PERCH_PATH/addons/fieldtypes/checklist/checklist.class.php
* Usage: <perch:content id="features" type="checklist" label="Features" options="Feature 1, Feature 2, Feature 3" />
* @author Jamie York
**/
class PerchFieldType_checklist extends PerchAPI_FieldType
{
@ziadoz
ziadoz / hgupdate.sh
Last active October 11, 2018 08:58
Bash Mercurial Update Script
#!/bin/bash
# Usage: ./hgupdate.sh /path/to/repositories
# Trap Ctrl + C command and exit the script.
trap 'exit 1' 2
# Strip trailing slashes from argument and test it's a directory.
TARGET=${1%/}
if [[ ! -d $TARGET ]]; then
echo "Please pass in a directory path."
@ziadoz
ziadoz / ternary.php
Last active December 11, 2015 23:28
PHP Ternary (Left/Right Associative)
#!/usr/bin/env php
<?php
// Left associative ternary.
// Output: T
echo (true ? 'True' : false ? 'T' : 'F') . "\n";
// This is essentially the same as above.
// Output: T
echo ((true ? 'True' : false) ? 'T' : 'F') . "\n";
@ziadoz
ziadoz / screenshot.js
Last active October 20, 2019 22:36
CasperJS Website Screenshots
// Usage: casperjs screenshot.js http://www.bbc.co.uk bbc.png
// https://gist.github.com/2310901
var casper = require('casper').create({
viewportSize: { width: 1024, height: 768 }
});
var utils = require('utils');
if (casper.cli.args.length < 2) {