This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Q | |
x = 3 | |
class C | |
def stuff | |
puts x | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final String URL_POST = "/post/*/"; | |
@RequestMapping(URL_POST) | |
public String showPost(HttpServletRequest req) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(POST_URL) | |
public String showPost(RequestParts parts) { | |
if (!parts.hasParts()) { | |
// show general page | |
} | |
else { | |
// Show specific page (parts.get(0)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import junit.framework.TestCase; | |
public class StrategyTest extends TestCase { | |
public void testSequentialStrategy() { | |
GuessTheNumber guesser = new GuessTheNumber(5, 100); | |
SequentialStrategy strategy = new SequentialStrategy(guesser); | |
for (int i=0; i<3; i++) { | |
try { |
OlderNewer