Skip to content

Instantly share code, notes, and snippets.

@mbrowne
mbrowne / simpleoo.js
Created October 26, 2013 13:18
simpleoo.js new version preview
(function(define) {
/*
Example usage:
function Animal() {}
Animal.prototype.eat = function() { console.log('yum'); }
function Cat() {}
simpleoo(Cat).extend(Animal, {
meow: function() { console.log('meow'); }
@mbrowne
mbrowne / unserialize.php
Created August 31, 2013 00:49
PHP serialization format for protected properties
class Test
{
protected $foo;
function __construct($foo) {
$this->foo = $foo;
}
}
$str = 'O:4:"Test":1:{s:6:"'."\0".'*'."\0".'foo";s:3:"bar";}';
$obj = unserialize($str);
var_dump($obj);
@mbrowne
mbrowne / grids.css
Last active December 21, 2015 23:59
Standalone implementation of Cascade Framework presentational grids
.grid-row, .col {width:100%;}
/* clearfix (http://nicolasgallagher.com/micro-clearfix-hack) */
.grid-row:before, .grid-row:after {
content:" "; display:table;
}
.grid-row:after {clear:both;}
/* for IE<=7 */
.grid-row {*zoom: 1;}
@mbrowne
mbrowne / students.php
Last active December 20, 2015 22:09
PHP Simple OOP Example - Graduate and Undergraduate Students
<?php
class Student
{
protected $name;
/**
* social security number
* @var string **/
protected $ssn;
protected $major;
@mbrowne
mbrowne / standard-gutter.css
Created May 30, 2013 13:24
Standard gutter
/* Put a standard gutter on these common elements, as well as any element with the std-gutter class.
This makes it possible to have a standard gutter compatible with IE<=7 without needing to wrap every
grid cell with <div class="cell"> (as is done in the Cascade Framework examples)
*/
.std-gutter, .panel, .media, h1, h2, h3, h4, h5, h6, dl, p, blockquote, table, address, pre, figure {margin:15px;}
/* since we're applying a standard margin, list-style-position:inside is needed to keep lists
in alignment with everything else */
ul, ol {list-style-position:inside;}
ul {margin:0 0 9px 2.4em}
ol {margin:0 0 9px 2em}
@mbrowne
mbrowne / Account.php
Last active February 8, 2019 14:39
Wrapper-based DCI in PHP accounting for the object identity problem
<?php
namespace DomainObjects;
class Account
{
protected $balance = 0;
function __construct($initialBalance) {
$this->balance = $initialBalance;
}
@mbrowne
mbrowne / stack.css
Last active December 16, 2015 03:59
CSS stack class (for stacking items vertically, optionally specifying percentage-based heights)
.box {padding:10px;}
.box, .stack-item:first-child .box {border:1px solid #ccc;}
.stack-item .box {border-top:none}
.stack {margin:0;padding:0;}
ul.stack {list-style:none;}
/*Note: if setting a min-height for items, set it on .stack-item .box, not on .stack-item,
otherwise .box won't expand to the full height*/
.stack-item .box {height:100%;
-moz-box-sizing: border-box; -ms-box-sizing: border-box;-webkit-box-sizing: border-box;box-sizing: border-box;
@mbrowne
mbrowne / gist:5185113
Created March 18, 2013 04:33
DCI Quiz Example
class FreeResponseQuizContext
{
protected IEnumerable<Question> questions;
FreeResponseQuizContext(Student student, QuizTemplate quizTemplate) {
IEnumerable<QuestionTemplate> questionTemplates = quizTemplate.getQuestionTemplates();
QuestionGenerator = questionTemplates;
AnswerCalculator = questionTemplates;
Student = student;
}
@mbrowne
mbrowne / Test.php
Created March 6, 2013 17:08
SSH Connection from CodeIgniter
<?php
class Test extends CI_Controller
{
public function deploy_test() {
$connection = ssh2_connect("123.45.67.890", 23);
if(!$connection) {
echo json_encode('Connection failed');
}
@mbrowne
mbrowne / dci2.php
Last active December 14, 2015 07:08
(Hacky) DCI in PHP 5.4, version 2
<?php
//SEE ALSO: https://gist.github.com/mbrowne/5562643 (works in PHP 5.3 too)
//and related discussion: https://groups.google.com/d/msg/object-composition/g4BMSdluuC8/yPR3-a1b2sMJ
ini_set('display_errors', 1);
trait AssignableToRole
{
protected $roles = array();
protected $methods = array();