Skip to content

Instantly share code, notes, and snippets.

@philwills
philwills / till-suffix.scala
Created December 5, 2016 17:08
Everything except a suffix in fastparse
import fastparse.all._
val suffix = P(" end" ~ End)
val parser = P((!suffix ~ AnyChar).rep.! ~ suffix)
parser.parse("start end")
// fastparse.core.Parsed[String,Char,String] = Success(start,9)
parser.parse("start end ")
// fastparse.core.Parsed[String,Char,String] = Failure(" end":1:11 ..."")

Keybase proof

I hereby claim:

  • I am philwills on github.
  • I am philwills (https://keybase.io/philwills) on keybase.
  • I have a public key whose fingerprint is 47AC FD1A CFE0 1E18 EEED 0C84 7381 F340 9657 C301

To claim this, I am signing this object:

@philwills
philwills / install-apache-zeppelin-on-amazon-emr.sh
Last active October 6, 2015 08:03 — forked from andershammar/install-apache-zeppelin-on-amazon-emr.sh
Bootstrap script for installing Apache Zeppelin on an Amazon EMR Cluster.
#!/bin/bash -ex
# Install Git
sudo yum -y install git
# Install Maven
wget -P /tmp http://apache.mirrors.spacedump.net/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz
sudo mkdir /opt/apache-maven
sudo tar -xvzf /tmp/apache-maven-3.3.3-bin.tar.gz -C /opt/apache-maven
@philwills
philwills / gist:687dc61388385568c86a
Created February 9, 2015 21:22
Sequencing Either
package ophan
object Or {
type Or[T] = Either[String, T]
def traverse[A,B](seq: Seq[Or[A]])(f: A => B): Or[Seq[B]] = {
seq.foldLeft[Or[Seq[B]]](Right(Nil)) { (acc, or) =>
or match {
case Left(s) => Left[String, Seq[B]](s)
case Right(a) => acc.right.map(_ :+ f(a))
@philwills
philwills / react-bootstrap-table-in-panel.html
Created February 5, 2015 15:26
react-bootstrap-table-in-panel
<html>
<head>
<title>React Bootstrap issue - basic bootstrap</title>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script
@philwills
philwills / poor-mans-match.scala
Created August 20, 2012 20:23
Pointless re-implementation of match
// I wanted to push my knowledge of PartialFunctions,
// so this seemed fun in a twisted way
// It doesn't do static exhaustiveness checking and is
// probably hideously inefficient, but it was lots of fun
class Matchable[A](item: A) {
def poorMansMatch[B](pfs: PartialFunction[A,B]*) = {
val composition = pfs.reduceLeft(_ orElse _)
if (composition.isDefinedAt(item)) composition(item)
@philwills
philwills / FailingNumberFinder.scala
Created August 12, 2011 17:28
Stream example gist
object FailingNumberFinder {
def findMagicNumber(numbers: Seq[Int]) : Option[Int] = {
for(number <- numbers) {
try {
return Some(SlowErrorProne.search(number))
} catch {
case _ =>
}
}
return None