Skip to content

Instantly share code, notes, and snippets.

View rafi's full-sized avatar

Rafael Bodill rafi

View GitHub Profile
<?php
Trait MethodDelegator
{
private $roles = array();
private $method_map = array();
public function delegate($class)
{
@rafi
rafi / gist:5706033
Created June 4, 2013 13:45
Goofing around with DCI, inspired by https://gist.github.com/Ikke/4075281
<?php
Trait MethodDelegator
{
private $roles = array();
private $method_map = array();
public function delegate($class)
{
<?php
class Model_User extends Model {
public function initialize()
{
$this->pk_fields = [ 'id' ];
$this->add_fields([
'id' => 'int4',
'account_id' => 'int4',
@rafi
rafi / collection_basics.js
Last active December 19, 2015 03:39
Backbone Basics
var Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
}
});
var TodosCollection = Backbone.Collection.extend({
model: Todo
});
@rafi
rafi / pimple_test.php
Created July 4, 2013 12:48
Pimple DI
<?php
class Test {
public $init = FALSE;
public function __construct() {
echo "Initialized Test";
$this->init = TRUE;
}
}
<?php
usort($products['mp'], function ($a, $b) {
return $a['priority'] - $b['priority'];
});
// VS
usort($products['mp'], function ($a, $b)
@rafi
rafi / Auth.php
Created July 22, 2013 11:05
Simplified Kohana Auth version with NO password hashing
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Simplified Kohana Auth version with NO password hashing
*/
class Auth {
/**
* @var Auth Static instance
*/
protected static $_instance;
@rafi
rafi / i3status.conf
Last active February 1, 2023 12:33
Rafi's i3status configuration file
# github.com/rafi i3status config
# i3status configuration file
# see "man i3status" for documentation.
# It is important that this file is edited as UTF-8.
# The following line should contain a sharp s:
# ß
# If the above line is not correctly displayed, fix your editor first!
@rafi
rafi / BAD.php
Created July 24, 2013 09:32
99% of times a `switch` statement is a BAD idea
<?php
$preferences = [ 'c', 'e' ];
$params = [];
foreach ($preferences as $setting)
{
switch($setting)
{
case 'a':
@rafi
rafi / valid_conditions.php
Last active December 20, 2015 09:49
⊕ Recursively compute conditions, supports $or (like Mongo) ⊕
<?php
/**
* Recursively compute conditions against existing data, supports $or (like Mongo)
* For example:
* {
* "$or": [
* { "foo": true },
* { "bar": true, "baz": true }
* ],