Skip to content

Instantly share code, notes, and snippets.

View metasansana's full-sized avatar
🕺
Wine on a buffer.

Lasana Murray metasansana

🕺
Wine on a buffer.
View GitHub Profile
/*The Great Dependency Injection.*/
//This is psuedo code. Screw the syntax rules!
//No dependency injection.
class User {
private Database db;
private String email;
@metasansana
metasansana / gist:5912763
Created July 2, 2013 20:21
Parasitic inheritance and constructors without the new keyword in JavaScript.
var ns= {};
ns.Object = function () {
var that = {};
that.toString = function () {
return 'I am an Object!!';
}
@metasansana
metasansana / no-setters
Created July 2, 2013 22:00
No setters please (unless necessary).
//One of the popular concepts in OOP style programming is the concept of loose coupling.
//Your objects should have everything they need to carry out their duties from the time you instansiate them (new Object).
//Failing that, you should be able to inject any missing dependecies into your classes whenever necessary.
//This does not mean you go and create a whole bunch of setters.
//Wrong!
dog = new Animal();
dog.setColor('blue');
@metasansana
metasansana / jsclosure
Created September 1, 2013 14:54
Javascript closure
function outer (outerArg) {
return function (innerArg) { // closure function
return outerArg+innerArg;
};
@metasansana
metasansana / golangclosure
Created September 1, 2013 14:58
Go language closure.
func outer (outerArg int) func(int) { //this could also be a custom type
return func (innerArg int) int { // closure func
return outerArg+innerArg;
@metasansana
metasansana / phpclosure
Created September 1, 2013 15:01
PHP closure.
function outer (int $outerArg) { //this could also be a custom type
return function (int $innerArg) { // closure function
return $outerArg+$innerArg;
}
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@metasansana
metasansana / gist:d043fbeb3338c5ab1622
Created June 26, 2014 23:47
Render email templates with nunjucks in KeystoneJS.
/**
* Email is a wrapper around the keystone Email object.
* @class Email
*
* @constructor
*
*/
module.exports = function Email(name, keystone, nunjucks) {
return new keystone.Email({