Skip to content

Instantly share code, notes, and snippets.

@b-ma
b-ma / index.html
Last active December 28, 2015 15:49
Strategy pattern
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Pattern Strategy</title>
</head>
<body>
<script src="./strategy.js"></script>
<script>
@b-ma
b-ma / git-commands
Created November 30, 2013 12:38
common git commands
======================================================
GITHUB
======================================================
recap pour utlisation de git et github :
* * * * * * * *
* CREATION *
@b-ma
b-ma / backbone-multirouter.js
Created March 4, 2014 20:41
allow to trigger multiple callback with 1 route using a route separator
Backbone.History.prototype.multiRouteSeparator = '|';
Backbone.History.prototype.loadUrl = function(fragment) {
fragment = this.fragment = this.getFragment(fragment);
// split the fragment according to the defined separator
var fragments = fragment.split(this.multiRouteSeparator);
// test handlers with each fragments
// the function doesn't return anything like the real one
// but it doesn't seems to create problems
@b-ma
b-ma / pubsub.js
Last active August 29, 2015 13:57
small pubsub - (maybe `call` api would be better finally...)
var cache = {};
var pubsub = {
publish: function(channel, args) {
if (!cache[channel]) {
return;
}
var stack = cache[channel];
@b-ma
b-ma / underscore-mixins.js
Last active August 29, 2015 13:57
underscore mixins
_.mixin({
// from underscore's examples [http://underscorejs.org/#mixin](http://underscorejs.org/#mixin)
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
},
ensureApi: function(obj, api) {},
/**
* add sep betwen 3 numbers:
@b-ma
b-ma / test
Last active August 29, 2015 14:00
the meaning of life
var life = {
start: function() {
delete this.stop;
},
stop: function() {
console.log('arg...');
}
};
// v2
@b-ma
b-ma / jquery-placeholder.js
Created May 7, 2014 09:35
jquery AMD placeholder plugin
define([
'jquery'
], function($) {
'use strict';
// extends $.support
// http://stackoverflow.com/questions/3937818/how-to-test-if-the-browser-supports-the-native-placeholder-attribute
$.support.placeholder = (function() {
var input = document.createElement( 'input' );
@b-ma
b-ma / utils.js
Created June 19, 2014 13:14
filesystem node utilities
/**
* find recursively in a given folder for a given pattern into file names
* returns an array of matching files
*/
var fs = require('fs'),
path = require('path'),
util = require('util');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>css</title>
<style>
a {
display: block;
border :1px solid #787878;
width: 300px;
@b-ma
b-ma / orthogonal-data.js
Last active August 29, 2015 14:23
Simple model to keep orthogonal representation of data in sync
class OrthogonalData {
constructor() {
this._cols = null; // object of arrays
this._rows = null; // array of objects
}
// verify that data are consistents
_checkConsistency() {
let size = null;