Skip to content

Instantly share code, notes, and snippets.

def max_depth(map, depth=0):
"""return's the max depth of a n-arry tree"""
if isinstance(map, dict):
depth += 1
val = 0
for x in map.itervalues():
val = max(val, max_depth(x, depth))
return val
else:
return depth
def merge(as: Stream[Int], bs: Stream[Int], cs: Stream[Int]): Stream[Int] = {
val h = as.head min bs.head min cs.head
Stream.cons(
h,
merge(as dropWhile {_ == h}, bs dropWhile {_ == h}, cs dropWhile {_ == h})
)
}
This function produces a stream containing a constant times each value from another:
@sheki
sheki / Config.scala
Created January 27, 2012 20:30
First Cut of a config tool in Scala
class Config(private val envConf: Map[String, _],private val defaultConf: Map[String, _], environment: String) {
def findInteger(key : String ) : Option[Int] = find[Int](key)
def findString(key : String ) : Option[String] = find[String](key)
private def find[T](key : String ) : Option[T] = {
val keyList = key.split("\\.").toList
lookInMap[T](keyList,envConf) match {
case None => lookInMap(keyList,defaultConf)
func() = {
var dataList = List[Array[Byte]]()
breakable {
for (i <- 0 until noItems) {
val response: GetResponse = channel.basicGet(queueName, true)
if (response != null) {
dataList = response.getBody :: dataList
}
else {
break()
@sheki
sheki / QueueMetaCache.scala
Created February 24, 2012 15:32
What is the compile error here?
import java.util.concurrent.TimeUnit
import com.google.common.cache.{LoadingCache, CacheLoader, CacheBuilder}
/**
* using google guave instead of building our own like in the previous case.
*/
class QueueMetaCache extends ConfigSupport {
private val queueRefreshCache :LoadingCache[String, Long]= CacheBuilder.newBuilder()
.maximumSize(10000)
@sheki
sheki / spring.log
Created February 28, 2012 19:28
Spring Error while configuring Codahale Metrics
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from class path resource [spring/codahale-metrics-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.xml.DefaultBeanDefiniti
@sheki
sheki / stack_trace
Created February 28, 2012 20:17
Using codahale metrics+spring. Using annotation throws this error
com.yammer.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:36)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy69.healthAsHTML(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
import com.yammer.metrics.annotation.Timed;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/healthcheck")
public interface HealthCheck
{
import time
@sheki
sheki / Cassandra_irc_schema
Created April 24, 2012 06:24
Cassandra Schema discussion
[11:11:57] <shekispeaks> are there any limits on the data size which can be stored against a super-column
[11:15:01] <driftx> http://www.quora.com/Cassandra-database/Why-is-it-bad-to-use-supercolumns-in-Cassandra don't use supers
[11:17:27] patricioe (~patricioe@99-28-161-222.lightspeed.miamfl.sbcglobal.net) joined the channel.
[11:18:18] Torgan (~Torgan@vil31-1-78-245-104-71.fbx.proxad.net) left IRC. (Quit: This computer has gone to sleep)
[11:18:51] mmalone (~mmalone@c-24-130-137-135.hsd1.ca.comcast.net) left IRC. (Read error: Connection reset by peer)
[11:19:24] mmalone (~mmalone@c-24-130-137-135.hsd1.ca.comcast.net) joined the channel.
[11:20:19] <nickmbailey> use composite columns instead: http://www.datastax.com/dev/blog/introduction-to-composite-columns-part-1
[11:20:42] <shekispeaks> ha thanks
[11:21:01] <nickmbailey> or just use regular columns
[11:21:35] wlian (~wlian@c-76-126-197-65.hsd1.ca.comcast.net) left IRC. (Quit: wlian)