Skip to content

Instantly share code, notes, and snippets.

@stew
stew / getopt_stew.scala
Created June 3, 2013 04:23
this is how I would have refactored
import scalaz.ValidationNel
import scalaz.syntax.traverse._
import scalaz.syntax.validation._
import scalaz.std.list._
sealed trait GetOptError
case object UnknownArgument extends GetOptError
case object EmptyElement extends GetOptError
private def parseArguments(i: Int, element: String): List[ValidationNel[GetOptError, (Char, Option[String])]] =
public java.lang.String foo(scala.Option<java.lang.String>);
Code:
0: aload_1
1: astore_2
2: aload_2
3: instanceof #16 // class scala/Some
6: ifeq 34
9: aload_2
10: checkcast #16 // class scala/Some
13: astore_3
@stew
stew / FSE.scala
Last active December 18, 2015 08:19
import scalaz._
import Scalaz._
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.Await
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
object FSE extends App {
// scalaz doesn't yet have a monad instance for future, here is one.
#!/usr/bin/env bash
#
# A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>
# todo - make this dynamic
declare -r sbt_release_version=0.12.3
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
unset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
diff --git a/dist/lib/swagger.js b/dist/lib/swagger.js
index 0905b64..291215b 100644
--- a/dist/lib/swagger.js
+++ b/dist/lib/swagger.js
@@ -56,16 +56,16 @@
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
- if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
- _this.basePath = response.basePath;
@stew
stew / UnapplyMT.scala
Last active December 19, 2015 20:58
I wrote an Unapply for MonadTrans instances which would catch both things like OptionT[M[_],A] and EitherT[M[_], A, B], then couldn't remember what I was trying to solve by doing it. so I'll just stick it here for now
trait UnapplyMT[TC[_[_[_], _]], N[_], MTNA] {
/** the type constructor */
type MT[_[_], _]
/** The type that MT is applied to */
type A
/** The instance of the type class */
def TC: TC[MT]
@stew
stew / scala-arrows.el
Created August 4, 2013 00:35
Fancy unicode arrows for emacs scala-mode. Done this way because I don't think it can work as an abbrev.
(defun right-arrow ()
(interactive)
(cond ((looking-back "=")
(backward-delete-char 1) (insert "⇒"))
((looking-back "-")
(backward-delete-char 1) (insert "→"))
(t (insert ">"))))
(defun left-arrow ()
(interactive)
scala> val f : Int => List[Int] = List(_)
f: Int => List[Int] = <function1>
scala> Stream(1,2,3) traverse f
res1: List[scala.collection.immutable.Stream[Int]] = List(Stream(1, ?))
@stew
stew / scala.el
Created September 3, 2013 14:44
; 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,
@stew
stew / gist:7222113
Created October 29, 2013 20:34
spire example fail
[debug] Waiting for thread run-main to exit
[error] (run-main) java.lang.AbstractMethodError: spire.example.RandomForestExample$$anonfun$1.apply(Ljava/lang/Object;)Ljava/lang/Object;
java.lang.AbstractMethodError: spire.example.RandomForestExample$$anonfun$1.apply(Ljava/lang/Object;)Ljava/lang/Object;
at spire.example.CrossValidation$.loop$1(DataSets.scala:234)
at spire.example.CrossValidation$.crossValidate(DataSets.scala:242)
at spire.example.CrossValidation$.crossValidateClassification(DataSets.scala:259)
at spire.example.RandomForestExample$.testClassification(randomforest.scala:40)
at spire.example.RandomForestExample$delayedInit$body.apply(randomforest.scala:24)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)