Skip to content

Instantly share code, notes, and snippets.

View wrobstory's full-sized avatar

Rob Story wrobstory

View GitHub Profile
@wrobstory
wrobstory / redshift.sql
Created November 5, 2014 16:53
Redshift debugging queries
-- Gets all queries for a given date range
select starttime, endtime, trim(querytxt) as query
from stl_query
where starttime between '2014-11-04' and '2014-11-05'
order by starttime desc;
-- Gets all queries that have been aborted for a given date range
select starttime, endtime, trim(querytxt) as query, aborted
from stl_query
where aborted=1
@wrobstory
wrobstory / gist:a501e1ff81bd026b46ac
Last active August 29, 2015 14:08
Type safety!
scala> val foo = Map("one" -> List("one", "two"))
foo: scala.collection.immutable.Map[String,List[String]] = Map(one -> List(one, two))
scala> foo.get("one").asInstanceOf[Option[Int]]
res1: Option[Int] = Some(List(one, two))
scala> val bar:Option[Int] = Some(List("one", "two"))
<console>:7: error: type mismatch;
found : List[String]
required: Int
@wrobstory
wrobstory / gist:02aba72adfe6f279e160
Created November 3, 2014 18:50
Get & GetOrElse
// I don't find this behavior remarkably consistent
scala> foo.get("one")
res0: Option[Int] = Some(1)
scala> foo.getOrElse("one", 2)
res1: Int = 1
scala> foo.getOrElse("two", 2)
res2: Int = 2
@wrobstory
wrobstory / gist:31734bc2ef4b5f4c4048
Last active August 29, 2015 14:08
Polymorphism?
In [1]: 1 + 1
Out[1]: 2
In [2]: 1 + 1.0
Out[2]: 2.0
In [3]: 1 + "string"
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-d295ea69933a> in <module>()
@wrobstory
wrobstory / gist:0c54b8a2ba1f5a81ba18
Last active August 29, 2015 14:07
This is a thing that worked and was necessary.
aux.get("amounts").asInstanceOf[Option[Map[String,Any]]].flatMap(_.get("originalAmount")).asInstanceOf[Option[Long]]
@wrobstory
wrobstory / gist:6e281004ae7d5bc35a4c
Created October 7, 2014 15:45
What even is Set
scala> List(1,2,3).toSet()
res23: Boolean = false
scala> List(1,2,3).toSet
res24: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
@wrobstory
wrobstory / gist:28ce5fecb3a11dcea564
Last active August 29, 2015 14:07
Higher Order Wat
def add(x: Int, y: Int = 1): Int = x + y
def transform(z: Int, transformer: (Int, Int) => Int): Int = transformer(z)
// Exiting paste mode, now interpreting.
<console>:9: error: not enough arguments for method apply: (v1: Int, v2: Int)Int in trait Function2.
Unspecified value parameter v2.
def transform(z: Int, transformer: (Int, Int) => Int): Int = transformer(z)
@wrobstory
wrobstory / malortapi.py
Last active August 29, 2015 14:06
Malort API
stats = malort.run('mydir/files', delimiter='|')
redshift_suggestions = malort.get_redshift_types(stats)
df = malort.get_dataframe(stats)
# OR
result = malort.run('mydir/files', delimiter='|')
redshift_suggestions = result.get_redshift_types()
df = result.get_dataframe()
class YoDawg(FacetGrid):
"""I got facets in your facets"""
def __init__(args, kwargs)
super(YoDawg, self).__init__(*args, **kwargs)
@wrobstory
wrobstory / gist:a352ff715d7c94042574
Created September 19, 2014 22:25
Scala pattern match
val vec1 = Vector(1, 2, 3)
val vec2 = Vector(3, 4, 5, 6, 7, 8)
val vec3 = Vector("foo", "bar", "baz")
val vec4 = Vector("one", Map("one" -> 1, "two" -> 2))
def match_vec(vec: Vector[Any]) {
vec match {
case Vector(_, _, 3) => println("Vector ends in 3!")
case Vector(3, _*) => println("Vector starts with three, has any number of elements!")
case Vector(_, "bar", _) => println("String Vector!")