Skip to content

Instantly share code, notes, and snippets.

View joescii's full-sized avatar

Joe Daniel Barnes joescii

  • Open to work
  • United States
View GitHub Profile
@joescii
joescii / gist:9336415
Created March 3, 2014 22:58
Some(null) sucks
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
class SomeNull extends FlatSpec with ShouldMatchers {
val o:Option[String] = Some(null)
"The option" should "not match Some(a)" in {
o match {
case Some(s) => s should not be (null)
case _ =>
@joescii
joescii / FileReaders.scala
Created March 27, 2014 10:40
Replicating Racket's file->lines
object FileReaders {
object file {
def ->(contents: Seq[String]) = contents
}
object lines {
def apply(path:String) = scala.io.Source.fromFile(path).getLines().toSeq
}
}
@joescii
joescii / IfBrowserIs
Created May 8, 2014 18:53
IE9 awareness in Lift
object IfBrowserIs {
def ie9 = if(S.request.map(_.isIE9).openOr(false)) PassThru else ClearNodes
}
@joescii
joescii / Script.scala
Last active August 29, 2015 14:01
Automatic asset versioning in Lift with sbt-js
package code.snippet
object Script {
def render(xhtml:NodeSeq):NodeSeq = attr("name").map { name =>
import config.BuildInfo.version
<script id={name+"_js"} src={s"/js/$name-$version.js"} type="text/javascript"></script>
} openOr xhtml
}
@joescii
joescii / Style.scala
Created May 9, 2014 02:57
Automatic asset versioning in Lift with sbt-less/sbt-sass
object Style {
def render(xhtml:NodeSeq):NodeSeq = attr("name").map { name =>
import config.BuildInfo.version
<link id={name+"_css"} href={s"/css/$name-$version.css"} rel="stylesheet"></link>
} openOr xhtml
}
@joescii
joescii / ImplicitSpecs.scala
Created October 23, 2014 20:42
The good, bad, and ugly of implicits with +
package com.joescii
import org.scalatest.{ShouldMatchers, FlatSpecLike}
/**
* Created by jbarnes on 10/23/2014.
*/
class ImplicitSpecs extends FlatSpecLike with ShouldMatchers {
"Scala implicits" should "act like their java counterparts" in {
val java = new MyJavaClass
@joescii
joescii / Traits.scala
Created April 6, 2015 15:58
Dynamic traits
trait Base
trait Child1 extends Base {
def method1:String = "method1"
}
trait Child2 extends Base {
def method2:String = "method2"
}
def coinFlip:Boolean = ???
val thing:String with Base = if(coinFlip) new String("str") with Child1
@joescii
joescii / Fun.purs
Created May 11, 2015 03:25
Unix-like piping DSL for purescript
module Fun where
import Data.Array (map, filter, (..))
-- Given an argument `a` applies the function `f`
(>>) :: forall a b. a -> (a -> b) -> b
(>>) a f = f a
infix 1 >>
-- Given functions `f` and `g`, composes to yield `g` of `f`
@joescii
joescii / install.sh
Created May 21, 2015 22:01
No ssh in rhel AMI created by Packer
#!/bin/bash -eux
sudo mv /tmp/symg /opt/symg
sudo echo "java -Dsymbol.generator.localhost=false -jar /opt/symg/symbol-generator.jar" >> /etc/rc.d/rc.local
bower check-new Checking for new versions of the project dependencies..
starter-kit C:\Users\jbarnes\code\intro-ps
├─┬ purescript-arrays#0.3.7 (latest is 0.4.0)
│ ├── purescript-control#0.2.6 (latest is 0.3.0)
│ └─┬ purescript-maybe#0.2.2 (latest is 0.3.1)
│ └── purescript-control#0.2.6
├─┬ purescript-bifunctors#0.4.0 extraneous
│ └── purescript-control#0.2.6 incompatible with ^0.3.0 (0.3.0 available)
├─┬ purescript-console#0.1.0 extraneous
│ └─┬ purescript-eff#0.1.0 extraneous