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
jprudent / i18n.scala.html
Created September 17, 2011 12:18
internationalization tag for playframework + scala
@(msg:String,params:Object *)@play.i18n.Messages.get(msg,params.toArray : _*)
//for example @i18n("index.hello","Marmite") in any play scala template
@jprudent
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)
object XhtmlTransformer {
import xml.transform.RuleTransformer
/
val className = MonocleReader.className
object XhtmlRewriter extends RewriteRule {
/**
@jprudent
jprudent / uselessParser.scala
Created September 23, 2011 05:47
How to read XML documents without validation
object MyXML extends XMLLoader[Elem] {
override def parser: SAXParser = {
val f = javax.xml.parsers.SAXParserFactory.newInstance()
f.setNamespaceAware(false)
f.setValidating(false)
f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
f.setFeature("http://apache.org/xml/features/validation/schema", false);
f.newSAXParser()
}
}
@jprudent
jprudent / removeNonNumerics
Created September 29, 2011 05:38
This method will transform a string to a number by removing non numbers characters (for memo)
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)
Novels to read :
boris Vian - Et on tuera tous les affreux
akutagawa
@jprudent
jprudent / gist:3619276
Created September 4, 2012 09:49
Blog entries to read
http://www.opensourcery.co.za/2009/04/19/to-amqp-or-to-xmpp-that-is-the-question/
@jprudent
jprudent / gist:4762623
Created February 12, 2013 12:42
Javascript module
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
jprudent / LearAsyncTest
Created June 5, 2013 10:08
self injecting spring test
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;
;; Anything you type in here will be executed
;; immediately with the results shown on the
;; right.
(use 'clojure.test)
(with-test
(defn extract-scheme
"extract scheme from url"
@jprudent
jprudent / gist:6375265
Last active December 21, 2015 22:29
substract 2 vectors in clojure
(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]