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
/** | |
* Clear-headed attempt at a functional-style, "Scala-way" implementation. | |
* | |
* Seems to work on trivial cases. Too lazy to write unit tests now (note to self: write them later and then pretend I did TDD). | |
*/ | |
class GameOfLife(val width: Int, val height: Int, val liveCells: Set[(Int, Int)]) { | |
def nextIteration: GameOfLife = { | |
val newCells = for { | |
(cell, liveNeighborCount) <- liveNeighborCounts |
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
package test; | |
import java.util.concurrent.ConcurrentLinkedQueue; | |
/** | |
* Illustrates a case when Collection.size() cannot reliably indicate how many elements were dumped by | |
* Collection.toArray(). | |
* | |
* Assuming that the array is reused and was previously filled with unrelated values, the fact that toArray() | |
* writes null after the last element is the only way to find out how many elements were actually dumped. |
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.Date; | |
/** | |
* Example code for my blog post "The TOCTTOU attack", available at http://out-println.appspot.com/posts/tocttou. | |
*/ | |
public class Tocttou { | |
public static final class Interval { | |
private final Date min; |
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 static ch.qos.logback.classic.Level.ALL; | |
import static org.slf4j.Logger.ROOT_LOGGER_NAME; | |
import java.io.ByteArrayOutputStream; | |
import java.io.OutputStream; | |
import java.io.UnsupportedEncodingException; | |
import java.nio.charset.Charset; | |
import ch.qos.logback.classic.Level; | |
import ch.qos.logback.classic.Logger; |
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
/* | |
* Copyright (c) 2010, Olivier Michallat | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without modification, | |
* are permitted provided that the following conditions are met: | |
* | |
* 1. Redistributions of source code must retain the above copyright notice, this | |
* list of conditions and the following disclaimer. | |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
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.Calendar._ | |
import java.util.GregorianCalendar | |
import java.util.GregorianCalendar._ | |
import java.util.TimeZone | |
// A calendar in Paris' time zone (GMT+1) | |
val cfr = new GregorianCalendar | |
cfr.setTimeZone(TimeZone.getTimeZone("Europe/Paris")) | |
// A calendar at GMT+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
/* Basic j.u.l config for simple projects */ | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
public class Jul{ | |
static { | |
Logger.getLogger("").setLevel(Level.SEVERE); | |
final Logger myLogger = Logger.getLogger("com.mycompany"); | |
myLogger.setLevel(Level.FINEST); |
NewerOlder