Skip to content

Instantly share code, notes, and snippets.

View rcoh's full-sized avatar

Russell Cohen rcoh

View GitHub Profile
@rcoh
rcoh / gist:1390585
Created November 24, 2011 03:46
fancy decorator
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):
@rcoh
rcoh / gist:3153345
Created July 20, 2012 21:25
Scala list
List(1, 2, 3)
@rcoh
rcoh / gist:3153362
Created July 20, 2012 21:27
Nonlazy Map
val logs: List[String] = aLotOfStrings
logs.map(_.takeWhile(_ != ' ')).grouped(8).count(_.contains("ERROR"))
@rcoh
rcoh / gist:3153369
Created July 20, 2012 21:29
view vs. non view
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 July 20, 2012 21:34
while loop counting
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 July 20, 2012 21:41
Scala for loop
var x = 0L
for(i <- 0 to 10000; j <- 0 to 1000; k <- 0 to 1000) {
x += 1
}
@rcoh
rcoh / count.scala
Created July 20, 2012 21:43
Scala count
(1 until 1000).count(_ % 10 == 0)
@rcoh
rcoh / count2.scala
Created July 20, 2012 21:44
count java style
var x = 1
var num = 0
while(x < 1000) {
if(x % 10 == 0) { num += 1 }
x += 1
}
@rcoh
rcoh / funcexample.scala
Created July 20, 2012 22:21
functional example
(1 to 10) map (_ + 5) map (_ * 2)
logs.view.map(_.takeWhile(_ != ' ')).grouped(8).count(_.contains("ERROR"))