Skip to content

Instantly share code, notes, and snippets.

View evantill's full-sized avatar

Eric Vantillard evantill

View GitHub Profile
import scalaz._, Scalaz._, NonEmptyList._
sealed trait Interval[+A] {
val min: A
val max: A
def map[B: Order](f: A => B): Interval[B] =
Interval(f(min), f(max))
def merge[AA >: A](i: Interval[AA])(implicit E: Enum[AA]): Option[Interval[AA]] =
import annotation.implicitNotFound
@implicitNotFound(msg = "This message can never appear!")
trait ~>[A, B] { self =>
def apply(a: A): B
def invert(b: B): A = inverse.apply(b)
def inverse: B ~> A = new ~>[B,A] {
def apply(b: B) = self.invert(b)
override def invert(a: A) = self(a)
}
@ayosec
ayosec / CORSDirectives.scala
Created December 18, 2012 03:28
CORS with Spray
package foo.bar
import spray.routing._
import spray.http._
import spray.http.StatusCodes.Forbidden
// See https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
case class Origin(origin: String) extends HttpHeader {
@alecthegeek
alecthegeek / fixgitprompt.sh
Created August 21, 2012 05:09
Fix for Git Prompt in Homebrew
# Upgraded git using Homebrew and now your __git_ps1() fails. Try something like this
# NB Still very fragile as had embedded version no
# enable git programmable completion features
if [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
. /usr/local/etc/bash_completion.d/git-completion.bash
fi
# enable git prompt
@tobiash
tobiash / categorypages.plugin.coffee
Created May 17, 2012 16:44
Dynamically generate pages for Docpad (from categories)
path = require 'path'
fs = require 'fs'
balUtil = require 'bal-util'
Backbone = require 'backbone'
module.exports = (BasePlugin) ->
class Category extends Backbone.Model
constructor: ->
@rodionmoiseev
rodionmoiseev / gist:2484934
Created April 25, 2012 00:41
Setting up Play 2.0 in build.gradle
apply plugin: 'java'
apply plugin: 'scala'
// For those using Eclipse or IntelliJ IDEA
apply plugin: 'eclipse'
apply plugin: 'idea'
def findPlay20(){
def pathEnvName = ['PATH', 'Path'].find{ System.getenv()[it] != null }
for(path in System.getenv()[pathEnvName].split(File.pathSeparator)){
for(playExec in ['play.bat', 'play.sh', 'play']){
@stuarthalloway
stuarthalloway / gist:2321773
Created April 6, 2012 18:15
Datomic schema query, constrained by attribute namespace
;; Datomic sample code
;; schema query for attribute types in specified namespaces
(q '[:find ?attr
:in $ [?include-ns ...] ;; bind ?include-ns once for each item in collection
:where
[?e :db/valueType] ;; all schema types (must have a valueType)
[?e :db/ident ?attr] ;; schema type name
[(datomic.Util/namespace ?attr) ?ns] ;; namespace of name
[(= ?ns ?include-ns)]] ;; must match one of the ?include-ns
@relrod
relrod / gist:1736528
Created February 4, 2012 09:00
SBT Install Script for Linux
# bash < <(curl -L http://da.gd/sbtinstall)
# Or, of course:
# bash < <(curl https://raw.github.com/gist/1736528/e9e978c81cc1f8a550973151d3922eede4c9b12a/gistfile1.sh)
mkdir -pv ~/bin/
curl -o ~/bin/sbt-launch.jar http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar
echo 'java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"' > ~/bin/sbt
chmod u+x ~/bin/sbt
echo 'Make sure ~/bin/ is in your $PATH and that you have a working `java` command.'
echo '* DONE *'
@cee-dub
cee-dub / dnsmasq.conf
Created January 14, 2012 23:23
Generic configuration files for *.#{hostname}.local wildcard DNS with dnsmasq and mDNSResponder
# Add domains for which you want to force to an IP address here.
# This is the magic sauce for making *.#{hostname}
# always route to the localhost
address=/#{hostname}/127.0.0.1
address=/#{hostname}/::1
mx-host=#{hostname},#{hostname},10
# Extra options that make dnsmasq play nice
log-queries