Skip to content

Instantly share code, notes, and snippets.

class MyArgs extends EnvArgs with SQLArgs {
//add extra app args here...
}
class MyArgs {
@Required
var db1: SQLArgs = new SQLArgs {}
@Required
var db2: SQLArgs = new SQLArgs {}
}
@Mortimerp9
Mortimerp9 / MonoidRange.scala
Last active August 29, 2015 14:03
Create ranges from any monoid in scala (with Algebird Monoid)
object MonoidRange {
case class MonoidRangeBuilder[T](from: T, to: T, incl: Boolean)(implicit mo: Monoid[T], ordering: Ordering[T]) {
def by(step: T) = Stream.iterate(from) { previous: T =>
previous + step
}.takeWhile { x =>
if (incl) {
ordering.lteq(x, to)
} else {
ordering.lt(x, to)
@Mortimerp9
Mortimerp9 / gist:365fd4f306b70b2570e6
Created July 14, 2014 18:42
toSet vs distinct in scala

you should probably use distinct instead of toSet:

scala> th.pbenchOff()((1 to 1000).toSet.size)((1 to 1000).distinct.size)
Benchmark comparison (in 23.17 s)
Significantly different (p ~= 0)
  Time ratio:    0.43815   95% CI 0.42991 - 0.44639   (n=20)
 First 125.6 us 95% CI 124.0 us - 127.2 us
@Mortimerp9
Mortimerp9 / divergingcolors.r
Last active August 29, 2015 14:04
diverging color schemes for negative and positive numbers in R
library(RColorBrewer)
colPos<-colorRampPalette(brewer.pal(9, "YlGn")[3:9])(100)
colNeg<-colorRampPalette(brewer.pal(9, "OrRd")[3:9])(100)
foo <- function(diff, bin) {
if(diff>=0) colPos[bin] else colNeg[bin]
}
mat$diff <- mat$x-mat$y
mat$bin <- cut(log10(abs(mat$diff)+1),100, labels=seq(1,100))
mat$col <- mapply(foo, mat$diff, mat$bin)
@Mortimerp9
Mortimerp9 / RichConfigString.scala
Created August 27, 2014 17:41
Smarter rich ConfigString to wrap Typesafe Config in Scala
import com.typesafe.config.Config
import scala.util.Try
import scala.concurrent.duration.FiniteDuration
/**
* Some scala wrapper around the typesafe Config object to write configuration in the format:
* "host.defaults" configOrElse List("173.208.36.96:8800", "69.162.159.99:8800", "173.208.36.55:8800")
*
* The key is given as a string and `configOrElse` tries to get it from the configuration and guess the right type
* based on the default fallback type.
@Mortimerp9
Mortimerp9 / keybase.md
Created May 11, 2015 16:46
Keybase proof

Keybase proof

I hereby claim:

  • I am mortimerp9 on github.
  • I am mortimer (https://keybase.io/mortimer) on keybase.
  • I have a public key whose fingerprint is BC13 E225 8D86 2CAB 6A1D DA1C B532 8844 EF4E 808F

To claim this, I am signing this object:

@Mortimerp9
Mortimerp9 / scales.js
Created May 30, 2015 05:09
Scales in javascript - d3 inspired
'use strict';
module.exports = (function() {
var linear = function(domain, range) {
var d0 = domain[0], r0 = range[0], multipler = ( range[1] - r0 ) / ( domain[1] - d0 );
return function ( num ) {
return r0 + ( ( num - d0 ) * multipler );
};
}
@Mortimerp9
Mortimerp9 / batch.js
Created September 1, 2015 23:08
batch queue calls with javscript
function batch(cb, maxSize, timeout) {
var queue = [];
var timer;
var flushQueue = function() {
cb(queue);
queue = [];
};
return function enQueue(msg) {
@Mortimerp9
Mortimerp9 / rgbafallback.pl
Created November 8, 2012 02:08
This is a very rough perl script that will go through a css file and find the possible rgba statements, it will then insert a fallback hex value before the rgba statement. As this was tailored to a particular use case, it only deals with background color
#!/usr/bin/perl
use strict;
sub min {
my ($a, $b) = @_;
if($a < $b) { return $a; }
else { return $b; }
}