This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import pandas as pd | |
import itertools | |
def query_driver(job, fname = False): | |
""" | |
Submits a Hive query on the gateway machine. You will still need to log in | |
enter your kerberos credentials in another ssh window prior to running. | |
Hive query can be in the form of a raw string or the path to a script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lift[A,B](f: A =>B): Option[A] => Option[B] = _ map f | |
lift(math.abs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type predicate[A] = A => Boolean | |
def exists[A](ls: List[A], p: A => Boolean): Boolean = { | |
ls match { | |
case x :: xs => p(x) || exists(xs,p) | |
case _ => false | |
} | |
} | |
def exists2[A](ls: List[A], p: predicate[A]): Boolean = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "Simple Project" | |
version := "1.0" | |
libraryDependencies += "edu.stanford.nlp" % "stanford-corenlp" % "3.3.0" | |
libraryDependencies += "edu.stanford.nlp" % "stanford-corenlp" % "3.3.0" classifier "models" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.reddit.com/r/dailyprogrammer/comments/pnhtj/2132012_challenge_5_intermediate/ | |
import scala.io.Source | |
val wordList = Source.fromURL("http://www.joereynoldsaudio.com/enable1.txt").getLines() | |
def findAnagrams(words: Iterator[String]) = { | |
val dd = words.foldLeft(Map.empty[String, List[String]]) { | |
case (acc, x) => acc + (x.sorted -> (x :: acc.getOrElse(x.sorted,Nil))) | |
}.values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//print a histogram | |
import scala.util.Random | |
import scala.annotation.tailrec | |
def twoDice(): Int = { | |
val r1 = Random | |
(r1.nextInt(6)+1) + (r1.nextInt(6) +1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooParamsMixin(object): | |
param1 = luigi.Parameter() | |
param2 = luigi.Parameter() | |
... | |
def foo_params(self): | |
return { 'param1': self.param1, 'param2' : self.param2, ... } | |
class TaskA(FooParamsMixin, luigi.Task): | |
def requires(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import scala.io.Source | |
def getFileTree(f: File): Stream[File] = | |
f #:: (if (f.isDirectory) f.listFiles().toStream.flatMap(getFileTree) | |
else Stream.empty) | |
def createIndex(path: String): Map[String, Set[String]] = { | |
val f = new File(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//p08 | |
def compress[A](xs: List[A]): List[A] = | |
xs match { | |
case x :: xs if (!xs.contains(x)) => x :: compress(xs) | |
case x :: xs => compress(xs) | |
case Nil => Nil | |
} | |
def compress2[A](xs: List[A]): List[A] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaj.http | |
val x = Http("http://en.wikipedia.org/wiki/Adolf_Hitler").option(_.setInstanceFollowRedirects(true)).asString |
OlderNewer