Skip to content

Instantly share code, notes, and snippets.

View francisdb's full-sized avatar
💾
undefined

Francis De Brabandere francisdb

💾
undefined
  • Ghent, Belgium
  • 02:57 (UTC +02:00)
View GitHub Profile
@RayRoestenburg
RayRoestenburg / firstSucceededOf.scala
Last active May 20, 2021 21:45
firstSucceededOf, returns a future containing the first successful result or contains the last failure if all futures have failed. What's wrong with it?
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util._
import java.util.concurrent.atomic.AtomicInteger
def firstSucceededOf[T](futures: TraversableOnce[Future[T]])(implicit executor: ExecutionContext): Future[T] = {
val p = Promise[T]()
val size = futures.size
val failureCount = new AtomicInteger(0)
@leon
leon / Grunt.scala
Last active September 3, 2016 02:23
Playframework 2.2 Grunt Runner
import sbt._
import Keys._
import java.net._
import java.io.File
import play.PlayRunHook
/*
Grunt runner should be in project directory to be picked up by sbt
*/
object Grunt {
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T](data: Option[T])(f: T => X => scala.slick.lifted.Column[Boolean]) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
def find(id: Option[Int], createdMin: Option[Date], createdMax: Option[Date], modifiedMin: Option[Date], modifiedMax: Option[Date]) = {
@peterkuterna
peterkuterna / gist:8245223
Created January 3, 2014 19:47
Nexus 5 in DE
1. Create an account at mailboxde.com and use it as package forwarder
2. Use a DE proxy/VPN. E.g. select one from http://www.proxynova.com/proxy-server-list/country-de/
3. Create a new Google account
4. Use address of mailboxde.com for your Google and Wallet account
5. Add a credit card with the following shipping address:
Mailboxde.com
Dresdner Str. 9
z. Hd. <first name> <last name>, ID <mailboxde id>
Zittau 02763 DE
+49 3583 8355148
@sebnozzi
sebnozzi / PlayBrowserSpec.scala
Last active November 8, 2016 02:15
How to integrate ScalaTest (FlatSpec) with Play
import org.scalatest.BeforeAndAfterAll
import org.openqa.selenium.WebDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.FlatSpec
import play.api.test.TestServer
import org.scalatest.Matchers
import play.api.test.Helpers
import org.scalatest.selenium.WebBrowser
import play.api.test.FakeApplication
@cvogt
cvogt / gist:9239494
Last active September 9, 2019 01:30
Slick app architecture cheat sheet
// Please comment in case of typos or bugs
import scala.slick.driver.H2Driver._
val db = Database.for...(...)
case class Record( ... )
class Records(tag: Tag) extends Table[Record](tag,"RECORDS"){
...
def * = ... <> (Record.tupled,Record.unapply)
// place additional methods here which return values of type Column
@julienrf
julienrf / Application.java
Last active August 29, 2015 14:00
Content negotiation in Java with Play framework
package controllers;
import play.mvc.Controller;
import play.libs.Json;
import static controllers.Render.*;
import static play.mvc.Http.MimeTypes;
public class Application extends Controller {
@staltz
staltz / introrx.md
Last active July 22, 2025 08:36
The introduction to Reactive Programming you've been missing
@Sitebase
Sitebase / gravatar.js
Created November 13, 2014 12:03
Little trick to check if a gravatar is available or not for a certain email address.
var http = require('http'),
md5 = require('MD5');
var options = {
method: 'HEAD',
host: 'www.gravatar.com',
port: 80,
path: '/avatar/' + md5('[email protected]') + '?d=http://bla.com'
};
var req = http.request(options, function(res) {
@cvogt
cvogt / gist:b86aff8ac51f49a574cc
Last active August 29, 2015 14:11
Immutable cycles (as seen in "Case classes a la carte with shapeless, now!" at scalax2014 by @milessabin)
// immutable cycle
class Node[T]( val value: T, _next: => Node[T] ){
lazy val next = _next
}
val cycle: Node[Int] = new Node( 1, new Node( 2, cycle ) )
// prints List(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
println(cycle.iterator.take(10).map(_.value).toList)
implicit class NodeIterator[T](node: Node[T]){