Skip to content

Instantly share code, notes, and snippets.

@schauder
schauder / Fizz Buzz.scala
Created August 15, 2011 21:28
Fizz Buzz Kata, mit dem 'funktionalen' refactoring von der Couch
package de.schauderhaft.kata.fizzbuzz
import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class FizzBuzzTest extends FunSuite with ShouldMatchers {
@schauder
schauder / DemonstrationTest.scala
Created August 30, 2011 18:57
A simple collection of ScalaTest examples
package de.schauderhaft.testen
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.BeforeAndAfterEach
@RunWith(classOf[JUnitRunner])
class DemonstrationTest extends FunSuite with ShouldMatchers {
@schauder
schauder / Always be honest in your code
Last active December 14, 2015 09:18
We found some exception handling code we weren't satisfied with, so we refactored it.
**before**
} catch (final Exception e) {
LOG.error(e.toString(), e);
return null;
}
**after**
} catch (final Exception e) {
object SetSeq {
// Set has a + operator with the same argument type as the elements
// Set does not have a :+ operator (prepending/appending doesn't make sens with out an ordering of the elements)
// Seq has a :+ operator which takes any type and returns a Seq with appropriate supertype of existing and new elements
// if no + operator exists and a String is used as an argument the collection is converted to a String and the result concatenated with the argument
val intSet = Set(1,2,3) //> intSet : scala.collection.immutable.Set[Int] = Set(1, 2, 3)
val strSet = Set("a","b","c") //> strSet : scala.collection.immutable.Set[java.lang.String] = Set(a, b, c)
val intSeq = Seq(1,2,3) //> intSeq : Seq[Int] = List(1, 2, 3)
import de.schauderhaft.degraph.configuration.NamedPattern;
import static de.schauderhaft.degraph.check.JCheck.*;
import org.junit.Test;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.assertThat;
import static de.schauderhaft.degraph.check.Check.classpath;
http://www.calormen.com/jsbasic/
10 GR
19 rem Himmel
20 color=14
30 for y = 0 to 20
40 HLIN 0,39 at y
50 next y
210 GR
220 REM CHOOSE A RANDOM COLOR
230 COLOR=RND(16)
240 REM CHOOSE A RANDOM POINT (X,Y)
250 x=RND(40)
260 Y=RND(40)
235 print x
280 PLOT X,Y
290 REM COOSE ANOTHER RANDOM COLOR AND POINT
300 goto 230
@schauder
schauder / gist:3ef94523366a7b871d63
Created January 20, 2016 11:41
Switch Configurationg Batch Script
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` LOCATION-NAME"
exit 1
fi
# switch git configuration
cat ~/base.gitconfig ~/$1.gitconfig > ~/.gitconfig
# switch gradle configuration
@schauder
schauder / SysoutRule.java
Last active April 23, 2016 14:43
A JUnit rule for testing output to `System.out`
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
public class SysoutRule implements TestRule {
private ByteOutputStream out;
public void contains(String string) {
class $12DynamicWithPixieDustTest extends LambdaBasedTests {{
List<Integer> ints = asList(Integer.MAX_VALUE, Integer.MIN_VALUE, -1, 0, 1, 2, 10);
for (Integer i : ints) {
for (Integer j : ints) {
test(format("adding integers is commutative (%d, %d)", i,j), () -> {
assertEquals(i + j, j + i);
});
}
}