Skip to content

Instantly share code, notes, and snippets.

@codenamegary
codenamegary / random.php
Last active April 19, 2017 15:39
Random PHP code
<?php
public function pdf_creation($content)
{
if (false !== file_put_contents($this->full_file_name, $content)) {
return true;
}
while (substr($this->filename, 0, 1) === '.') {
$this->filename .= substr($this->filename, 1, (strlen($this->filename) - 1));
@codenamegary
codenamegary / php-scalars.php
Last active January 4, 2016 09:48
Scalar Type Hinting in PHP
<?php
// See: http://nikic.github.io/2012/03/06/Scalar-type-hinting-is-harder-than-you-think.html
// And RFC: https://wiki.php.net/rfc/scalar_type_hinting_with_cast
//
// Basically the same implementation as outlined in the RFC but with a concept for scalar
// magic to be added to objects at some point in the future.
class MyObjectWithScalarMagic {
<?php
use Validator;
use RuleSet;
use Filters;
use Rule;
use Constraints;
class ValidationBuilder {
@codenamegary
codenamegary / gist:7495415
Created November 16, 2013 03:04
#laravel IRC pong
$players = array();
@codenamegary
codenamegary / gist:7015030
Last active December 25, 2015 17:39 — forked from s3gfau1t/gist:7014684
ERMAHGERD IF/ELSE! $raceWriter('Message to console or file.');
<?php
$velocities = array("turtle", "donkey", "rabbit");
$mode = isset($argv[1]) ? $argv[1] : 'console';
$file = isset($argv[2]) ? $argv[2] : '';
$fp = null;
$raceWriters = array(
'file' => function($output)use($file, $fp){
if(!$fp) $fp = fopen($file, 'a+');
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)],
'actions' => array(),
),
'2' => array(
@codenamegary
codenamegary / gist:7013392
Last active December 25, 2015 17:29 — forked from s3gfau1t/gist:7013352
Added actions and actionsFunc
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)]),
'actions' => array(),
'2' => array(
'name' => 'Bar',
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)],
'actions' => array(),
),
'2' => array(
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)]),
'2' => array(
'name' => 'Bar',
'velocity' => $velocities[rand(0,2)]),
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)]),
'2' => array(
'name' => 'Bar',
'velocity' => $velocities[rand(0,2)]),