Skip to content

Instantly share code, notes, and snippets.

View loicdescotte's full-sized avatar

Loïc Descotte loicdescotte

View GitHub Profile
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")
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._
@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}
@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)
}
}
@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");
@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...
@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" />
@k33g
k33g / 1-dart.md
Created August 23, 2012 08:59
Dart, first steps
@caycefischer
caycefischer / jekyllSyntaxHighlighting.md
Created July 30, 2012 02:19
Various Methods of Syntax Highlighting w/ Jekyll

1. Highlighting the Jekyll way.

This method uses Liquid tags and works when published to Github Pages. It doesn't work in Github's viewer when browsing the repo.

{{ "{% highlight html linenos "}}%}
<div>this is some preformatted code</div>
{{ "{% endhighlight "}}%}

2. Highlighting the Markdown way

@sadache
sadache / AA.md
Created July 8, 2012 21:29
Is socket.push(bytes) all you need to program Realtime Web apps?

Is socket.push(bytes) all you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications that make use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications let users work with information as it is published - without having to periodically ping the service.

There are quite a few web frameworks that target the development of this type of application: but usually the solution is to simply provide an API that allows developers to push/receive messages from/to an open channel, something like: