Skip to content

Instantly share code, notes, and snippets.

View loicdescotte's full-sized avatar

Loïc Descotte loicdescotte

View GitHub Profile
const config = {
typeDirs: [
{ type: "pdf", directory: "documents" },
{ type: "png", directory: "images" },
{ type: "mp3", directory: "music" },
],
};
type Config = typeof config;
type TypeDirs = Config["typeDirs"];
trait Functor[Box[_]] {
def map[In, Out](boxA: Box[In])(f: In => Out): Box[Out]
}
object Functor {
implicit val functorOption = new Functor[Option] {
override def map[In, Out](boxA: Option[In])(f: In => Out) = boxA.map(f)
}
implicit val functorList = new Functor[List] {
@jeantil
jeantil / scala.txt
Created August 24, 2016 13:22
getting started with scala
Infos générales et saines lectures
- les 4 articles Strategic Scala Style du blog de lee haoyi
http://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html
http://www.lihaoyi.com/post/StrategicScalaStyleConcisenessNames.html
http://www.lihaoyi.com/post/StrategicScalaStylePracticalTypeSafety.html
http://www.lihaoyi.com/post/StrategicScalaStyleDesigningDatatypes.html
Et la track de Daniel westheide
http://danielwestheide.com/scala/neophytes.html
Pour te familiariser avec le langage lui même tu peux pratiquer avec les workshops
@MarioAriasC
MarioAriasC / spark.kt
Last active December 21, 2019 11:22
Word Count with Apache Spark and Kotlin
package org.cakesolutions.spark
import org.apache.spark.SparkConf
import org.apache.spark.api.java.JavaSparkContext
import scala.Tuple2
fun main(args: Array<String>) {
val inputFile = args[0]
val outputFile = args[1]
@jfairbank
jfairbank / fibonacci-generator.js
Last active December 4, 2023 12:23
Fibonacci ES6 Generator
function *fibonacci(n) {
const infinite = !n && n !== 0;
let current = 0;
let next = 1;
while (infinite || n--) {
yield current;
[current, next] = [next, current + next];
}
}
@pathikrit
pathikrit / Node.scala
Last active September 17, 2021 02:02
Reverse a LinkedList in Scala
case class Node(value: Int, next: Option[Node])
def reverse(node: Node, prev: Option[Node] = None): Node = {
val reversed = node.copy(next = prev)
node.next map {reverse(_, Some(reversed))} getOrElse reversed
}
/****************************************************************/
val one = Node(1,Some(Node(2,Some(Node(3,None)))))
println(s"$one\n${reverse(one)}")
@jroper
jroper / Router.scala
Created July 2, 2014 07:50
Simple Play routing DSL with string interpolation
import java.util.regex.Pattern
import play.core.Routes
import play.api.mvc._
object Router extends Routes {
def routes = {
// Static paths
case Route("GET", p"") => controllers.Application.index
case Route("GET", p"/items") => controllers.Items.list
@nicmarti
nicmarti / JournauxRepository.scala
Created May 26, 2014 23:30
Slick 2.x left join
object JournauxRepository {
def allWithOperateurs():Seq[(Journal, Operateur, Option[String])] = {
DB.withSession {
implicit s =>
val result = for {
((journal, operateur), intervenant) <- Journaux leftJoin Operateurs on(_.idOperateur === _.id) leftJoin Intervenants on(_._1.idIntervenant === _.idAgence)
} yield (journal,operateur,intervenant.nom.?)
result.run
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Association du Paris Java User Group.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
@cvogt
cvogt / gist:9193220
Last active February 13, 2022 13:50 — forked from ruescasd/gist:7911033
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
import scala.slick.lifted.CanBeQueryCondition
// 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,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
import java.sql.Date