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: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: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: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 / 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;
Buckethead - Soothsayer
@jprudent
jprudent / consistent-hashing.clj
Created January 12, 2016 12:00
A simple implementation of consitant hashing in Clojure
(defprotocol ConsistentHashRing
(add-node [this node] "add node to the ring")
(remove-node [this node] "remove node and its replicas of the ring")
(find-node [this data] "find the node responsible of data"))
(defn- find-closest-key [xs h]
(or (first (drop-while #(> h %) xs))
(first xs)))
(extend-protocol ConsistentHashRing
#include <stdio.h>
#include <signal.h>
void infinite_loop(int signum) {
printf("in loop");
//signal(5, infinite_loop);
__asm__("int3");
}
int main(int argc, char ** argv) {
@jprudent
jprudent / ptrace_ext3.c
Created June 25, 2016 11:29
ptrace ex 3
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <sys/user.h>
#include <sys/reg.h>
void fizzbuzz() {