Skip to content

Instantly share code, notes, and snippets.

@jeancroy
jeancroy / distcorr.py
Created November 8, 2020 04:56 — forked from wladston/distcorr.py
Distance correlation with p-value
from scipy.spatial.distance import pdist, squareform
import numpy as np
import copy
def distcorr(Xval, Yval, pval=True, nruns=500):
""" Compute the distance correlation function, returning the p-value.
Based on Satra/distcorr.py (gist aa3d19a12b74e9ab7941)
>>> a = [1,2,3,4,5]
@jeancroy
jeancroy / float2rat.js
Last active December 21, 2017 20:44 — forked from joni/float2rat.js
A JavaScript function to find short rational number representations of floating point numbers, with the help of some continued fractions.
// See http://jonisalonen.com/2012/converting-decimal-numbers-to-ratios/
// Also https://en.wikipedia.org/wiki/Diophantine_approximation
// or french https://fr.wikipedia.org/wiki/Fraction_continue_et_approximation_diophantienne
function float2rat(x) {
var tolerance = 1.0E-6;
var max_iter = 100; // Limit on the amount of work we want to do
var max_den = 1000; // When is a fraction not really more helpfull than decimal ?
@jeancroy
jeancroy / AESGCM.cs
Created August 5, 2016 03:10 — forked from jbtule/AESGCM.cs
I have two code examples that I wrote for best practices encrypting a string in c#. They are both using authenticated encryption. http://stackoverflow.com/a/10366194/637783
/*
* This work (Modern Encryption of a String C#, by James Tuley),
* identified by James Tuley, is free of known copyright restrictions.
* https://gist.github.com/4336842
* http://creativecommons.org/publicdomain/mark/1.0/
*/
using System;
using System.IO;
using System.Text;