Skip to content

Instantly share code, notes, and snippets.

View rodo's full-sized avatar

Rodolphe Quiédeville rodo

View GitHub Profile
@rodo
rodo / percentile.erl
Last active December 16, 2015 20:49
calculate percentile in erlang
-module('percentile').
-export([percentile/2]).
-export([percentile95/1,percentile98/1]).
percentile95(L)-> percentile(L,0.95).
percentile98(L)-> percentile(L,0.98).
percentile(L, P)->
K=(length(L) - 1) * P,
F=floor(K),
@rodo
rodo / gist:8313478
Created January 8, 2014 08:19
Implement a HTTP server for unit test
"""
Basic httpserver usefull for testing
"""
import SimpleHTTPServer
import SocketServer
import threading
class JsonHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""
@rodo
rodo / gist:8560557
Created January 22, 2014 15:21
Use model default in a Django CreateView
#
# views.py
#
class ResumeNew(ProtectedMixin, CreateView):
model = Resume
form_class = ResumeForm
success_url = '/accounts/profile/'
template_name = 'resume/new.html'
def get_initial(self):
@rodo
rodo / gist:11016326854523f8f170
Created June 5, 2014 11:13
Sample usage of ts_utils:new_ets
%% -*- coding: utf-8 -*-
%%
%% Copyright (c) 2014 Rodolphe Quiédeville <rodolphe@quiedeville.org>
%%
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
@rodo
rodo / gist:c9a807c35c8412ea80d0
Created June 3, 2015 19:07
PostgreSQL Most common values in percent
SELECT
CAST(
UNNEST(string_to_array(
array_to_string(most_common_vals, ','), ','
)) AS integer
) AS most_common_vals,
CAST(
@rodo
rodo / gist:eb1aff3c0959eb6932f1
Created January 20, 2016 20:40
How many wal file in late for a streaming slave on PostgreSQL
CREATE OR REPLACE FUNCTION hex_to_int(hexval varchar) RETURNS integer AS $$
DECLARE
result int;
BEGIN
EXECUTE 'SELECT x''' || hexval || '''::int' INTO result;
RETURN result;
END;
$$
LANGUAGE 'plpgsql' IMMUTABLE STRICT;
--
-- Simple serialization with PostgreSQL 9.5
--
--
-- Sample tables
--
CREATE TABLE parc (
id serial primary key, name text,
ratio int default 10,
~# CREATE TABLE pocuui (id serial, extid uuid);
CREATE TABLE
~# drop table pocuui ;
DROP TABLE
~# CREATE TABLE pocuui (id int, extid uuid);
CREATE TABLE
~# insert into po
pocuui poire
~# insert into pocuui (id) values (generate_series(1,12));
INSERT 0 12
@rodo
rodo / trig.sql
Created May 27, 2016 10:32
Trigger to maintain new array from pseud CSV field
CREATE OR REPLACE FUNCTION doctype_extensions_migration()
RETURNS TRIGGER AS $BODY$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.exten IS NOT NULL) THEN
NEW.exten_array
= array_agg(trim(x.e))
### Keybase proof
I hereby claim:
* I am rodo on github.
* I am rodo (https://keybase.io/rodo) on keybase.
* I have a public key whose fingerprint is D9DA 64FF 732B 3876 2766 7AE7 177B F809 0835 E50E
To claim this, I am signing this object: