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:3487507
Created August 27, 2012 11:08
anyone who formats their code like this should be summarily executed
for(int q=start;q<n+start;q++)
{
IntegerVectorIndividual i = (IntegerVectorIndividual)inds[q];
for(int x=0;x<i.genome.length;x++)
if (state.random[thread].nextBoolean(species.mutationProbability))
i.genome[x] = -i.genome[x];
// it's a "new" individual, so it's no longer been evaluated
i.evaluated=false;
}
return n;
@fearofcode
fearofcode / Posttest.scala
Created August 29, 2012 23:01
unable to get Scalamachine to handle post requests (edit: fixed)
package com.stackmob.posttest.server
import java.net.InetSocketAddress
import com.twitter.finagle.builder.ServerBuilder
import com.twitter.finagle.http.Http
import com.stackmob.common.logging.LoggingSugar
import scalamachine.finagle.{FinagleWebmachineV3, FinagleWebmachineService}
import scalamachine.core.dispatch.Route._
@fearofcode
fearofcode / gist:3697023
Created September 11, 2012 08:55
matrix row/column indexing in R + csv input
> a <- array(1:20, dim=c(4:5))
> a
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
> a[1,]
[1] 1 5 9 13 17
> a[,2]
@fearofcode
fearofcode / gist:3861024
Created October 9, 2012 19:53
java client sdk issue
final CountDownLatch localLatch = latchOne();
final MultiThreadAsserter localAsserter = new MultiThreadAsserter();
StackMobObjectOnServer<UserOnServer> user = doLoginLogout(StackMob.OAuthVersion.Two, false);
List<HashMap<String, String>> chores = new ArrayList<HashMap<String, String>>();
HashMap<String, String> todo1 = new HashMap<String, String>();
todo1.put("action", "related object 1");
HashMap<String, String> todo2 = new HashMap<String, String>();
@fearofcode
fearofcode / gist:5002102
Created February 21, 2013 04:36
Simple Ruby OOP example
class RentalCar
attr_accessor :miles_travelled
def check_maintenance
if @miles_travelled > 60000
puts "Give it a tuneup!"
end
end
end
# See http://www.zerocater.com/challenge/#mathy-challenge for details of what
# this code does
#
# The approach I took was to Google 'primal sums' and get most of the solution
# directly:
#
# http://oeis.org/A007506
#
# I also use pre-computed lists of primes to avoid having to implement a sieve
# in order to get lists of primes.
@fearofcode
fearofcode / plot_series.gp
Created February 25, 2013 22:59
sample gnuplot script for plotting multiple time series together, each with different colors
# resulting image: http://i.imgur.com/E5CsReh.png
# create a 1680x1050 image using Arial, 12pt
set terminal pngcairo enhanced font "arial,12" fontscale 1.0 size 1680, 1050
# write to the file 'multiplot_test.png'
set output 'multiplot_test.png'
# turn key off since we will be plotting many different
@fearofcode
fearofcode / timeseriesplot.r
Created March 19, 2013 20:27
Sample usage of ggplot2 to highlight timeseries by color. http://t.co/DDfe8eWZkY for sample image of what it looks like when used with plausible CSV data
library(ggplot2)
eurusd <- read.table("/home/warren/Downloads/EURUSD_Candlestick_1_D_BID_01.03.2007-16.03.2013.csv", sep=",", header=T)
eurusd$Time <- as.Date(eurusd$Time, "%d.%m.%Y %H:00:00.000")
long_trades = read.table(textConnection(
"Open, Close
2009-02-02, 2009-02-10
2009-04-05, 2009-06-07
2013-01-01, 2013-01-25"), sep=',',
@fearofcode
fearofcode / sl.sh
Created October 7, 2013 23:32 — forked from ieure/sl.sh
#! /bin/bash
IFS="
"
echo
for FRAME in \
"B :^)" \
" B :^)" \
" B :^)" \
" B :^)" \
#!/bin/sh
# rename pre-commit.sample in the hooks directory to pre-commit and replace its content with this
set_traces=`git grep "pdb.set_trace()"`
if [ ! -z "$set_traces" ] ; then
echo "You have pdb.set_trace() in your code! Commit aborted!"
echo $set_traces
exit 1