Skip to content

Instantly share code, notes, and snippets.

Russell Cohen rcoh

View GitHub Profile
@rcoh
rcoh / gist:1390585
Created Nov 24, 2011
fancy decorator
View gist:1390585
def retry_with_backoff(success_func, backoff_rate=2, checkback_time=1):
def wrap(f):
def new_function(*args, **kw):
try:
f(*args, **kw)
try_in(checkback_time, retry, [checkback_time, args, kw])
finally:
pass
def retry(delay, args, kw):
View gist:3153362
val logs: List[String] = aLotOfStrings
logs.map(_.takeWhile(_ != ' ')).grouped(8).count(_.contains("ERROR"))
@rcoh
rcoh / gist:3153369
Created Jul 20, 2012
view vs. non view
View gist:3153369
def nonview = (1 to 5000000).map(_ % 10).filter(_ > 5).reduce(_ + _)
def view = (1 to 5000000).view.map(_ % 10).filter(_ > 5).reduce(_ + _)
@rcoh
rcoh / gist:3153394
Created Jul 20, 2012
while loop counting
View gist:3153394
var i,j,k = 0
var x = 0L
while(i < 10000) {
while(j < 1000) {
while(k < 1000) {
x += 1
k += 1
}
k = 0;
j += 1
@rcoh
rcoh / gist:3153431
Created Jul 20, 2012
Scala for loop
View gist:3153431
var x = 0L
for(i <- 0 to 10000; j <- 0 to 1000; k <- 0 to 1000) {
x += 1
}
View count.scala
(1 until 1000).count(_ % 10 == 0)
@rcoh
rcoh / count2.scala
Created Jul 20, 2012
count java style
View count2.scala
var x = 1
var num = 0
while(x < 1000) {
if(x % 10 == 0) { num += 1 }
x += 1
}
@rcoh
rcoh / funcexample.scala
Created Jul 20, 2012
functional example
View funcexample.scala
(1 to 10) map (_ + 5) map (_ * 2)
View lazymap.scala
logs.view.map(_.takeWhile(_ != ' ')).grouped(8).count(_.contains("ERROR"))
You can’t perform that action at this time.