Skip to content

Instantly share code, notes, and snippets.

@mbrowne
mbrowne / db-sync.sh
Created March 24, 2014 21:49
Shell script to copy remote MongoDB database (and overwrite local copy)
#!/bin/bash
#SYNC MONGODB DATABASE FROM REMOTE SERVER
#NOTE: This overwrites the local copy of the database
remoteHost='yourhost.com'
remoteDbUser='root'
remoteDbPasswd='password123'
remoteDb='test'
localDb='test'
@mbrowne
mbrowne / prototypal.js
Last active August 29, 2015 14:06
Pure prototypal inheritance in Javascript
var Animal = {
init: function(name) {
this.name = name || null;
}
}
var Cat = Object.create(Animal);
Cat.meow = function() {
console.log('meow');
}
@mbrowne
mbrowne / dci.php
Last active December 14, 2015 06:49
(Hacky) DCI in PHP 5.4
<?php
/***********************************************************************
UPDATE: See my improved example: https://gist.github.com/mbrowne/5047982
************************************************************************/
ini_set('display_errors', 1);
trait AssignableToRole
{
@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();
@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 / 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 / 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 / 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 / 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 / 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'); }