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:8383414
Created January 12, 2014 11:22
Solving the 16th first problems of project Euler with clojure
(ns euler-clj.core
:use [clojure.test])
;; problem 1
(with-test
(defn multiple-of-3-and-5
"Find the sum of all the multiple of 3 and 5 below `limit`"
[limit]
@jprudent
jprudent / gist:6485375
Created September 8, 2013 15:00
Convert a clojure sequence to a scala.collection.immutable.List
(defn to-scala-list [& vals]
(reduce
#(.apply scala.collection.immutable.$colon$colon$/MODULE$ %2 %1)
(scala.collection.immutable.Nil$/MODULE$)
(map to-jmhc-tile vals)))
@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]
;; 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 / 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;
@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 / 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/
Novels to read :
boris Vian - Et on tuera tous les affreux
akutagawa
@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)