Skip to content

Instantly share code, notes, and snippets.

View StrategyTest.java
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);
View SequentialStrategy.java
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++) {
View GuessTheNumber.java
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;
View gist:760535
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 Dec 31, 2010
For Post: Using pretty URLs with Spring and Annotations (pt4)
View gist:760521
@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 Dec 31, 2010
For Post: Using pretty URLs with Spring and Annotations (pt3)
View gist:760520
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 Dec 31, 2010
For Post: Using pretty URLs with Spring and Annotations (pt2)
View gist:760518
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 Dec 31, 2010
For Post: Using pretty URLs with Spring and Annotations (pt1)
View gist:760510
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 Mar 25, 2010
HELP! How to use a variable at the module scope within a class
View How to use a variable declared within a module in a class.rb
module Q
x = 3
class C
def stuff
puts x
end
end
end