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 / K-nearest neighbor in Java
Created November 21, 2013 23:35
Writting some code in scala and java about collections.
package org.knuchel.playground;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@loicknuchel
loicknuchel / angularError.js
Last active March 9, 2017 17:37
Error handling in angular
angular.module('app', [])
.config(function($provide, debug){
// catch exceptions in angular
$provide.decorator('$exceptionHandler', ['$delegate', function($delegate){
return function(exception, cause){
$delegate(exception, cause);
var data = {
type: 'angular',
@loicknuchel
loicknuchel / angularPlugin.js
Created January 21, 2015 10:20
Angular MediaSrv : play audio with Cordova & Ionic apps
angular.module('my.cordova.plugins', ['ionic'])
// for media plugin : http://plugins.cordova.io/#/package/org.apache.cordova.media
.factory('MediaSrv', function($q, $ionicPlatform, $window){
var service = {
loadMedia: loadMedia,
getStatusMessage: getStatusMessage,
getErrorMessage: getErrorMessage
};
@loicknuchel
loicknuchel / dirty.js
Last active August 29, 2015 14:16
do: magic({"a": {"b": {"c": "hey"}}}, "a.b.c") === "hey"
// Quick & Unsafe way...
// + with eval your var MUST be global & you MUST know its name
var obj = {"a": {"b": {"c": "hey"}}};
var path = "a.b.c";
console.log(magic(obj, path)); // hey
console.log(eval("obj."+path)); // hey
console.log(obj.a.b.c); // hey
var wrongPath = "b.c";
@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}}}
])
@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 / 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))
}
}
}
}
// 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 / 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 :)

@loicknuchel
loicknuchel / README.md
Created September 4, 2016 18:21
Missing features in Play i18n