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
| rootDir = "/home/zcox/dev/20_newsgroups" | |
| raise rootDir + " does not exist" unless File.directory? rootDir | |
| counts = Hash.new(0) #0 will be the default value for non-existent keys | |
| Dir["#{rootDir}/**/*"].reject{|file| File.directory? file}.each do |file| | |
| IO.read(file).scan(/\w+/) { |word| counts[word.downcase] += 1 } | |
| end | |
| open("counts-descreasing-ruby", "w") do |out| | |
| counts.sort { |a, b| b[1] <=> a[1] }.each { |pair| out << "#{pair[0]}\t#{pair[1]}\n" } |
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
| import java.io._ | |
| val rootDir = new File("/home/zcox/dev/20_newsgroups") | |
| if (!rootDir.exists) throw new IllegalArgumentException(rootDir + " does not exist") | |
| var counts = Map.empty[String, Int].withDefaultValue(0) | |
| files(rootDir) { _.split("""\W+""").foreach { word => counts = counts(word.toLowerCase) += 1 }} | |
| write(counts, "counts-descreasing-scala") {_._2 > _._2} | |
| write(counts, "counts-alphabetical-scala") {_._1 < _._1} | |
| /** Writes the specified map to the specified file in tab-delimited format, sorted accordingly. */ |
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 using[A <: {def close(): Unit}, B](param: A)(f: A => B): B = | |
| try { | |
| f(param) | |
| } finally { | |
| param.close() | |
| } |
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
| <properties> | |
| <scala.version>2.8.0</scala.version> | |
| </properties> | |
| ... | |
| <plugin> | |
| <groupId>org.scala-tools</groupId> | |
| <artifactId>maven-scala-plugin</artifactId> | |
| <executions> |
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
| import com.tinkerpop.blueprints.pgm._ | |
| import com.tinkerpop.blueprints.pgm.impls.tg._ | |
| import com.tinkerpop.pipes._ | |
| import com.tinkerpop.pipes.util._ | |
| import scala.collection.JavaConversions.asScalaIterator | |
| import java.lang.{Boolean => JBoolean} | |
| val graph = TinkerGraphFactory.createTinkerGraph() | |
| //Adapter from T => Boolean to PipeClosure along with an implicit conversion |
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 ABTest { | |
| public static void main(String[] args) { | |
| A<String> a = new A<String>().f1().f2(); | |
| B<String> b = new B<String>().f1().f2().f3(); | |
| System.out.println(a + " " + b); | |
| } | |
| /** The type parameter T just shows we can parameterize these types. */ |
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
| trait PipeFunction[A, B] | |
| class NullPipeFunction[A, B] extends PipeFunction[A, B] | |
| trait Pipe[S, E] | |
| class Pipeline[S, E, T[S, E]] extends Pipe[S, E] { | |
| def add[F](pipe: Pipe[E, F]): T[S, F] = | |
| throw new UnsupportedOperationException() | |
| } |
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 Base<T extends Base> { | |
| public T f1() { | |
| return (T) this; //Warning => Type safety: Unchecked cast from Forgetful.Base<T> to T | |
| } | |
| public T f2() { | |
| return (T) this; //Warning => Type safety: Unchecked cast from Forgetful.Base<T> to 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
| package write | |
| import com.tinkerpop.blueprints.pgm.{ Index, Vertex, Edge, IndexableGraph, TransactionalGraph } | |
| import com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph | |
| import com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jGraph | |
| import com.tinkerpop.blueprints.pgm.TransactionalGraph.Conclusion._ | |
| import scala.collection.JavaConversions._ | |
| import java.util.Date | |
| object PerfTest { |
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
| Mozilla/4.0 (BREW 3.1.5; U; en-us; Sanyo; NetFront/3.5.1/AMB) Boost SCP3810 |
OlderNewer