Skip to content

Instantly share code, notes, and snippets.

View apruden's full-sized avatar

Alex Prudencio apruden

View GitHub Profile
@Grapes([
@Grab('org.gebish:geb-core:0.12.0'),
@Grab('org.seleniumhq.selenium:selenium-htmlunit-driver:2.45.0'),
@Grab('org.seleniumhq.selenium:selenium-support:2.45.0')
])
import geb.Browser
import org.openqa.selenium.htmlunit.HtmlUnitDriver
def browser = new Browser(driver: new HtmlUnitDriver())
@apruden
apruden / Outline.scala
Last active February 13, 2019 04:26
fictional document management system - outline
case class Heading(weight: Int, text: String)
case class Node(heading: Heading, children: List[Node])
/** Converts a list of input headings into nested nodes */
def toOutline(headings: List[Heading]): Node = {
def buildNodes(input: List[Heading]): List[Node] = input match {
case Nil => Nil
case head :: Nil => Node(head, Nil) :: Nil
case head +: tail =>
tail.splitAt(tail.indexWhere(head.weight == _.weight)) match {
@apruden
apruden / introrx.md
Created February 15, 2017 19:15 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@apruden
apruden / geo_location.py
Last active February 11, 2016 03:11
geo location distance
import sys, math
def get_bin(lat, lng):
'''bin position'''
lat = max(0, lat + 70) if lat < 0 else min(140, lat + 70)
lng = lng + 180
return int(2 * lat) + 280 * int(2 * lng)
@apruden
apruden / gist:c7655738acb244e1a3d3
Created December 11, 2014 02:52
Monad Transformers
case class Reader[C, A](g: C => A) {
def apply(c: C) = g(c)
def map[B](f: A => B): Reader[C, B] =
(c:C) => f(g(c))
def flatMap[B](f: A => Reader[C, B]): Reader[C, B] =
(c:C) => f(g(c))(c)
}
object Reader {
implicit def Reader[A,B](f: A => B): Reader[A,B] = Reader(f)