Skip to content

Instantly share code, notes, and snippets.

View jprudent's full-sized avatar
Chasing butterflies

Jérôme Prudent jprudent

Chasing butterflies
View GitHub Profile
jprudent / i18n.scala.html
Created September 17, 2011 12:18
internationalization tag for playframework + scala
View i18n.scala.html
@(msg:String,params:Object *)@play.i18n.Messages.get(msg,params.toArray : _*)
//for example @i18n("index.hello","Marmite") in any play scala template
jprudent / addClass.scala
Created September 21, 2011 16:48
Adding a given class on first level paragraph and heading elements of XHTML document (for memo)
View addClass.scala
object XhtmlTransformer {
import xml.transform.RuleTransformer
val className = MonocleReader.className
object XhtmlRewriter extends RewriteRule {
jprudent / uselessParser.scala
Created September 23, 2011 05:47
How to read XML documents without validation
View uselessParser.scala
object MyXML extends XMLLoader[Elem] {
override def parser: SAXParser = {
val f = javax.xml.parsers.SAXParserFactory.newInstance()
f.setFeature("", true);
f.setFeature("", false);
jprudent / removeNonNumerics
Created September 29, 2011 05:38
This method will transform a string to a number by removing non numbers characters (for memo)
View removeNonNumerics
public static String removeNonNumerics(String text) {
//remove everything except + - and digits
String num = text.replaceAll("[^-+\\.\\d]", "");
if (num.length() > 0) {
//remove + and - in middle of the string
num = num.charAt(0) + num.substring(1).replaceAll("[-+]", "");
//remove extra . (keep the first)
View gist:3496864
Novels to read :
boris Vian - Et on tuera tous les affreux
jprudent / gist:3619276
Created September 4, 2012 09:49
Blog entries to read
View gist:3619276
jprudent / gist:4762623
Created February 12, 2013 12:42
Javascript module
View gist:4762623
var myNamespace = (function () {
var myPrivateVar, myPrivateMethod;
// A private counter variable
myPrivateVar = 0;
// A private function which logs any arguments
myPrivateMethod = function( foo ) {
console.log( foo );
jprudent / LearAsyncTest
Created June 5, 2013 10:08
self injecting spring test
View LearAsyncTest
import fr.pmu.commons.spring.SpringBuilder;
import org.junit.*;
import org.junit.Test;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Service;
View url-encoding-in-clojure.clj
;; Anything you type in here will be executed
;; immediately with the results shown on the
;; right.
(use 'clojure.test)
(defn extract-scheme
"extract scheme from url"
jprudent / gist:6375265
Last active December 21, 2015 22:29
substract 2 vectors in clojure
View gist:6375265
(defn minus [v1 v2]
"substract 2 vectors, v2 must be a subset of v1"
(reduce (fn [acc v]
(let [index (.indexOf acc v)]
(into (subvec acc 0 index) (subvec acc (inc index))))) v1 v2))
(minus [:c :a :b :b :a :a :b] [:a :a :b :a]) ; [:c :b :b]