Skip to content

Instantly share code, notes, and snippets.

View sledorze's full-sized avatar

Stéphane Le Dorze sledorze

View GitHub Profile
@sledorze
sledorze / 960gs.less
Created September 21, 2011 19:48 — forked from Aeon/960gs.less
LessCSS and 960gs don't play well together normally. Here's the definitions for 960gs to let LessCSS work with it. Looks like we can pull all grid data out of the HTML.
/**
* A LessCSS version of the 960 Grid System
*
* http://lesscss.org/
* http://960.gs/
*/
/*********************************************************************
* Settings *
*********************************************************************/
@sledorze
sledorze / Monax nodejs monad
Created January 4, 2012 22:14
A feeling of Monax NodeJs continuation Monad for haXe
// Fake example showing the syntax
NodeM.dO({
coll <= db.collection("avatars", _);
avatars <= coll.all("", _);
ret(avatars.length);
})(function (err, res) etc.. );
@sledorze
sledorze / unfoldScala
Created February 3, 2012 10:16
unfold in Scala
final class Unfoldable[A](a : A){
def unfold[B, This, That](f: A => Option[(B, A)])(implicit cb: CanBuildFrom[This, B, That]): That = {
val builder = cb()
@tailrec def unfolding(a: A) : That = {
f(a) match {
case Some((e, next)) =>
builder += e
unfolding(next)
case None =>
builder.result()
@sledorze
sledorze / gist:5541555
Created May 8, 2013 16:10
failing function on coursera course.
def terrainFunction(levelVector: Vector[Vector[Char]]): Pos => Boolean =
{ case Pos(x,y) =>
try {levelVector(y)(x) != '-'} catch { case (e : IndexOutOfBoundsException) => false}
}
def findChar(c: Char, levelVector: Vector[Vector[Char]]): Pos = {
val y = levelVector.indexWhere(_.contains(c))
val x = levelVector(y).indexOf(c)
Pos(x, y)
@sledorze
sledorze / VerEx.hx
Created August 6, 2013 12:53 — forked from dpeek/VerEx.hx
class VerEx
{
public static function main()
{
var test = new VerEx()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
package Vect
import scala.language.higherKinds
sealed trait Nat
sealed trait Z extends Nat
sealed trait S[N <: Nat] extends Nat
trait Exists[A, +B[_ <: A]] {
type fst <: A
####################################
# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/
# Last tested & updated 10/13/2011
####################################
sudo apt-get update
####################################
@sledorze
sledorze / HttpsFilter
Last active August 29, 2015 14:01
Play Https filter for Heroku
object HttpsFilter extends Filter {
def isHttpsRequest(request : RequestHeader) =
Play.isDev || request.headers.get("x-forwarded-proto").exists(_.contains("https"))
override def apply(next: (RequestHeader) => Future[SimpleResult])(request: RequestHeader): Future[SimpleResult] = {
if (isHttpsRequest(request))
next(request)
else
Future.successful(Results.Redirect("https://"+ request.host + request.uri, request.queryString))
@sledorze
sledorze / abstractions.md
Created December 9, 2015 21:40 — forked from arobson/abstractions.md
Rabbit.MQ + Node.js Notes

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x