Skip to content

Instantly share code, notes, and snippets.

engine = Moonstone::Engine.new
engine.index(@some_docs)
engine.reader do |r|
r.terms.for_field('name').sort.should == %w{ burger king depeche mode }.sort
end
# Use Jruby to read hadoop sequence files
def load_libs(libs)
Dir.glob(File.join(libs,"*.jar")).each { |f|
require f
}
end
load_libs ENV["HADOOP_HOME"]
load_libs File.join(ENV["HADOOP_HOME"], 'lib')
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class Embedder {
public ScriptingContainer container;
public String file;
public Embedder(String filename) {
file = filename;
container = new ScriptingContainer();
package play;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class ClassUseSample {
public ScriptingContainer container;
public String file;
public ClassUseSample(String filename) {
# i don't have a rails app handy, but I think this works if you have dependt destroy set for the child relationship
post.comments.delete(@some_comment)
# instant.rake
# Rake rules for compiling and running trivial Java programs
#
# Usage: rake com.example.MonkeyShines
# Source goes under ./src
# Classes end up under ./target
require 'rake/clean'
libs = FileList["lib/*"]
A="jar $JOB_JAR com.attinteractive.ar.hadoopjobs.examplejob.Main $1 $2"
B="mvn exec:exec -Dexec.args="
exec $B"$A"
String xmlFile = "Wikipedia-Category-GlobalWarming-20090919043526.xml";
InputStream is = WikipediaSeederTest.class.getClassLoader().getResourceAsStream(xmlFile);
XPath xpath = XPathFactory.newInstance().newXPath();
String xmlFile = "Wikipedia-Category-GlobalWarming-20090919043526.xml";
InputStream is = WikipediaSeederTest.class.getClassLoader().getResourceAsStream(xmlFile);
InputSource inputSource = new InputSource( is );
NamespaceContext context = new NamespaceContextMap("wp", "http://www.mediawiki.org/xml/export-0.3/");
xpath.setNamespaceContext(context);
NodeList elements = (NodeList)xpath.evaluate(
"//wp:page", inputSource, XPathConstants.NODESET );
int count = Files.readLines(
new File("/path/to/file"),
Charsets.UTF_8, // remember that? :)
new LineProcessor<Integer>() {
int count = 0;
public boolean processLine(String line) {
count++;
}
public Integer getResult() { return count; }
});