Skip to content

Instantly share code, notes, and snippets.

View kevinmeredith's full-sized avatar

Kevin Meredith kevinmeredith

  • https://twitter.com/Gentmen
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fibonacci
{
class Program
{
@kevinmeredith
kevinmeredith / gist:4542857
Created January 15, 2013 22:39
dumb example
void foo() {
print "bar";
}
@kevinmeredith
kevinmeredith / a.java
Created February 19, 2013 04:30
sangho lights stationary with walls
package mosquito.g1;
import java.awt.geom.Line2D;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;
@kevinmeredith
kevinmeredith / PartOfHeadsUp.java
Created March 20, 2013 03:51
Methods `isLetterInDictionary()` and `getBid()`. The latter method calls `isLetterInDictionary(letter, bonusDictionary)` to find out if the letter can form a 7-letter word for the given bonusDictionary
private boolean isLetterInDictionary(Letter letter, Set<Multiset<Character>> dictionary) {
for (Multiset<Character> temp : dictionary) {
if(temp.contains(letter.getCharacter())) {
logger.error("temp(" + temp.toString() + " contains the letter, " + letter.toString());
return true;
}
}
return false;
}
@kevinmeredith
kevinmeredith / method.java
Created April 4, 2013 02:04
recursive Java function
private List<Integer> getStartTimes(List<Plane> inPlanes, List<Integer> startTimes, int index) {
if (inPlanes.size() == 0) {
return startTimes;
}
else {
startTimes.add(inPlanes.remove(index++).getDepartureTime());
return getStartTimes(inPlanes, startTimes, index);
}
}
@kevinmeredith
kevinmeredith / TestLoadingJsNumber.scala
Created September 19, 2013 00:37
java.lang.IllegalArgumentException: can't serialize class scala.math.BigDecimal
package test
import com.mongodb.casbah.Imports._
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
import play.api.libs.json._
import play.api.{Play, Logger}
class TestLoadingJsNumber extends FlatSpec with ShouldMatchers {
@kevinmeredith
kevinmeredith / File.scala
Last active December 24, 2015 07:19
Problem when trying to bulk insert in Casbah
// recurse through each element of "docs", using `builder` to add another key-value MongoDBObject for time-stamp purposes
def getEnrichedDocs(docs: List[DBObject]) : List[DBObject] = {
def go(list : List[DBObject], docs_: List[DBObject]) : List[DBObject] = list match {
case x :: xs => var builder = MongoDBObject()
builder = builder ++ MongoDBObject("LoadTimestamp" -> Utils.getTimestamp) // returns a Long (I know that I should be using a BSON TS, but that's a TODO
builder = builder ++ x
go(xs, docs_ :+ builder) // call go() recursively with the updated accumulator (2nd arg)
case Nil => docs_
}
go(docs, List[DBObject]())
@kevinmeredith
kevinmeredith / MongoTesting.js
Last active December 24, 2015 12:19
Testing Multi-key Indexing
// Array of JSON Objects where each JSON object has a non-distinct key name
// note that `records`'s array element row has name, age and hair
// Note- update at bottom showing how to use $elemMatch to achieve what the initial find()'s could not
db.test3.find()
{ "_id" : 1, "records" : [ { "name" : "ralph", "age" : "55", "hair" : "brown" } ] }
{ "_id" : 2, "records" : [ { "name" : "bill", "age" : "25", "hair" : "blue" } ] }
{ "_id" : 3, "records" : [ { "name" : "joe", "age" : "35", "hair" : "blonde" } ] }
>
> db.test3.ensureIndex( { records: 1} )
@kevinmeredith
kevinmeredith / TestElemMatch.scala
Created October 3, 2013 21:23
Testing Mongo's $elemMatch DSL with the Casbah API
package test
import com.mongodb.casbah.Imports._
import com.mongodb.util.JSON
import com.typesafe.config.ConfigFactory
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
import play.api.libs.json._
import play.api.{Play, Logger}