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:1621772
Created January 16, 2012 16:56
Mongo DB ObjectId request matching
object Oid {
def unapply(s: String): Option[ObjectId] = {
if(ObjectId.isValid(s)) Some(new ObjectId(s))
else None
}
}
def intent = {
scala> MongoDBObject("foo" -> None).getAs[String]("foo")
res0: Option[String] = Some(None)
scala> MongoDBObject("foo" -> null).getAs[String]("foo")
res0: Option[String] = None
@divarvel
divarvel / gist:1726491
Created February 2, 2012 23:46
flatten & flatMap
function flatten(list) {
return _.reduce(list, function(acc, item) {
return acc.concat(item);
}, []);
}
function flatMap(list, func, context) {
return flatten(_.map(list, func, context));
}
@divarvel
divarvel / gist:2146847
Created March 21, 2012 13:22
Play2 + Bootstrap2
@(elements: helper.FieldElements)
@**************************************************
* Generate input according twitter bootsrap rules *
**************************************************@
<div class="control-group@if(elements.hasErrors) {" errors"}">
<label for="@elements.id" class="control-label">@elements.label</label>
<div class="controls">
@elements.input
<span class="help-inline">@((elements.errors ++ elements.infos).mkString(", "))</span>
@divarvel
divarvel / gist:3832468
Created October 4, 2012 09:18
This is wrong.
def method(a: Any): String = a match {
case i: Int => "Int"
case s: String => "String"
case _ => "Other"
}
@divarvel
divarvel / gist:3879641
Created October 12, 2012 15:03
Xmonad workspaces
myWorkspaces = zipWith (++)
(map show [1..12]) $
map (":"++)
[ "Web"
, "Code"
, "SSH"
, "Social"
, "Email"
, "Music"
, "Video"
@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: