Skip to content

Instantly share code, notes, and snippets.

@iwein
iwein / tests.java
Created October 11, 2016 09:30
The anatomy of a good testcase
@Test
public void shouldWorkAccordingToInstructions() {
//given (instructor is a mock injected in a worker)
given(instructor.getInstructions()).willReturn(particularInstructions);
//when (operate the SUT)
ParticularResult result = workerUnderTest.work();
//then
then(instructor).should.getInstructions();
@iwein
iwein / str-cmp.js
Created December 15, 2012 10:15 — forked from anonymous/str-cmp.js
//make sure you understand what's happening here, you'll thank me some day
'foo' === 'bar'
false
'foo' === 'foo'
true
//watch out!
!'foo' === 'foo'
false
# Get the binaries and move them to the right place
cd /tmp/
wget http://phantomjs.googlecode.com/files/phantomjs-1.7.0-linux-i686.tar.bz2
tar xvjf phantomjs-1.7.0-linux-i686.tar.bz2
mv phantomjs-1.7.0-linux-i686 /opt/
# Make it available to Testacular
sudo ln -s /opt/phantomjs-1.7.0-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
# If you don't want that symlink you can `export PHANTOMJS_BIN=/opt/phantomjs-1.7.0-linux-i686/bin/phantomjs` instead.
@iwein
iwein / git-linux.sh
Created November 11, 2012 06:48
Install git on linux
git clone git://github.com/joyent/node.git
cd node
git checkout v0.8.14-release #latest version
./configure make sudo make install
#Confirm with
node -v
npm -v.
@iwein
iwein / testacular-junit-bamboo.js
Created November 11, 2012 06:45
Testacular junit config for Bamboo
junitReporter = {
// will be resolved to basePath (in the same way as files/exclude patterns)
outputFile: 'test-results.xml'
};
@iwein
iwein / scheduler.py
Created May 7, 2012 17:28
Iron.io scheduler
from iron_worker import *
//you could read this from a file or stdin if you're not too lazy
payload = {'herokuping':{'hosts': ['comma-separated-hosts.com', 'another.net']}}
worker = IronWorker(config='config.ini')
name = "heroku-pinger"
zipFile = IronWorker.createZip(files=["herokuping_worker.py"],
destination="herokuping_worker.zip", overwrite=True)
@iwein
iwein / worker-snippet.py
Created May 7, 2012 17:26
worker script
//there's an argument payload that gets a json file passed in containing the hosts
args = parser.parse_args()
hosts = False
if args.payload is not None:
payload = json.loads(open(args.payload).read())
if 'herokuping' in payload:
hosts = (payload['herokuping']['hosts'])
@iwein
iwein / fit.scala
Created November 22, 2011 21:01
LinearFit full code
object LinearFit {
def through (points : (Double,Double)*) : (Double, Double) = {
val (xTotal,yTotal) = ((0.0,0.0) /: points) { case ((xA, yA), (x, y)) => (xA + x, yA + y) }
val (xAverage, yAverage) = (xTotal / points.size , yTotal / points.size)
val (squareSumXX, squareSumXY) = ((0.0,0.0) /: points) {
case ((ssxx, ssxy), (x, y)) => (ssxx + pow(x - xAverage, 2),
ssxy + (x - xAverage) * (y - yAverage))
}
val b = (squareSumXY / squareSumXX)
(yAverage - b * xAverage, b)
@iwein
iwein / test.scala
Created November 22, 2011 20:46
Combined fit and histogram
LinearFit through (Histogram of hitTimes)
@iwein
iwein / test.scala
Created November 22, 2011 20:44
Designing an api in scala
LinearFit through ((0.0, 1.0), (1.0, 1.0), (2.0, 1.0)) must beEqualTo(1, 0)