Skip to content

Instantly share code, notes, and snippets.

View divarvel's full-sized avatar

Clément Delafargue divarvel

View GitHub Profile
@divarvel
divarvel / gist:10020595
Created April 7, 2014 13:46
Type inference with curried functions
scala> Some("yolo").fold(Nil)(List(_))
<console>:8: error: type mismatch;
found : List[String]
required: scala.collection.immutable.Nil.type
Some("yolo").fold(Nil)(List(_))
^
scala> Some("yolo").map(List(_)).getOrElse(Nil)
res1: List[String] = List(yolo)
@divarvel
divarvel / gist:10820327
Created April 16, 2014 06:58
tikhon jelvis quora answer
Tikhon Jelvis, consistency is all I ask
Votes by Jed Wesley-Smith, Scott Danzig, Gregory Popovitch, Toby Thain, and 111 more.
Most modern and well-featured? Hah! It's hard to tell it wasn't design 30 years ago. Go completely ignores most recent advances in programming languages in order to seem more similar to C. Charming.
Yes, there are drawbacks you're not seeing. But, more importantly, there are better alternatives you're ignoring. While some of the problems with Go are certainly actively detrimental, the bigger story is opportunity cost: you're missing out on some more capable, more expressive and safer languages.
So lets take your question in two parts: Go's drawbacks and then better alternatives.
Drawbacks

Play - Grunt integration

Gist does not let me put directories names in file names, so make sure to put:

  • assets-Gruntfile.js in assets/Gruntfile.js
  • assets-package.json in assets/package.json
  • project-Grunt.scala in project/Grunt.scala
  • project-JavaScriptBuild.scala in project/JavaSCriptBuild.scala

The goal is to let grunt handle everything in the assets directory.

Keybase proof

I hereby claim:

  • I am divarvel on github.
  • I am clementd (https://keybase.io/clementd) on keybase.
  • I have a public key whose fingerprint is 78D3 430C 4600 7020 9F7A B0A2 6BFE 863C 2684 AD09

To claim this, I am signing this object:

just value = Cont ($ value)
nothing def = Cont (const def)
result = do
x <- just 5
just (x + 5)
result' = do
x <- nothing(0)
just (x + 5)
@divarvel
divarvel / Email.scala
Last active August 29, 2015 14:13
Mailjet + Play mailer plugin
import play.api.Play.current
import scala.concurrent.duration._
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.Logger
import play.api.libs.mailer._
object email {
val senderAddress = ("name", "email@example.com")
@divarvel
divarvel / enums.scala
Created January 23, 2015 22:23
Enums
package models
import scalaz._
import Scalaz._
import anorm._
import org.postgresql.util.PGobject
import org.postgresql.jdbc4.Jdbc4Array
class A() {
def b(c: C): Unit = ()
}
class C() {
def >>:(a: A): Unit = ()
}
object test {
val a = new A()
var casper = require("casper").create();
casper.start();
var screenSize = [1024, 768];
var frameCount = 68;
function slideUrl(i) {
return 'http://localhost:9000/slides.html#'+i+'.0'
}
function frameName(i) {
var n = i < 10 ? '0' + i : i;
@divarvel
divarvel / mailjet.js
Created March 13, 2015 16:31
Mailjet API
var mailjet = require('mailjet');
var Promise = require('bluebird');
var _ = require('lodash');
var request = require('request');
var Mailjet = function(key, secret) {
return {
makeRequest: function(endPoint, args, method, creds) {
return new Promise(function(resolve, reject) {