Skip to content

Instantly share code, notes, and snippets.

import junit.framework.TestCase;
public class StrategyTest extends TestCase {
public void testSequentialStrategy() {
GuessTheNumber guesser = new GuessTheNumber(5, 100);
SequentialStrategy strategy = new SequentialStrategy(guesser);
int value = strategy.solve();
assertEquals(guesser.getValue(), value);
public class SequentialStrategy {
private final GuessTheNumber guesser;
public SequentialStrategy(GuessTheNumber guesser) {
this.guesser = guesser;
}
public int solve() {
for (int i=guesser.getMin(); i<=guesser.getMax(); i++) {
import java.util.Random;
public class GuessTheNumber {
private final Integer value;
private final int min;
private final int max;
private int guesses = 0;
private boolean solved = false;
set archiveFolderName to "@Archive"
set exchangeAccount to "My Exchange Email"
tell application "Microsoft Entourage"
repeat with msg in (get current messages)
move msg to folder archiveFolderName in Exchange account exchangeAccount
end repeat
end tell
@ericanderson
ericanderson / gist:760521
Created December 31, 2010 00:13
For Post: Using pretty URLs with Spring and Annotations (pt4)
@RequestMapping(POST_URL)
public String showPost(RequestParts parts) {
if (!parts.hasParts()) {
// show general page
}
else {
// Show specific page (parts.get(0))
}
}
@ericanderson
ericanderson / gist:760520
Created December 31, 2010 00:12
For Post: Using pretty URLs with Spring and Annotations (pt3)
String[] parts = UrlUtils.breakUri(req.getRemoteUri(), URL_POST);
if (parts == null) {
// Do code to show an archive or whatever you want when the * part is missing
}
else {
// parts[0] will have what you want.
}
@ericanderson
ericanderson / gist:760518
Created December 31, 2010 00:11
For Post: Using pretty URLs with Spring and Annotations (pt2)
public class UrlUtils {
public static String[] breakUri(final String uri, final String expectedUrl) {
Pattern p = Pattern.compile(expectedUrl.replace("*", "(.*?)"));
Matcher m = p.matcher(uri);
if (m.find()) {
String[] ret = new String[m.groupCount()];
for (int i=0; i<ret.length; i++) {
ret[i] = m.group(i+1);
}
return ret;
@ericanderson
ericanderson / gist:760510
Created December 31, 2010 00:06
For Post: Using pretty URLs with Spring and Annotations (pt1)
public static final String URL_POST = "/post/*/";
@RequestMapping(URL_POST)
public String showPost(HttpServletRequest req) {
...
}
@ericanderson
ericanderson / How to use a variable declared within a module in a class.rb
Created March 25, 2010 17:51
HELP! How to use a variable at the module scope within a class
module Q
x = 3
class C
def stuff
puts x
end
end
end