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 / gist:a2c405ad16a5d9dee6fb
Last active August 29, 2015 14:05
Calcul du revenu d'imposition
(let [revenu 50000
tranches [ [0 6011 0.] [6011 11991 0.055] [11991 26631 0.14] [26631 71397 0.3] [71397 151200 0.41]]]
(reduce
(fn [total [tmin tmax coeff]]
(let [m-in-tranche (- (min tmax revenu) tmin)]
(+ total (max 0 (* m-in-tranche coeff)))))
0
tranches))
@jprudent
jprudent / gist:ce1e06377784c88763d1
Created July 4, 2015 19:50
ISO 8601 duration regexp
(def duration-pattern #"^(?<sign>\+|-)?P(?:(?:(?:(?<years>\d+(?:[,.]\d+)?)Y)?(?:(?<months>\d+(?:[.,]\d+)?)M)?(?:(?<days>\d+(?:[.,]\d+)?)D)?(?<time>T(?:(?<hours>\d+(?:[.,]\d+)?)H)?(?:(?<minutes>\d+(?:[.,]\d+)?)M)?(?:(?<seconds>\d+(?:[.,]\d+)?)S)?)?)|(?<weeks>\d+(?:[.,]\d+)?W))$")
(ns hello-world.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]])
(:use [ring.adapter.jetty]))
(defroutes app-routes
(GET "/" [] "Salut Billy")
(route/not-found "Not Found"))
@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 / LearnJenaTest.java
Created November 30, 2015 17:05
Extract model
package com.vidal.pmsi.data;
import java.util.HashSet;
import java.util.Set;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFFormat;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;