Skip to content

Instantly share code, notes, and snippets.

@ken210
ken210 / parallel-middleware.js
Last active November 16, 2017 09:48
Middleware to run multiple middlewares in parallel
/**
* Runs multiple middlewares in parallel
* Usage: parallel(mw1, mw2, mw3);
*/
const { after } = require("lodash");
const parallel = (...fns) => (req, res, next) => {
const finalNext = after(fns.length, next);
fns.forEach(fn => fn(req, res, finalNext));
/*
Using genetic algorithim
Given an array of integers, say [-2, 9, 2, -5, 1, -3, -10, 6]
Find a sum of elements that is closest to 0
This solution finds the best solution on 100 rounds.
The best solution is the Gene with it's defect closest to 0,
with the maximum number of elements included,
found on the earliest round possible
*/
/*
This code does the following:
1 - Start a new population of 50 "numbers" and a GOAL of 9999
2 - Select the two highest multiple of 3 available
3 - Create a new generation of numbers ranging between it's parents values, incresing a little
4 - Do that until reaches the GOAL
*/
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="arrow"
# Example aliases
@ken210
ken210 / config.rb
Created March 26, 2013 19:19
My config.rb file for compass
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "../../"
css_dir = "../"
sass_dir = "."
images_dir = "../../img"
javascripts_dir = "../../js"
fonts_dir = "../../font"
@ken210
ken210 / robot.js
Created December 11, 2012 16:21
zarolo201
//FightCode can only understand your robot
//if its class is called Robot
var myRobot;
var Robot = function(robot) {
robot.ahead(100);
robot.clone();
myRobot = robot.id;
robot.log(myRobot);
@ken210
ken210 / robot.js
Created December 5, 2012 05:08
zarula9
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@ken210
ken210 / iisWatcher.js
Created November 13, 2012 16:57
A NodeJS file-watcher for .NET
var fs = require('fs'),
walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if(err) return done(err);
var pending = list.length;
if(!pending) return done(null, results);
list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
@ken210
ken210 / jQuery.parallax.coffee
Created September 3, 2012 21:30
jQuery.parallax.coffee
###
jQuery.parallax
by ken210.com
Based on homonymous plugin by Ian Lunn
Author URL: http://www.ianlunn.co.uk/
Plugin URL: http://www.ianlunn.co.uk/plugins/jquery-parallax/