Skip to content

Instantly share code, notes, and snippets.

View fearofcode's full-sized avatar
🎵
Take that chance / All day long / Fucking up so fucking strong

Warren Henning fearofcode

🎵
Take that chance / All day long / Fucking up so fucking strong
View GitHub Profile
@fearofcode
fearofcode / gist:767365
Created January 6, 2011 01:30
main loop of simple genetic algorithm (real-to-real function optimizer)
public double[] runGenerations(int generations, int tournamentSize) {
int generation = 1;
while(generation <= generations) {
computeFitness();
double[][] parents = selectParentsByTournament(tournamentSize);
double[][] children = breedChildrenFromParents(parents);
for(double[] child : children) {
@fearofcode
fearofcode / FunctionOptimizer.java
Created January 6, 2011 07:15
Simple use of the Watchmaker framework (https://github.com/dwdyer/watchmaker) to optimize the sphere function in N dimension. The sphere function is just (x_1*x_1, ..., x_n*x_n) with a single global minimum at (0, ..., 0).
package org.eccasts.watchmakerexample;
import java.util.*;
import org.uncommons.maths.random.*;
import org.uncommons.watchmaker.framework.*;
import org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory;
import org.uncommons.watchmaker.framework.operators.DoubleArrayCrossover;
import org.uncommons.watchmaker.framework.operators.EvolutionPipeline;
import org.uncommons.watchmaker.framework.selection.RouletteWheelSelection;
@fearofcode
fearofcode / FunctionOptimizer.java
Created January 6, 2011 07:20
Optimize the sphere function in N dimensions using the WatchMaker framework. the function is simply just (x_1*x_1, ..., x_n*x_n) with a single global minimum at (0, ..., 0).
package org.eccasts.watchmakerexample;
import java.util.*;
import org.uncommons.maths.random.*;
import org.uncommons.watchmaker.framework.*;
import org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory;
import org.uncommons.watchmaker.framework.operators.DoubleArrayCrossover;
import org.uncommons.watchmaker.framework.operators.EvolutionPipeline;
import org.uncommons.watchmaker.framework.selection.RouletteWheelSelection;
@fearofcode
fearofcode / gist:948838
Created April 29, 2011 19:16
haskell is pretty cool
import Data.List
rightTriangles = [(a,b,c) | c <- [1 .. ], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2]
{--
*Main> take 10 rightTriangles
[(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17),(12,16,20),(15,20,25),(7,24,25),(10,24,26),(20,21,29)]
--}
@fearofcode
fearofcode / gist:961618
Created May 8, 2011 19:25
Analyzing Rebecca Black's "Friday" in Haskell
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
deriving (Show, Enum)
{--
*Main> let day = Friday -- It's Friday, Friday / Gotta get down on Friday
*Main> pred day -- Yesterday was Thursday
Thursday
*Main> succ day -- Tomorrow is Saturday
Saturday
@fearofcode
fearofcode / gist:991276
Created May 25, 2011 16:16
object creation macros from cbarrett
#define NSDICT(...) [NSDictionary dictionaryWithObjectsAndKeys: __VA_ARGS__, nil]
#define NSARRAY(...) [NSArray arrayWithObjects: __VA_ARGS__, nil]
#define NSBOOL(_X_) ((_X_) ? (id)kCFBooleanTrue : (id)kCFBooleanFalse)
describe("Simple test of jasmine and jasmine-jquery", function() {
it("should be able to run tests on HTML to demonstrate jasmine-jquery", function() {
expect($('<div>some text</div>')).toHaveText('some text')
});
});
@fearofcode
fearofcode / gist:1116266
Created July 31, 2011 01:59
Simple demonstration of speedup achievable with new parallel collection in Scala 2.9
package com.ign
import scala.collection.mutable.ArrayBuffer
object Main extends App {
var wordList = ArrayBuffer[String]()
val size = 10000
for(i <- 1 to size)
@fearofcode
fearofcode / gist:1116319
Created July 31, 2011 02:47
Simple demonstration of speedup achievable with new parallel collection in Scala 2.9
package com.ign
import scala.collection.mutable.ArrayBuffer
object Main extends App {
var wordList = ArrayBuffer[String]()
val size = 10000
for(i <- 1 to size)
wordList += ("foo" + i)
@fearofcode
fearofcode / gist:1145600
Created August 15, 2011 02:11
Sample script to call google closure
import dircache
import os
import os.path
import fnmatch
# change these as needed
js_dirs = ["js/", "js/lib/"]
output_file = "output.js"
jar_path = "lib/java/"