Skip to content

Instantly share code, notes, and snippets.

View loicknuchel's full-sized avatar
👨‍💻
Explore your database => https://azimutt.app

Loïc Knuchel loicknuchel

👨‍💻
Explore your database => https://azimutt.app
View GitHub Profile
@loicknuchel
loicknuchel / Lazy.scala
Last active August 24, 2017 14:25
Lazy monad
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{FunSpec, Matchers}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Success, Try}
class Lazy[A](block: => A) {
private var evaluated = false
private lazy val underlying: A = {
evaluated = true
@loicknuchel
loicknuchel / problem.md
Created May 23, 2017 16:37
Decoding json

I've got a JSON with a list of events :

[
  {"id":"1","kind":"start"},
  {"id":"2","kind":"start"},
  {"id":"1","kind":"stop"},
  {"id":"4","kind":"start"},
  {"id":"4","kind":"stop"}
]
@loicknuchel
loicknuchel / bio.md
Last active November 9, 2017 11:29
Profil formateur Human Coders

avatar

Après être passé par la SSII, le freelance et la création de startup, Loïc Knuchel est maintenant développeur Scala chez Criteo. En parallèle, il s'investit activement dans la communauté tech parisienne en participant à de nombreux meetup et conférences, aussi bien comme participant que speaker. Aller à la rencontre des autres développeurs, apprendre d'eux et partager ses expériences est crucial. C'est pourquoi il organise les HumanTalks Paris depuis plusieurs années. Côté technologies, il a commencé avec Java mais est rapidement passé à Scala en 2013 en découvrant Play Framework. Aujourd'hui, il est fan de programmation fonctionnelle et de typage fort; et cherche toujours comment écrire du code qui soit utile (à l'utilisateur) et reste le plus simple et maintenable possible, notamment via le mouvement du software craftsmanship, le DDD, l'UX, l'event storming, l'event sourcing et autres gros mots du genre ;)

@loicknuchel
loicknuchel / gist:a2907a6ef04d2da1800f4aadaf23759d
Created November 10, 2016 09:58
Types vs React.propTypes

Why (some) frontend devs don't like TypeScript because of types but writes React.propTypes ????

Dropdown.propTypes = {
    text: React.PropTypes.object.isRequired,
    children: React.PropTypes.oneOfType([
        React.PropTypes.object,
        React.PropTypes.array
    ]).isRequired,
 autoClose: React.PropTypes.bool
@loicknuchel
loicknuchel / README.md
Created September 4, 2016 18:21
Missing features in Play i18n
@loicknuchel
loicknuchel / README.md
Created March 24, 2016 09:26
Problem with Play macro Json.format[T]

En mettant en place du typage pour mes IDs, je me retrouve avec un No apply function found matching unapply parameters quand j'utilise la macro Json.format[T] de Play :(

Du coup je suis obligé de définir explicitement les Reads et Writes

D'ailleurs, le type Email ne pose pas de problème. Je pense que ça doit venir du fait que Id est générique... Mais j'ai pas trouvé comment fixer le problème.

Si quelqu'un à une idée de ce qu'il peut manquer...

Ex: User.scala, Id.scala, Email.scala et TString.scala :)

// inspired from https://github.com/stacktracejs/stacktrace.js/blob/master/stacktrace.js
var Log = (function(){
return {
instrumentObj: instrumentObj
};
// This is working on my tests, do I made some "dangerous" things ?
function instrumentObj(tag, obj){
for(var i in obj){
if(typeof obj[i] === 'function'){
@loicknuchel
loicknuchel / bug.scala
Created September 3, 2015 17:27
Avez vous trouvé le bug ? En combien de temps ?
def details(eventId: String, exponentId: String) = SecuredAction.async { implicit req =>
withEvent(exponentId) { event =>
withExponent(eventId) { exponent =>
AttendeeRepository.findByUuids(exponent.info.team).map { team =>
Ok(backend.views.html.Events.Exponents.details(exponent, team, event))
}
}
}
}
@loicknuchel
loicknuchel / Sessions.scala
Last active March 30, 2018 19:31
Scala for-comprehension
object Sessions extends SilhouetteEnvironment {
def details(eventId: String, sessionId: String) = SecuredAction.async { implicit req =>
implicit val user = req.identity
val res: Future[Result] = for {
eventOpt: Option[Event] <- EventRepository.getByUuid(eventId)
sessionOpt: Option[Session] <- SessionRepository.getByUuid(sessionId)
} yield {
var res2: Option[Result] = for {
event: Event <- eventOpt
session: Session <- sessionOpt
@loicknuchel
loicknuchel / gist:662f04974132f0f2d51c
Last active August 29, 2015 14:20
Problem with Reactivemongo & Aggregation

I'm using Play 2.3.7, Mongo 2.4.8 and reactivemongo 0.10.5 and I've got some surprising things...

When start the shell and run :

db.Exponents.aggregate([
  {$match: {eventId: {$in: ["3dac7440-f8e5-497d-8b0b-77127d16e1ae", "fcb07f0c-2ff3-4408-b83e-8f42d6a00112"]}}},
  {$group: {_id: "$eventId", eventCount: {$sum: 1}}}
])