Skip to content

Instantly share code, notes, and snippets.

View loicdescotte's full-sized avatar

Loïc Descotte loicdescotte

View GitHub Profile
@sdaclin
sdaclin / IntellijBespin.icls
Last active October 23, 2017 06:28
My custom Mozilla Bespin based intellij idea color scheme. Install => Create a new colors scheme named IdeaBespin, locate the new configuration in .IdeaIC[xx]/config/colors and replace with this.
<scheme name="IdeaBespin" version="142" parent_scheme="Default">
<option name="LINE_SPACING" value="1.0" />
<option name="EDITOR_FONT_SIZE" value="14" />
<option name="EDITOR_LIGATURES" value="true" />
<console-font>
<option name="EDITOR_FONT_NAME" value="Consolas" />
<option name="EDITOR_FONT_SIZE" value="12" />
</console-font>
<console-font>
<option name="EDITOR_FONT_NAME" value="Monospaced" />
@leommoore
leommoore / node_redis.md
Last active April 26, 2023 07:01
Node - Redis

#Node - Redis

Redis is a simple key, value pair database. The common commands include:

Data StructureCommands
StringsSET, GET, DEL, APPEND, DECR, INCR...
HashsHSET, HGET, HDEL, HGETALL...
ListsLPUSH, LREM, LTRIM, RPOP, LINSERT...
SetsSADD, SREM, SMOVE, SMEMBERS...
@sadache
sadache / gist:4714280
Last active July 14, 2022 15:09
Playframework: Async, Reactive, Threads, Futures, ExecutionContexts

Asynchronicity is the price to pay, you better know what you're paying for...

Let's share some vocabulary first:

Thread: The primitive responsible of executing code on the processor, you can give an existing (or a new) Thread some code, and it will execute it. Normally you can have a few hundreds on a JVM, arguments that you can tweak your way out to thousands. Worth noting that multitasking is achieved when using multiple Threads. Multiple Threads can exist for a single processor in which case multitasking happens when this processor switches between threads, called context switching, which will give the impression of things happenning in parallel. An example of a direct, and probably naive, use of a new Thread in Java:

public class MyRunnable implements Runnable {
  public void run(){
 System.out.println("MyRunnable running");
@oxlade39
oxlade39 / InputStreamLineEnumerator.scala
Created March 1, 2013 07:53
Reading lines from an InputStream using a play.api.libs.iteratee.Enumerator
lazy val bufferedReader = new BufferedReader(new InputStreamReader(inputstream))
val responseStream: Enumerator[String] = Enumerator.generateM[String] {
Future{
logger.trace("about to read line")
val line: String = bufferedReader.readLine()
logger.trace("read line")
Option(line)
}
}
@mathieuancelin
mathieuancelin / WSEnumerator.scala
Last active December 21, 2015 10:48
Scala class to transform an HTTP GET stream into Enumerator[Whatever]
package play.api.libs.ws
import play.api.libs.iteratee.{Enumeratee, Concurrent, Enumerator}
import play.api.libs.concurrent.Execution.Implicits._
import com.ning.http.client._
import com.ning.http.client.AsyncHandler.STATE
import play.api.Logger
import scala.concurrent.{Future, Promise}
package controllers
import play.api.mvc.{Action, Controller}
import play.api.libs.iteratee.{Concurrent, Enumeratee}
import play.api.libs.json.{Json, JsValue}
import play.api.libs.EventSource
import play.api.libs.ws.WSEnumerator
import models._
import play.api.libs.concurrent.Execution.Implicits._
println("Hello :)")
println(list[1,2,3]:get(2))
let l = list[1,2,"3"]
let s = set["lions","tigers","bears"] # you can use let
println(s) #[lions, tigers, bears]
s:add("Honey badger")
@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
/*
* 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,
@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
}
}