Skip to content

Instantly share code, notes, and snippets.

View trishagee's full-sized avatar

Trisha Gee trishagee

View GitHub Profile
public static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream range = range(0, LIST_SIZE * LIST_SIZE);
if (parallel) {
range.parallel();
}
public static int[][] computeLevenshteinAugustin(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Stream<String> wordStream = wordList.stream();
if (parallel) {
wordStream.parallel();
}
wordStream.forEach(word -> {
int wordIndex = wordList.indexOf(word);
public static int[][] computeLevenshteinHector(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Stream<String> wordStream = wordList.stream();
if (parallel) {
wordStream.parallel();
}
distances = wordStream.map(word -> IntStream.range(0, LIST_SIZE)
.map(i -> lesson3b.Levenshtein.lev(word, wordList.get(i)))
package com.mechanitis.talks.stayingahead;
import com.mongodb.DBCollection;
import org.mongojack.JacksonDBCollection;
import org.mongojack.WriteResult;
import javax.ws.rs.core.Response;
import java.net.URI;
public class BadLambdas {
@trishagee
trishagee / populate-database-xml.groovy
Created October 1, 2014 01:25
Shows the section of the script that deals with transforming the XML into something MongoDB-shaped.
def xmlSlurper = new XmlSlurper().parse(new File('resources/all-coffee-shops.xml'))
xmlSlurper.node.each { child ->
Map coffeeShop = ['openStreetMapId': child.@id.text(),
'location' : ['coordinates': [Double.valueOf(child.@lon.text()), Double.valueOf(child.@lat.text())],
'type' : 'Point']]
child.tag.each { theNode ->
def fieldName = theNode.@k.text()
if (isValidFieldName(fieldName)){
coffeeShop.put(fieldName, theNode.@v.text())
@trishagee
trishagee / populate-database-init.groovy
Created October 1, 2014 01:12
Initialisation of the groovy script
import com.mongodb.BasicDBObject
import com.mongodb.MongoClient
def mongoClient = new MongoClient();
def collection = mongoClient.getDB("Cafelito").getCollection("CoffeeShop")
collection.drop()
collection.remove(new BasicDBObject("address.city", "London"));
collection.remove(new BasicDBObject("_id", "jo"));
collection.update(query, personDocument, true, false);
collection.update(new BasicDBObject(),
new BasicDBObject("$set", new BasicDBObject("country", "UK")), false, true);