Skip to content

Instantly share code, notes, and snippets.

@kvalle
kvalle / MyTestRunner.java
Created January 16, 2012 19:09
Mininimal example of setup for writing Grinder test scripts in Java
package my.java.package;
import net.grinder.plugin.http.HTTPRequest;
import net.grinder.script.NotWrappableTypeException;
import net.grinder.script.Test;
public class MyTestRunner {
private HTTPRequest test;
@kvalle
kvalle / rampup.py
Created March 16, 2012 17:33
Decorator for Grinder thread-rampup
from net.grinder.script.Grinder import grinder
def thread_rampup(interval):
"""Decorator for waking grinder threads incrementally.
Input argument `interval` determines time in ms between wakeup of each thread.
Usage:
class TestRunner:
@thread_rampup(3000)
@kvalle
kvalle / progress.py
Created November 21, 2012 22:14
Demo of python "progress bar"
import time
import sys
total = int(sys.argv[1]) if len(sys.argv) > 1 else 100
def status_line(num, total):
line = "> processed %d of %d files" % (num, total)
sys.stdout.write(line)
sys.stdout.flush()
sys.stdout.write("\b" * (len(line)))
@kvalle
kvalle / tests.sml
Created January 28, 2013 09:09
Simple function for testing Standard ML code
use "hw2.sml";
fun test (tests) =
let
fun assess ([], _) = []
| assess (x::rest, num) = if x then assess(rest,num+1)
else Int.toString(num)^""::assess(rest,num+1)
val results = assess(tests,1)
in
case results of [] => "OK"
@kvalle
kvalle / asserts.sml
Last active December 12, 2015 05:58
Tests for coursera-pl hw3
fun assert_equals (expected, actual, formatter) =
if expected = actual
then " -- PASS"
else "Expected: '" ^ formatter (expected) ^ "' but got '" ^ formatter (actual) ^ "' -- FAIL"
fun assert_bool_equals(expected, actual) =
if expected = actual then " -- PASS"
else "Expected: " ^ Bool.toString (expected) ^ ", but was: " ^ Bool.toString (actual) ^ " -- FAIL"
fun assert_true (actual) = assert_bool_equals(true, actual)
import re
from flask import Flask, request
app = Flask(__name__)
@app.route('/', endpoint='index')
def index():
question = request.args.get("q", "").partition(": ")[2]
answer = solve(question)
print "\nQ: %s?\nA: %s" % (question, answer)
@kvalle
kvalle / hw7testsprovided.sml
Last active December 14, 2015 19:29
Provided tests for SML part of HW7 in Coursera course on programming languages, re-written to work with https://github.com/kvalle/sml-testing
(* University of Washington, Programming Languages, Homework 7
Based on hw7testsprovided.sml *)
use "hw7.sml";
use "testing.sml"; (* Requires https://github.com/kvalle/sml-testing to run! *)
open SmlTests;
fun real_equal(x,y) = Real.compare(x,y) = General.EQUAL;
@kvalle
kvalle / fizzbuzz.py
Last active June 20, 2016 14:31
Fizzbuzz, using Python generator expression and iterators
from itertools import cycle, islice, izip, imap
fizz = cycle([""]*2 + ["fizz"])
buzz = cycle([""]*4 + ["buzz"])
fizzbuzz = imap(lambda (i, x): x[0]+x[1] or (i+1), enumerate(izip(fizz,buzz)))
print list(islice(fizzbuzz, 100))
@kvalle
kvalle / extreme-flask.py
Created October 10, 2013 15:20
Enkel server for Extreme Startup med Flask i Python
import re
from flask import Flask, request
app = Flask(__name__)
@app.route('/', endpoint='index')
def index():
question = request.args.get("q", "").partition(": ")[2]
answer = "the answer"
print "\nQ: %s?\nA: %s" % (question, answer)
@kvalle
kvalle / notes.md
Last active September 25, 2015 05:12
Future Programming Workshop - SL2015

Programmeringens fremtid

Som programmerere, hvordan kommer hverdagen vår til å se ut i fremtiden? Det er spørsmålet vi forsøker å besvare på Future Programming Workshop, en event som arrangeres dagen før StrangeLoop 2015.

Som arrangøren formulerte det innledningsvis, "at StrangeLoop you'll see a lot of stuff that actually works, but what about five or ten years from now?" Vi forsøker vi å løfte blikket for å få et glimt av hva som rører seg på horisonten.

De store linjene

Hvis vi myser litt, så kan dagens temaer grovt deles inn i to kategorier: