Skip to content

Instantly share code, notes, and snippets.

View AutoSponge's full-sized avatar

Paul Grenier AutoSponge

View GitHub Profile
@adrianseeley
adrianseeley / pso.js
Last active June 5, 2021 12:03
JavaScript Normalized Particle Swarm Optimization Implementation - Search for an N-dimensional vector of components between -1 and +1 that optimizes a given function to a fitness of 0.
// based on http://msdn.microsoft.com/en-us/magazine/hh335067.aspx
// usage example at bottom
function pso (number_of_dimensions, function_to_optimize, number_of_particles, number_of_iterations, fitness_threshold, inertia_weight, cognitive_weight, social_weight) {
var particles = [];
var swarm_best_position = [];
var swarm_best_fitness = null;
for (var p = 0; p < number_of_particles; p++) {
particles.push({
particle_position: [],
@CrossEye
CrossEye / lens.js
Created June 5, 2014 15:36 — forked from andyhd/lens.js
function lens(get, set) {
var f = function (a) { return get(a); };
f.set = set;
f.mod = function (f, a) { return set(a, f(get(a))); };
return f;
}
var first = lens(
function (a) { return a[0]; },
function (a, b) { return [b].concat(a.slice(1)); }
@staltz
staltz / introrx.md
Last active May 15, 2025 10:37
The introduction to Reactive Programming you've been missing
/**
* Variant of Avraham Plotnitzky's String.prototype method mixed with the "fast" version
* see: https://sites.google.com/site/abapexamples/javascript/luhn-validation
* @author ShirtlessKirk. Copyright (c) 2012.
* Licensed under WTFPL (http://www.wtfpl.net/txt/copying)
*/
function luhnChk(luhn) {
var len = luhn.length,
mul = 0,