Skip to content

Instantly share code, notes, and snippets.

View francisdb's full-sized avatar
💾
undefined

Francis De Brabandere francisdb

💾
undefined
  • Ghent, Belgium
  • 14:04 (UTC +02:00)
View GitHub Profile
@JakeWharton
JakeWharton / BaseActivity.java
Created July 6, 2012 01:17
Scoped event bus which automatically registers and unregisters with the lifecycle.
package com.squareup.example;
public abstract BaseActivity extends SherlockActivity {
private final ScopedBus scopedBus = new ScopedBus();
protected ScopedBus getBus() {
return scopedBus;
}
@Override public void onPause() {
@rynbrd
rynbrd / text-zoom.py
Created August 10, 2012 18:18
Toggle interface scaling in Gnome3 and Google Chrome
#!/bin/env python3
import os
import sys
import json
import subprocess
from gi.repository import Gio
class ScaleError(Exception):
@bverbeken
bverbeken / AfterOrganisationTest.java
Created October 19, 2012 11:31
Custom JUnit runner for Playframework (2.0) apps to eliminate boilerplate code
@RunWith(PlayJUnitRunner.class)
public class AfterOrganisationTest {
@Test
public void canBePersisted() {
new Organisation("org1").save();
Organisation reloadedOrg = Ebean.find(Organisation.class).findUnique();
assertThat(reloadedOrg.name).isEqualTo("org1");
}
@JakeWharton
JakeWharton / README.md
Last active March 31, 2025 21:01
Maven pom for Google Play services
/**
* "Select" off the first future to be satisfied. Return this as a
* result, with the remainder of the Futures as a sequence.
*
* @param fs a scala.collection.Seq
*/
def select[A](fs: Seq[Future[A]])(implicit ec: ExecutionContext): Future[(Try[A], Seq[Future[A]])] = {
@tailrec
def stripe(p: Promise[(Try[A], Seq[Future[A]])],
heads: Seq[Future[A]],
@mandubian
mandubian / gist:5183939
Created March 17, 2013 22:34
Play2.1 JSON API: Reads a JsArray and then map on its elements applying Reads (cumulating errors)
// maybe we could add this one into Play...
// Reads a JsArray and then map on its elements applying Reads (cumulating errors)
def readJsArrayMap[A <: JsValue](transformEach: Reads[A]): Reads[JsArray] = Reads { js => js match {
case arr: JsArray =>
arr.value.foldLeft(JsSuccess(Seq[JsValue]()): JsResult[Seq[JsValue]]) { (acc, e) =>
acc.flatMap{ seq =>
e.transform(transformEach).map( v => seq :+ v )
}
}.map(JsArray(_))
case _ => JsError("expected JsArray")
@visenger
visenger / install_scala_sbt.sh
Last active January 31, 2023 19:10
Scala and sbt installation on ubuntu 12.04
#!/bin/sh
# one way (older scala version will be installed)
# sudo apt-get install scala
#2nd way
sudo apt-get remove scala-library scala
wget http://www.scala-lang.org/files/archive/scala-2.11.4.deb
sudo dpkg -i scala-2.11.4.deb
sudo apt-get update
@jroper
jroper / MyManagedResource.scala
Last active November 4, 2021 10:20
Play resource routing
class MyManagedResource extends ResourceController[String] {
def index = Action(Ok("index"))
def newScreen = Action(Ok("new"))
def create = Action {
Redirect(MyInjectableResource.reverseRoutes.index())
}
def show(id: String) = Action(Ok("Show " + id))
@Jamedjo
Jamedjo / currency.js
Last active December 18, 2015 02:39
Quick currency detection script I wrote while making http://jamedjo.github.io/Converter/ to test out angularjs
function defaultCurrencyFromLanguage(){
var lang = window.navigator.userLanguage || window.navigator.language;
var symbol = "$";
if(/gb|uk|tr|je|ta|gs|gg|im|sd|sl|vg|cy|eg|fk|gi|lb|sh|ac|ss|sd|sy/i.test(lang)) {
symbol = "£";
}
else if(/me|sk|ea|gf|tf|bl|mf|ie|ee|re|it|mc|si|de|es|at|yt|gp|pm|cy|pt|fr|gr|ic|be|ad|fi|lu|va|mt|sm|mq|nl|ax|cs/i.test(lang)) {
symbol = "€";
}
else if(/cn|jp|fm|sj/i.test(lang)) {
@hanshoglund
hanshoglund / pad.hs
Last active February 12, 2021 16:21
Haskell String pad
padR :: Int -> String -> String
padR n s
| length s < n = s ++ replicate (n - length s) ' '
| otherwise = s