Skip to content

Instantly share code, notes, and snippets.

@dfilimon
dfilimon / jeopy_ip.py
Created December 4, 2010 12:58
Getting all IP addresses of a particular machine in Python. Unfortunately it doesn't work properly in Linux without a properly configured /etc/hosts file.
self.ip = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0]
@dfilimon
dfilimon / ATETextPane.java
Created October 17, 2012 21:08
Add this after ATETextPane.java:137 to enjoy anti-aliased text in your ANTLWorks editor! :)
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@dfilimon
dfilimon / GView.java
Created October 17, 2012 21:27
Add this after Gview.java:380 to enjoy anti-aliased placeholder text in your ANTLRWorks diagram viewer.
g.setFont(new Font(AWPrefs.getEditorFont(), Font.PLAIN, 2 * AWPrefs.getEditorFontSize()));
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@dfilimon
dfilimon / BasicKMeans.java
Created November 8, 2012 13:13
This compiles file, but I'm having classpath issues.
package org.apache.mahout.knn.experimental;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
@dfilimon
dfilimon / AbstractSymbolTest.java
Created November 12, 2012 13:03
AbstractSymbol not hashable properly
import static org.junit.Assert.*;
import java.util.Set;
import org.junit.Test;
import com.google.common.collect.Sets;
public class AbstractSymbolTest {
@dfilimon
dfilimon / StreamingKMeansFailure.txt
Created December 5, 2012 23:17
StreamingKMeans failure for 10 dimensions
org.apache.mahout.knn.search.ProjectionSearch org.apache.mahout.common.distance.EuclideanDistanceMeasure
Total number of clusters 344
java.lang.AssertionError: Maximum weight too large 1.4078472959685535
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.assertTrue(Assert.java:43)
at org.apache.mahout.knn.cluster.StreamingKMeansTest.testClustering(StreamingKMeansTest.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
@dfilimon
dfilimon / plot-streaming-kmeans.r
Created December 6, 2012 22:24
Trying to plot different columns
plot_skm <- function(infile) {
print(infile)
library(package=ggplot2)
skm <- read.table(infile, skip=1)
cur_dev <- dev.cur()
plot_file <- paste(infile, '-numDataPointSeen.png', sep='')
@dfilimon
dfilimon / Seqfile3DProjector.java
Created December 27, 2012 19:28
Projecting vectors
// Project the vector.
Vector vectorValue = value.get().clone();
Vector projectedVector = new DenseVector(3);
for (int i = 0; i < 3; ++i) {
projectedVector.set(i, vectorValue.dot(basisVectors.get(i)));
}
projectedVector = projectedVector.normalize();
writer.printf("%f %f %f\n", projectedVector.get(0), projectedVector.get(1),
projectedVector.get(2));
@dfilimon
dfilimon / StreamingKMeansTest.java
Created January 2, 2013 18:13
Logback output to stream.
ByteArrayOutputStream bs = new ByteArrayOutputStream(2048);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.reset();
lc.setName("context");
lc.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(lc);
encoder.setPattern("%message\n");
@dfilimon
dfilimon / DelegatingVector.java
Created January 2, 2013 21:43
DelegatingVector's clone()
@Override
public Vector clone() {
DelegatingVector r;
try {
r = (DelegatingVector) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone not supported for DelegatingVector, shouldn't be possible");
}
// delegate points to original without this
r.delegate = delegate.clone();