Skip to content

Instantly share code, notes, and snippets.

@snichme
snichme / di.js
Created October 14, 2015 18:48
Dependency Injection in JavaScript
var di = (function Dein() {
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var _register = {};
function anno(fn, strictDi, name) {
var fnText, argDecl, args;
@snichme
snichme / models.js
Created November 5, 2014 21:04
JS model with mixins
(function() {
'use strict';
/** Helper methods */
function merge(obj1, obj2) {
Object.keys(obj2).forEach(function(key) {
obj1[key] = obj2[key];
});
return obj1;
}

Keybase proof

I hereby claim:

  • I am snichme on github.
  • I am mange (https://keybase.io/mange) on keybase.
  • I have a public key whose fingerprint is 1932 4B35 EC8A 5A99 421F 5384 B6D3 5474 91A5 1E7D

To claim this, I am signing this object:

@snichme
snichme / impossible.js
Created September 18, 2014 18:28
Impossible js
var a = {
v: false,
valueOf: function() {
return this.v = !this.v;
}
};
@snichme
snichme / g
Created June 18, 2014 12:33
Grunt or Gulp or Broccoli
#!/bin/zsh
if [ -s gruntfile.js ]; then
grunt $@
elif [ -s gulpfile.js ]; then
gulp $@
elif [ -s brocfile.js ]; then
broccoli $@
else
echo "No build file found, checked for gruntfile.js, gulpfile.js and brocfile.js"
exit -1
@snichme
snichme / Maybe.js
Last active August 29, 2015 13:57
Maybe.js
class Maybe {
constructor(val) {
this.val = val;
}
map(f) {
return this.val ? new Maybe(f(this.val)) : new Maybe();
}
toString() {
@snichme
snichme / foo.js
Created December 5, 2013 20:35
Requirejs + Angular Injectable modules
// Blank file, will be removed during build
@snichme
snichme / Scroller.js
Created October 25, 2013 01:22
Scroller service for Angular
(function() {
'use strict';
angular.module('ngExtensionsApp')
.factory('Scroll', function($window, $timeout) {
var wait = 100,
callbacks = [],
timeout_identifier = null;
function onScroll(event) {
$timeout.cancel(timeout_identifier);
@snichme
snichme / grunt-cram.js
Last active December 21, 2015 22:58
Example grunt task for Cram.js
module.exports = function(grunt) {
'use strict';
grunt.registerMultiTask('cram', 'Cram runner for grunt', function() {
// Cram failed, tell grunt
function fail (ex) {
grunt.fail.warn('cram failed: ', ex && ex.message || ex);
if (ex && ex.stack) console.log(ex.stack);
}
@snichme
snichme / pure.zsh
Created July 9, 2013 21:38
My zsh theme
# Pure
# by Sindre Sorhus
# https://github.com/sindresorhus/pure
# MIT License
# Change this to your own username
DEFAULT_USERNAME='mange'
# Threshold (sec) for showing cmd exec time