Skip to content

Instantly share code, notes, and snippets.

View r-wheeler's full-sized avatar

Ryan Wheeler r-wheeler

View GitHub Profile
@r-wheeler
r-wheeler / query_runner.py
Last active August 29, 2015 14:10
Python submit Hive Query
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
@r-wheeler
r-wheeler / lift.scala
Created December 9, 2014 16:06
Lifting a function to take option
def lift[A,B](f: A =>B): Option[A] => Option[B] = _ map f
lift(math.abs)
@r-wheeler
r-wheeler / funprog
Last active August 29, 2015 14:11
Scala Exists, forAll, takeWhile and simple fun with functions
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 = {
@r-wheeler
r-wheeler / build.sbt
Created December 23, 2014 20:11
build.sbt for stanford NLP
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"
@r-wheeler
r-wheeler / anagram.scala
Created January 11, 2015 00:21
DailyProgrammer[2/13/12] - Anagram
//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
@r-wheeler
r-wheeler / Hist.scala
Created January 11, 2015 07:03
DailyProgrammer[7/13/2012]
//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)
}
@r-wheeler
r-wheeler / luigi_params.py
Created January 16, 2015 15:13
Global Params for Luigi
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):
@r-wheeler
r-wheeler / fileToMap.scala
Created January 17, 2015 03:13
read a directory contents, parse the words in each file and store the result as a Map(word -> Set(documentName))
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)
@r-wheeler
r-wheeler / 99problems_8_12.scala
Created January 19, 2015 03:00
99 Scala (problems 8 - 12) answers
//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] = {
@r-wheeler
r-wheeler / http_request.scala
Created January 29, 2015 04:00
Scalaj http request
import scalaj.http
val x = Http("http://en.wikipedia.org/wiki/Adolf_Hitler").option(_.setInstanceFollowRedirects(true)).asString