Skip to content

Instantly share code, notes, and snippets.

View ahoy-jon's full-sized avatar
🐋
Thinking!

Jonathan Winandy ahoy-jon

🐋
Thinking!
View GitHub Profile
@ahoy-jon
ahoy-jon / gist:3775129
Created September 24, 2012 09:35
isBalanced
def balance(chars: List[Char]): Boolean = {
@scala.annotation.tailrec
def balance(chars: List[Char], stack:List[Unit]): Boolean = (chars, stack) match {
case (Nil , Nil) => true
case (Nil , _ ) => false
case (')':: _, Nil) => false
case (head::tail, stack) => head match {
case '(' => balance(tail, () :: stack)
case ')' => balance(tail, stack.tail )
case _ => balance(tail, stack )
import language.dynamics
case class DynamicDuke(prefix:String = "") extends Dynamic {
def apply(s:String) = DynamicDuke(prefix + s)
def selectDynamic(method:String) = DynamicDuke(prefix + " " + method)
def applyDynamic(method:String) = selectDynamic(method)
}
val duke = DynamicDuke()
import TypeConverter._
import ParserCSV._
import scalaz._
import Scalaz._
val csvReaderAhoy = readCSV("./csv/ahoy.txt")
case class Personne(nom:String, prenom:String, age:Option[Int])
csvReaderAhoy(line => ^(line.nom.s,line.prenom.s,line.age.to[Option[Int]])(Personne)) //Iterator
csvReaderAhoy(line => ^(line.nom.s,line.prenom.s,line.age.to[Option[Int]])(Personne)).toList //List[ValidationNEL[String,Personne]]
@ahoy-jon
ahoy-jon / gist:4079924
Created November 15, 2012 17:25
implicit !
case class ImplicitInject[I,B,C](f: (I,B) => C) {
def apply(b:B)(implicit i:I):C = f(i,b)
//def i(b:B)(implicit i:I):C = f(i,b) // it could be "explicit"
}
object ImplicitInject {
implicit val a:Int = 1
object GOL extends App {
type Cell = (Int,Int)
type Step = List[Cell]
lazy val motifvoisinage:Step = {
val iii = (-1 to 1)
iii.flatMap(x => iii.map( _ -> x)).filter(_ != (0,0)).toList
}
def add(c1:Cell, c2:Cell):Cell = (c1._1 + c2._1, c2._2 + c1._2)
trait Closable[A] {
def closable(a:A):Unit
}
object Ahoy extends App {
implicit def closable[A <: {def close:Unit}] = new Closable[A] {
def closable(a:A) {a.close}
}
"@context": {
"@comment": "Generic term for blog in RDF and JSON/LD",
"wikia": "http://data.wikia.com/terms#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"@vocab": "http://example.org/myblog#",
"date": {
"@type": "xsd:dateTime"
},
"email": {
"@type": "xsd:email"
object SomeHelper {
implicit def lazyFunc[A,B](f: A=> B): ((=> A) => B) = a => f(a)
}
object MyApp extends App {
import SomeHelper._
val m = new SomeFunctor(1)
context.Expr(
Apply(
Apply(
Select(suite.tree, newTermName("testPublic"))
, List(testName.tree)
)
, List(testFun.tree)
)
)
@ahoy-jon
ahoy-jon / tron.bot.clj
Last active December 17, 2015 13:39 — forked from cgrand/tron.bot.clj
;the bot is tron.bots.ahoy/turn-based-strat
(ns tron.bots.ahoy
(:require [tron.core :as tron]))