This file contains hidden or 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
| compile and run all tests | |
| ./pants tests/java/com/twitter/common:all! | |
| find all java targets | |
| $ ./pants list -d src/java tests/java | |
| src/java/com/twitter/common/application/BUILD:action | |
| src/java/com/twitter/common/application/BUILD:application | |
| src/java/com/twitter/common/application/http/BUILD:http | |
| src/java/com/twitter/common/application/modules/BUILD:applauncher | |
| src/java/com/twitter/common/application/modules/BUILD:http |
This file contains hidden or 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 Pair<U,T> { | |
| public final U left; | |
| public final T right; | |
| public static <U,T> Pair<U,T> of(U u, T t) { | |
| return new Pair<U,T>(u, t); | |
| } | |
| public Pair(U left, T right) { |
This file contains hidden or 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 GenericsTest { | |
| public static void main(String[] args) { | |
| Bar b = new Bar("Test"); | |
| System.out.println(b.getReferenceType().getType()); | |
| } | |
| static class TypeReference<T> { |
This file contains hidden or 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
| #------------------------------------------------------------------------------ | |
| # | |
| # The following properties set the logging levels and log appender. The | |
| # log4j.rootCategory variable defines the default log level and one or more | |
| # appenders. For the console, use 'S'. For the daily rolling file, use 'R'. | |
| # For an HTML formatted log, use 'H'. | |
| # | |
| # To override the default (rootCategory) log level, define a property of the | |
| # form (see below for available values): | |
| # |
This file contains hidden or 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
| FileSystem fs = FileSystems.getDefault(); | |
| for (FileStore e : fs.getFileStores()) { | |
| System.out.println(e.name() + " " + e.getTotalSpace() + " " + e.type()); | |
| } | |
| On my box returns: | |
| /dev/sda1 488306122752 ext4 | |
| proc 0 proc | |
| sysfs 0 sysfs |
This file contains hidden or 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
| def scanTrace() { | |
| import collection.mutable.{ HashMap, MultiMap, Set } | |
| val source = scala.io.Source.fromFile("google-cluster-data-1.csv") | |
| val map = new HashMap[String, Set[String]] with MultiMap[String, String] | |
| for (i <- source.getLines()) { | |
| val fields = i.split(" ") | |
| val parent = fields(1) |
This file contains hidden or 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
| // scala | |
| (1 to 100).toList foreach { x => x match { | |
| case x if (x % 15 == 0) => println("FizzBuzz") | |
| case x if (x % 3 == 0) => println("Fizz") | |
| case x if (x % 5 == 0) => println("Buzz") | |
| case x => println(x) | |
| } | |
| } |
This file contains hidden or 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
| val list = (1 to 10).toList | |
| // imutable map | |
| val map1 = list.foldLeft(Map.empty[Int,String])( (map, value) => map + (value -> value.toString) ) | |
| // this is equivalent to | |
| val map1 = list.foldLeft(Map.empty[Int,String])( (map, value) => map + ((value, value.toString)) ) | |
| // imutable map with more complex value (note the extra parenthesis) |
This file contains hidden or 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
| def suffix(l: List[Int]): List[List[Int]] = l match { | |
| case Nil => List()::Nil | |
| case _ => l :: suffix(l.tail) | |
| } |
This file contains hidden or 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 WTF extends Thread { | |
| private boolean finished = false; | |
| ... | |
| public void run() { | |
| .... | |
| while (!finished) { |