Skip to content

Instantly share code, notes, and snippets.

memo = {};
function fibonacci(num) {
if (num <= 1) return 1;
if (! memo[num]) {
memo[num] = fibonacci(num - 1) + fibonacci(num - 2);
}
return memo[num];
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<Pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
class SimplePropertySpec extends Specification with ScalaCheck {
"the property test" should {
"prove addition and multiplication are related" in {
forAll{(a: Int) => a+a must_== 2*a}
}
}
}
@CliveEvans
CliveEvans / CountingEventsDemo.java
Created January 20, 2011 20:48
Using Expectations in test
package com.blogspot.swishbob;
import static com.blogspot.swishbob.MessageCounter.COMPLETED;
import static com.blogspot.swishbob.MessageCounter.REASSIGNED;
import static com.blogspot.swishbob.MessageCounter.TIMED_OUT;
import static com.blogspot.swishbob.MessageEventType.MESSAGE_COMPLETED;
import static com.blogspot.swishbob.MessageEventType.MESSAGE_REASSIGNED;
import static com.blogspot.swishbob.MessageEventType.MESSAGE_TIMED_OUT;
import static com.blogspot.swishbob.Expectation.expect;
private String removeNewlines(String inputString) {
String returnString = "";
for (int i = 0;i < inputString.length(); i++) {
if ((inputString.charAt(i) == '\r') || (inputString.charAt(i) == '\n')) {
}
else {
returnString = returnString + inputString.charAt(i);
}
}
return returnString;
public class StringArrayConfigurationEntry extends AbstractConfigurationEntry<String[]> {
public StringArrayConfigurationEntry(String name) {
super(name);
}
@Override
public boolean invalid(String[] value) {
return false;
}
@CliveEvans
CliveEvans / wtf.java
Created July 6, 2010 10:09
general code snippets
int escalated = 0, regular = 0, requeue = 0;
for (LanguageMessageCountType languageMessageCountType : LanguageMessageCountType.values()) {
switch (languageMessageCountType) {
case ESCALATED:
escalated = languageQueue.getEscalatedMessagesCount();
keyValuesMap.put(languageMessageCountType.name(), String.valueOf(escalated));
break;
case REGULAR:
regular = languageQueue.getRegularMessagesCount();
keyValuesMap.put(languageMessageCountType.name(), String.valueOf(regular));
private List<AbstractConfigurationEntry<?>> entries = new ArrayList<AbstractConfigurationEntry<?>>();
/**
*
* {@link AbstractConfiguration} now uses reflection to build its list of entries<p>
* You no longer need to call define to add your {@link AbstractConfigurationEntry}s to the list to be validated<p>
*
* This method will be removed in the next version
*
*/
public class Helper {
public void addInterface(SomeInterface some) {
}
}