Skip to content

Instantly share code, notes, and snippets.

View marlun78's full-sized avatar

Martin Eneqvist marlun78

View GitHub Profile
@marlun78
marlun78 / di.js
Last active August 29, 2015 13:57
JavaScript dependency injection - sort of...
/**
* Dependency Injection
* Copyright (c) 2014, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* === EXAMPLE ===
* //Some module...
* (function () {
* var di = window.di;
*
@marlun78
marlun78 / SOFS.js
Last active August 29, 2015 13:57
Self-overwriting function statement - an alternative to IIFE?
/**
* Self-overwriting Function Statement (SOFS)
* Copyright (c) 2013, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* === EXAMPLE ===
* console.log('---');
* console.log('SOFS return:', sofs());
* console.log('SOFS return:', sofs());
* console.log('---');
@marlun78
marlun78 / evts.js
Last active August 29, 2015 14:00
Minimal Events
/**
* Minimal Events
* Copyright (c) 2013 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
// TODO: Rework “once”
window.evts = (function () {
'use strict';
@marlun78
marlun78 / Class.js
Last active August 29, 2015 14:06
JavaScript prototypal inheritance
/**
* Class.js
* JavaScript prototypal inheritance
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* @example:
* function Person(name) {
* this.name = name;
* }
@marlun78
marlun78 / UniqueMap.js
Last active August 29, 2015 14:06
Provides an immutable enum-like type where both keys and values must be unique.
/**
* UniqueMap.js
* Provides an immutable enum-like type where both keys and values must be unique.
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
(function (undefined) {
'use strict';
@marlun78
marlun78 / Enum.js
Last active August 29, 2015 14:06
Provides an immutable enum type
/**
* Enum.js
* Provides an immutable Enum type
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* @example:
* var colors = new Enum({
* RED: '#f00',
* GREEN: '#0f0',
@marlun78
marlun78 / Intercept.js
Last active August 29, 2015 14:08
Simple meta-programming for methods
/**
* Intercept.js
* Simple meta-programming for methods
* Copyright (c) 2014 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* The intercept-function provides a pre and a post hook that
* will run before and after the original implementation
* respectively. In the pre-hook you have access to the
* arguments passed, and in the post-hook you have access to
@marlun78
marlun78 / toRatio.js
Created May 18, 2015 08:00
Takes a screen dimension and return its ratio as width:height
/**
* toRatio.js
* Copyright (c) 2015 marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* Takes a screen dimension and return its ratio as width:height.
*
* @example
* toRatio(1280, 720); //=> 16:9
* toRatio(800, 600); //=> 4:3
/**
* Mootools Date.Swedish.js
* Copyright (c) 2009, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
MooTools.lang.set('sv-SE', 'Date', {
months: function (i) {
return ['januari', 'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti', 'september', 'oktober', 'november', 'december'][i]
},
days: function (i) {
@marlun78
marlun78 / unsorted.js
Last active September 27, 2015 20:58
Unsorted JavaScript stuff
/**
* Unsorted stuff
* Copyright (c) 2011, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*/
(function (NS) {
if (!NS) { NS = window; }
// isNumber