Skip to content

Instantly share code, notes, and snippets.

@julienrf
julienrf / fb-page-feed.js
Created November 29, 2010 11:06
A small js snippet retrieving the feed of a Facebook page and displaying its elements.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://connect.facebook.net/fr_FR/all.js"></script>
<script>
// Replace the id by any other public page id
FB.api('170913076256527/feed', { limit: 3 }, function(result) {
$('#fb-feed').empty();
$(result.data).each(function(i, post) {
entry = $('<div class="fb-item"></div>');
if (post.icon) {
entry.append('<img class="icon" src="' + post.icon + '" />');
@julienrf
julienrf / SurgicalUpdate.scala
Last active September 29, 2021 21:38
Surgical updates in Slick
import slick.lifted.TupleShape
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.concurrent.ExecutionContext.Implicits.global
object Example {
val db = Database.forConfig("db")
@julienrf
julienrf / Action.scala
Created April 9, 2012 16:20
How to implement a custom PathBindable with Play 2
def show(article: Article) = Action {
Ok(views.html.article(article))
}
@julienrf
julienrf / JFunction1.java
Created December 3, 2011 17:55
Using scala.Function1 from Java
package lambda;
public interface JFunction1<T1, R> {
R apply(T1 t);
}
@julienrf
julienrf / collections.scala
Created September 13, 2017 16:36
Signature of new operations
trait Iterable[A] {
// https://github.com/scala/collection-strawman/issues/221
/**
* Returns a collection formed by the result of applying a function to each pair of corresponding elements
* from this collection and another collection. It is semantically equivalent to `(xs zip ys) map f`.
* If one of the two collections is longer than the other, its remaining elements are ignored.
*/
def zipWith[B, C](that: Iterable[B])(f: (A, B) => C): Iterable[C]
@julienrf
julienrf / code.scala
Created January 15, 2016 15:10
dependent types + higher-kinded types + implicits
object OK {
trait `*`[A]
trait Bar {
type Qux
implicit val `*`: `*`[Qux]
}
def foo(bar: Bar): `*`[bar.Qux] = {
import bar._
@julienrf
julienrf / Main.scala
Last active December 27, 2015 16:09
Play with control
object Main extends App {
// You can retrieve the application configuration from any place
val configuration = Configuration("conf/my-app.conf")
// You instantiate your controllers with their required configuration
val application = new MyAbstractController(configuration) with SomeEventualMixin
// You pass your controllers as parameters to a router factory
val router = Router("conf/routes", application)
@julienrf
julienrf / unsoundness.dart
Last active December 14, 2015 04:49
Contravariance is useful.
// Some data type definitions: the usual (and boring) zoo class hierarchy
abstract class Animal { }
abstract class Mammal extends Animal { }
class Giraffe extends Mammal { }
class Zebra extends Mammal {
num stripeCount;
Zebra(num stripeCount) {
object Ok {
trait Foo[A]
case class Bar(x: Int)
object Bar {
implicit class BarOps(bar: Foo[Bar]) {
val ok = "ok"
}
}
def usage(bar: Foo[Bar]) = bar.ok // Ok, the implicit conversion is found in the Bar companion object
/**
* data (f :+: g) a = Inl (f a) | Inr (g a)
*/
sealed trait Coproduct[F[+_], G[+_], A]
case class Inl[F[+_], G[+_], A](a: F[A]) extends Coproduct[F, G, A]
case class Inr[F[+_], G[+_], A](a: G[A]) extends Coproduct[F, G, A]
trait :+:[F[+_], G[+_]] {
type Apply[A] = Coproduct[F, G, A]
}