Skip to content

Instantly share code, notes, and snippets.

View wrobstory's full-sized avatar

Rob Story wrobstory

View GitHub Profile
@wrobstory
wrobstory / gist:bc7636e3254ca733f2d8
Created March 17, 2015 23:13
Py.test Fixture error
import pytest
def setup_function(function):
foo = 1
function(foo)
def test_thing(thing):
two = thing + 1
assert two == 2
@wrobstory
wrobstory / gist:79872b94f0d7bf1720f1
Last active August 29, 2015 14:16
Scala/Java ConcurrentHashMap
scala> val mymap = new ConcurrentHashMap[String, Int]
mymap: java.util.concurrent.ConcurrentHashMap[String,Int] = {}
scala> mymap.put("one", 1)
res8: Int = 0
scala> mymap.put("zero", 0)
res9: Int = 0
scala> mymap.get("one")
from random import gauss
from IPython.display import clear_output
from IPython.html import widgets
from IPython.utils.traitlets import link
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
@wrobstory
wrobstory / gist:1398260581236e20dfa3
Last active August 29, 2015 14:16
Widget trait events
from IPython.html import widgets
toggle = widgets.ToggleButton()
def foo():
if toggle.value is True:
print("The Toggle is True!")
else:
print("The Toggle is False!")
toggle.on_trait_change(foo)
display(toggle)
@wrobstory
wrobstory / gist:47d0c8a6aa76d127c7d3
Created February 27, 2015 01:05
World's Most Advanced Type System
scala> val listOfTuples = List(("one", Map("foo" -> 1, "bar" -> 2)),
| ("two", Map("baz" -> 3, "qux" -> 4)),
| ("three", Map()))
listOfTuples: List[(String, scala.collection.immutable.Map[_ <: String, Int])] = List((one,Map(foo -> 1, bar -> 2)), (two,Map(baz -> 3, qux -> 4)), (three,Map()))
scala> val thirdTuple = listOfTuples(2)
thirdTuple: (String, scala.collection.immutable.Map[_ <: String, Int]) = (three,Map())
scala> val thirdTupleMap = thirdTuple._2
thirdTupleMap: scala.collection.immutable.Map[_ <: String, Int] = Map()
@wrobstory
wrobstory / gist:09494d12aa117d4ed320
Created February 27, 2015 00:47
Scala getOrElse BS
scala> val foo = Map("one" -> "two")
foo: scala.collection.immutable.Map[String,String] = Map(one -> two)
scala> foo.getOrElse("nokey", None)
res67: java.io.Serializable = None
scala> foo.getOrElse("nokey", null)
res68: String = null
scala> val fooList: List[String] = List()
fooList: List[String] = List()
scala> foo :+ "one"
res117: List[String] = List(one)
scala> foo +: "one"
res118: scala.collection.immutable.IndexedSeq[Any] = Vector(List(), o, n, e)
@wrobstory
wrobstory / gist:d59490da0d86d0973709
Created February 18, 2015 03:40
Matplotlib Wheel
Robs-MacBook-Pro:WASKOMDROOLS robstory$ virtualenv .env
New python executable in .env/bin/python2.7
Also creating executable in .env/bin/python
Installing setuptools, pip...done.
Robs-MacBook-Pro:WASKOMDROOLS robstory$ source .env/bin/activate
(.env)Robs-MacBook-Pro:WASKOMDROOLS robstory$ pip install matplotlib
Downloading/unpacking matplotlib
Downloading matplotlib-1.4.3-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (47.6MB): 47.6MB downloaded
Downloading/unpacking nose>=0.11.1 (from matplotlib)
Downloading nose-1.3.4-py2-none-any.whl (154kB): 154kB downloaded
In [60]: df = pd.DataFrame({"foo": [1, 2], "bar": [3, 4]})
In [61]: df.rename({"foo": "foo_1", "bar": "bar_1"})
Out[61]:
bar foo
0 3 1
1 4 2
In [62]: df.rename(columns={"foo": "foo_1", "bar": "bar_1"})
Out[62]:
@wrobstory
wrobstory / gist:35ea4eb1bae8ebdee0b5
Created February 5, 2015 00:47
Scala Queue Take
scala> import scala.collection.mutable.Queue
import scala.collection.mutable.Queue
scala> var newQ = Queue(1, 2, 3, 4, 5)
newQ: scala.collection.mutable.Queue[Int] = Queue(1, 2, 3, 4, 5)
scala> newQ.take(3)
res0: scala.collection.mutable.Queue[Int] = Queue(1, 2, 3)
scala> newQ