Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View MiguelCastillo's full-sized avatar

Miguel Castillo MiguelCastillo

View GitHub Profile
/**
* RuleMatcher is a helper class to define groups of rules. It provides methods
* to execute a particular criteria against one rule, a set of rules, or all
* rules.
*
* @class
*/
function RuleMatcher(config) {
if (!(this instanceof RuleMatcher)) {
return new RuleMatcher(config);
@MiguelCastillo
MiguelCastillo / bitloder-logger.js
Last active August 29, 2015 14:21
sample default Logger stream and serializer
Bitloader.Logger.default.enable();
Bitloader.Logger.default.stream = {
write: function(buffer) {
console.log(buffer);
}
};
Bitloader.Logger.default.serialize = function(packet) {
return JSON.stringify({
@MiguelCastillo
MiguelCastillo / imports-plugin-config.js
Last active August 29, 2015 14:20
Sample config for bit-imports
//https://github.com/MiguelCastillo/bit-loader
//https://github.com/MiguelCastillo/bit-imports
/* jshint -W098 */
var require = (function() {
/* jshint +W098 */
var importer = bitimports.config({
"baseUrl": "../",
"paths": {
"chai": "../node_modules/chai/chai",
@MiguelCastillo
MiguelCastillo / bad-context.js
Created April 22, 2015 21:18
incorrect context in method `login`; the context is `window` instead of the instance of `Login`
import React from 'react';
class Login extends React.Component {
render() {
return (
<div className='Login'>
<input type='text' ref='username'></input><input type='password' ref='password'></input>
<button onClick={this.login}>Please Login</button>
</div>
);
{
"insertHintOnTab": true
}
@MiguelCastillo
MiguelCastillo / jquery-bootstrap-browserify.js
Created March 31, 2015 03:44
Adding require jquery to bootstrap via a browserify transform
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var through = require('through');
var libs = ['jquery', 'bootstrap'];
gulp.task('app-bundle', function() {
var appBundler = browserify(['./app.js']);
libs.forEach(function(lib) {
@MiguelCastillo
MiguelCastillo / cancelableSequence.js
Last active August 29, 2015 14:12
Cancelable Promise Sequence
var promises = [promise1, promise2, promise3];
// Now you can actually call a cancel interface without affecting the state of the promises.
var cancelable = cancelableSenquence(promises);
function cancelableSequence(promises) {
var cancelled = false;
var cancelable = promises.reduce(function(prev, curr) {
@MiguelCastillo
MiguelCastillo / samdy.js
Last active August 29, 2015 14:12
Tiny AMD resolution algorithm
/**
* spromise Copyright (c) 2014 Miguel Castillo.
* Licensed under MIT
*/
var define, require;
(function() {
var root = this,
cache = {};
@MiguelCastillo
MiguelCastillo / taskManager.js
Last active August 29, 2015 14:11
Sample task manager to handle recursion with trampoline
/**
* Task manager to handle queuing up async tasks in an optimal manner
*/
var TaskManager = {
_asyncQueue: [],
asyncTask: function(task) {
if (TaskManager._asyncQueue.push(task) === 1) {
async(TaskManager.taskRunner(TaskManager._asyncQueue));
}
},
@MiguelCastillo
MiguelCastillo / printStack.js
Created December 11, 2014 17:31
printStack
function printStack() {
try {
throw new TypeError("");
}
catch(ex) {
console.log(ex.stack);
}
}