Skip to content

Instantly share code, notes, and snippets.

View fcroiseaux's full-sized avatar

Fabrice Croiseaux fcroiseaux

View GitHub Profile
@fcroiseaux
fcroiseaux / actix-web-client-request.rs
Created January 27, 2021 21:35
Example of an actix http client request that return sa string containing the body of the response
let url = "https://site.com/endpoint";
let client = Client::default();
let response :String = match client
.get(url)
.send()
.await {
Ok(mut resp) => match resp.body().await {
Ok(r) => String::from_utf8(r.to_vec()).unwrap_or_default(),
Err(e) => {
println!("{}", e);
@fcroiseaux
fcroiseaux / 3Box.txt
Created November 15, 2019 08:31
3Box verification
This post links my 3Box profile to my Github account! Web3 social profiles by 3Box.
✅ did:muport:QmRkqEhrjBmGKLwuucDx8kxuc4nwDJVyX2n4q9gPBMF5XC ✅
Create your profile today to start building social connection and trust online at https://3Box.io/
@fcroiseaux
fcroiseaux / gist:22aef388145d21f29cf2
Created November 16, 2014 20:38
Verifying that +fxzo is my openname (Bitcoin username). https://onename.io/fxzo
Verifying that +fxzo is my openname (Bitcoin username). https://onename.io/fxzo
@fcroiseaux
fcroiseaux / gist:8095387
Last active January 1, 2016 04:59
Regexp not working with ReactiveMongo ?
// Cette requête retourne bien l'enregistrement
val cursor: Cursor[JsObject] = connections.
find(BSONDocument("lastName" -> BSONString(mask))).
cursor[JsObject]
// Celle ci ne retourne rien ?
val cursor: Cursor[JsObject] = connections.
find(BSONDocument("lastName" -> BSONRegex("/"+mask+"/", "i"))).
cursor[JsObject]
package elastic
import play.api.libs.ws.{Response, SignatureCalculator, WS}
import play.api.libs.json._
import play.api.libs.json.Json._
import scala.concurrent._
import ExecutionContext.Implicits.global
/**
* Created with IntelliJ IDEA.
@fcroiseaux
fcroiseaux / Application.scala
Last active December 12, 2015 02:18
Une solution à l'exercice Jajascript du concours Code Story 2013 en Play/Scala avec utilisation des Iteratee pour le chargement des 50000 vols "à la volée". Cette solution donne 10000 points. L'ensemble des vols est chargé au fur et à mesure du parsing de la requête http et les vols sont stockées dans un ensemble trié par ordre inverse des heure…
package controllers
import play.api._
import libs.iteratee.Iteratee
import libs.json.{JsValue, JsArray, Json}
import play.api.mvc._
import models._
import collection.mutable
object Application extends Controller {
@fcroiseaux
fcroiseaux / DateUtils.scala
Created December 4, 2012 05:48
Utils class to calculate and work with holidays in a country (here in Luxembourg)
package utils
import org.joda.time.{Period, LocalDate}
object DateUtils {
def dateRange(from: LocalDate, to: LocalDate, step: Period): Iterator[LocalDate] =
Iterator.iterate(from) {
dt => dt.plus(step)
}.takeWhile(!_.isAfter(to))
@fcroiseaux
fcroiseaux / ReactiveFileUpload.scala
Created August 13, 2012 13:40
Play 2.0 Reactive File Upload using CSVReader and Iteratee. Parse a CSV file using Iteratee and send each line to a local elasticsearch instance
package controllers
import play.api.mvc._
import play.api.libs.iteratee.{Iteratee, Input}
import play.api.libs.concurrent.Promise
import play.api.libs.iteratee.Input.{El, EOF, Empty}
import au.com.bytecode.opencsv.CSVReader
import java.io.StringReader
import scala.collection.JavaConversions._
import play.api.libs.json.Json._
@fcroiseaux
fcroiseaux / listResult.scala.html
Created May 30, 2012 07:16
Testing template DSL
<!-- Example row of columns -->
@table(queryResult,
"[Nom du Client|Prenom du Client|Résidence]",
"[Nom|prenom|adresse]"
)
@fcroiseaux
fcroiseaux / ServerEventsComparison.scala
Created April 28, 2012 11:28
Comparison of Comet, SSE and WebSocket server to client communication with Playframework 2.0 in Scala
/**
* Handles the comet event stream.
*/
def cometStream = Action {
AsyncResult {
implicit val timeout = Timeout(5.seconds)
val actor=Akka.system.actorOf(Props[EventListener])
// Actor is listening for event on the eventStream
Akka.system.eventStream.subscribe(actor,classOf[ChangeEvent])
// For each event, stream the data to client