Skip to content

Instantly share code, notes, and snippets.

Avatar
🦋
Chasing butterflies

Jérôme Prudent jprudent

🦋
Chasing butterflies
View GitHub Profile
@jprudent
jprudent / i18n.scala.html
Created Sep 17, 2011
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
jprudent / addClass.scala
Created Sep 21, 2011
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
jprudent / uselessParser.scala
Created Sep 23, 2011
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.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 Sep 29, 2011
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
akutagawa
@jprudent
jprudent / gist:3619276
Created Sep 4, 2012
Blog entries to read
View gist:3619276
http://www.opensourcery.co.za/2009/04/19/to-amqp-or-to-xmpp-that-is-the-question/
@jprudent
jprudent / gist:4762623
Created Feb 12, 2013
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
jprudent / LearAsyncTest
Created Jun 5, 2013
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)
(with-test
(defn extract-scheme
"extract scheme from url"
@jprudent
jprudent / gist:6375265
Last active Dec 21, 2015
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]