Skip to content

Instantly share code, notes, and snippets.

@nafg
nafg / gist:8729695
Created January 31, 2014 10:24
routing issue
// git clone git@github.com:nafg/reactive.git
// git checkout v0.4.0
// sbt routing/console
import reactive.routing._
implicit object IntArg extends Stringable[Int] { def format = _.toString; def parse = s => util.Try(s.toInt).toOption }
implicit object StringArg extends Stringable[String] { def format = identity; def parse = Option(_) }
val a = arg[Int] >> { i => i.toString }
val b = arg[String] >> { s => s }
@nafg
nafg / MintByDate.html
Created April 9, 2014 20:22 — forked from anonymous/MintByDate.html
View Mint transactions within a date range
<!DOCTYPE html>
<html><body>
<h1>Show Mint transactions within date range</h1>
<form action="https://wwws.mint.com/transaction.event" target="_blank" method="get">
<input type="date" id="s" onchange="document.getElementById('sd').value=this.value.replace(/(\d+)-(\d+)-(\d+)/,'$2/$3/$1')"/>
to
<input type="date" id="e" onchange="document.getElementById('ed').value=this.value.replace(/(\d+)-(\d+)-(\d+)/,'$2/$3/$1')"/>
<input type="hidden" name="startDate" id="sd"/><input type="hidden" name="endDate" id="ed"/>
<input type="submit"/>
</form>
@nafg
nafg / gist:e8af2dc665da77e9e6ba
Last active August 29, 2015 14:03
Limitless Applicative builder
trait ApType {
import scala.language.higherKinds
type FS[+Z]
}
trait ApTypeOne[A] extends ApType {
type FS[+Z] = A => Z
}
trait ApTypeMore[A, N <: ApType] extends ApType {
type FS[+Z] = A => N#FS[Z]
}
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.mutable.{ArrayBuffer, SynchronizedBuffer}
import scala.concurrent.{ExecutionContext, Future}
import scala.xml.Elem
import reactive.{Observing, Subscription}
import reactive.Applicative.ApType
import reactive.web.Page
function dev --argument q
find ~/dev -name '.git' | xargs dirname | begin
peco --query=$q
or return
end | read d
cd $d
end
@nafg
nafg / update-idea-quicklist.scala
Created September 2, 2014 09:44
Put IntelliJ projects in .desktop jumplist
import java.nio.file._
import java.nio.file.attribute.BasicFileAttributes
import scala.collection.convert.decorateAsJava._
val ideaFile = "/home/naftoli/.local/share/applications/jetbrains-idea-ce.desktop"
val file = io.Source.fromFile(ideaFile)
case class Section(head: Option[String], entries: Seq[Either[String, (String, String)]]) {
@nafg
nafg / Producer.scala
Last active August 29, 2015 14:21
One attempt at taming css bound forms without tons of (X => Unit)s
trait Produce { self =>
type F[R]
def runWith(f: =>F[Unit]): CssSel
protected[lrbcol] def combineFunc[R](f: F[R]): (R => Unit) => CssSel
def combine[R](f: F[R]) = new ProduceOne(new Binding(combineFunc(f)))
}
class Binding[A, T](val func: (A => Unit) => T) {
var realHandler: () => A => Unit = null
private val closure: A => Unit = a => realHandler()(a)
val result = func(closure)
@nafg
nafg / Producers.scala
Created May 20, 2015 03:01
A different attempt at taming css bound forms without tons of (X => Unit)s
package lrbcol.misc
import scala.xml._
import scala.concurrent._
import net.liftweb.http._
import net.liftweb.util.{ A => _, _ }
import net.liftweb.util.Helpers._
@nafg
nafg / MultiMap.scala
Created June 3, 2015 18:11
Immutable multimap via implicit class
implicit class MultiMap[K, V](map: Map[K, Set[V]]) {
def addBinding(k: K, v: V) = addBindings(k, Set(v))
def addBindings(k: K, vs: Set[V]) = map.get(k) match {
case None => map + (k -> vs)
case Some(xs) => map + (k -> (vs ++ xs))
}
def removeBinding(k: K, v: V) = map.get(k) match {
case None => map
@nafg
nafg / ClassWithDependency.csx
Last active August 29, 2015 14:27 — forked from mikehadlow/ClassWithDependency.csx
C#: Only Use Static Methods
public class Thing : IThing
{
public Thing(IDependency dependency) { }
public void Do(string arg) { }
}