Skip to content

Instantly share code, notes, and snippets.

View anttip's full-sized avatar

Antti Pöyhönen anttip

View GitHub Profile
@anttip
anttip / gist:6961879
Last active December 25, 2015 10:29
Coding for Interviews puzzle 10th October 2013. Looked like fun, so here's a quick try at it with javascript. The problem: Find the maximum sum possible from picking a contiguous subsequence of an array. [-1, 5, 6, -2, 20, -50, 4] What is the largest sum of contiguous elements available in this list? In the example above, the maximum sum would b…
function maxContiguousSum(f){
var maxSoFar=0 , maxNow=0, i;
for(i=0; i<f.length; i++){
maxNow = Math.max(0, maxNow+f[i]);
maxSoFar = Math.max(maxSoFar, maxNow);
}
return maxSoFar;
}
function test(expected, actual, msg){
if(expected!==actual){
@anttip
anttip / Stacktrace
Created December 27, 2012 13:29
Running into a problem with Astyanax and Cassandra. Using Astyanax auto paginated query without a column range specifier causes following queries to fail.
15:00:29,501 INFO ~ Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=MyConnectionPool,ServiceType=connectionpool
15:00:29,514 INFO ~ AddHost: 127.0.0.1
Exception in thread "main" com.netflix.astyanax.connectionpool.exceptions.BadRequestException: BadRequestException: [host=127.0.0.1(127.0.0.1):9160, latency=1(1), attempts=1]InvalidRequestException(why:String didn't validate.)
at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:159)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:60)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:200)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:192)
at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$1.execute(ThriftSyncConnectionFactoryImpl.java:136)
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(Abs