Skip to content

Instantly share code, notes, and snippets.

View willf's full-sized avatar
✒️
pondering

Will Fitzgerald willf

✒️
pondering
View GitHub Profile
object SalaryWorld extends App {
val rules = Seq(
('allowance, 1.2),
('bonus, 1.1),
('tax, 0.7),
('surcharge, 0.9)
)
def salary(config: Set[Symbol], base: Double) =
object GOption {
def some[A](a: A): GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
def none[A]: GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
}
trait GOption[+A] {
def countMonotonicityBreaks(items: Seq[Int]): Int =
items.sliding(2). // two items at a time
filter(p => p.size == 2 && p(0) != p(1)). // remove any equalities
map{p => p(1).compare(p(0))}. // get -1 and 1 values; must have 2 values
sliding(2). // take *these* two at a time
count(p => p.size == 2 && p(0) != p(1)) // count when the differ
@willf
willf / ordering.scala
Last active December 20, 2015 03:29
arbitrary sort orderings using contramaps from scalaz (via Cody Allen)
import scalaz.Order
case class WeightedConcept(id: String, weight: Double)
val concepts = List(WeightedConcept("one", 1.0), WeightedConcept("two", 0.5))
val weightOrder: Order[WeightedConcept] = implicitly[Order[Double]].contramap[WeightedConcept](_.weight)
concepts.sorted(weightOrder.toScalaOrdering)
concepts.sorted(weightOrder.reverseOrder.toScalaOrdering)
@willf
willf / scala.el
Created September 3, 2013 14:51 — forked from stew/scala.el
; scala-mode2 found here: https://github.com/hvesalai/scala-mode2 is much better than the scala mode that comes with scalac
(add-to-list 'load-path "~/.emacs.d/scala-mode2/")
(require 'scala-mode)
; http://www.emacswiki.org/emacs/RainbowDelimiters
(add-hook 'scala-mode-hook 'rainbow-delimiters-mode)
; I get ensime from git:
; https://github.com/aemoncannon/ensime
; then run `sbt stage` inside the ensime source directory,
@willf
willf / genders.txt
Created February 14, 2014 01:45
Custom Genders in Facebook
Agender
Androgynous
Bigender
Cis Female
Cis Male
Cis Man
Cis Person
Cisgender
Cisgender Female
Cisgender Male
@willf
willf / student.scala
Created June 25, 2014 15:30
Simple Scala Student class
case class Student (fn: String, ln: String) {
def name() = s"$fn $ln"
def greet() = s"Hello, $name"
}
val s = Student("John", "Doe")
val l = List(s,s,s)
val res = l.map{_.name.length}.sum
package org.entish.montecarlo
import scala.util.Random
import System.{ currentTimeMillis  _time }
import com.nicta.rng._, scalaz._, Scalaz._

object Main extends App {

  def profile[R](code:  R, t: Long = _time, msg: String = "Profile") = (msg, code, _time - t)
@willf
willf / gist:5f36c2cfb8512acabb24
Created June 22, 2015 13:15
Simple elastic search calls
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.create(index="test", doc_type="articles", body={"content": "One more fox"})
res = es.search(index="test", doc_type="articles", body={"query": {"match": {"content": "fox"}}})
print("%d documents found" % res['hits']['total'])
for doc in res['hits']['hits']:
print("%s) %s" % (doc['_id'], doc['_source']['content']))
"@0xabad1dea I love the term \"Cutie Twitter\""
"@AccuRayno I love the term \"not as brutal\". I wonder what color it would be if the forecast was \"brutal\"?"
"@Ashton5SOS @Smallzy I love the word wallop!!"
"@CL_Hellisen @MindTheCurvesZA gorgeous! i love the expression, the pose!"
"@DannyNoriega danny i have like a major problem...i hate the word fag and my neighbor calls me\" gay spic fag boy\" what do i do? ps. i love u"
"@Gwenelope love the word Luddite. Almost as much as I love the words palimpsest and velvet #randomtweet"
"@JMamuds I love the term “organic mass”"
"@JamesTharpy24 I love the term meddler in the middle for TP. It more accurately described what we really do in our classroom."
"@Mikah_Clark Hello. Nerd. Also, I love the word abysmal and have been wanting to use it in a convo for like three days now. Deal."
"@NinBendo1 I hate the term, Christian. I am a follower of Christ. And He says to love EVERYONE. So, that is how I choose to live."