Skip to content

Instantly share code, notes, and snippets.

@stla
stla / splitDF.js
Created October 4, 2016 14:25
Split a JSON dataframe
function split(df, columns, by){
var factors = Array.from(new Set(unpack(df, by)));
var y = factors.map(function(factor) {
var rowsFiltered = df.filter(function(row) {
return (row[by] === factor);
});
var subdf = {};
for(i=0; i<columns.length; i++){
subdf[columns[i]] = unpack(rowsFiltered, columns[i]);
}
@stla
stla / deming_v00.R
Created October 19, 2016 09:26
Deming regression: confidence and prediction intervals
####### Estimates and covariance matrix #########
deming.estim <- function(x,y,lambda=1){ # lambda=sigmay²/sigmax²
n <- length(x)
my <- mean(y)
mx <- mean(x)
SSDy <- crossprod(y-my)[,]
SSDx <- crossprod(x-mx)[,]
SPDxy <- crossprod(x-mx,y-my)[,]
A <- sqrt((SSDy - lambda*SSDx)^2 + 4*lambda*SPDxy^2)
@stla
stla / uploadXLSXorCSV.html
Created April 2, 2017 10:49
Upload a XLS, XLSX, or CSV sheet
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script src="libraries/jquery.min.js"></script>
<script src="libraries/papaparse.min.js"></script>
<script src="libraries/xlsx.core.min.js"></script>
<script src="libraries/bootstrap.min.js"></script>
<link rel="stylesheet" href="libraries/bootstrap.min.css">
<link rel="stylesheet" href="libraries/bootstrap-theme.min.css">
@stla
stla / loadSheetAndSelectColumn.html
Created April 2, 2017 11:26
Upload a XLS/XLSX/CSV sheet and select a column
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script src="libraries/jquery.min.js"></script>
<script src="libraries/papaparse.min.js"></script>
<script src="libraries/xlsx.core.min.js"></script>
<script src="libraries/bootstrap.min.js"></script>
<link rel="stylesheet" href="libraries/bootstrap.min.css">
<link rel="stylesheet" href="libraries/bootstrap-theme.min.css">
@stla
stla / transform_vector_cpp.hs
Last active September 24, 2017 06:30
Transform a vector in Haskell with inline-c-cpp
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
module TestsCPP
where
import qualified Language.C.Inline.Cpp as C
import qualified Data.Vector.Storable as V
import Data.Monoid ((<>))
C.context (C.cppCtx <> C.vecCtx)
@stla
stla / Lib.hs
Last active October 13, 2017 10:03
Haskell FFI examples
{-# LANGUAGE ForeignFunctionInterface #-}
module Lib where
import Foreign.C.Types
import Foreign (peek, newForeignPtr_)
import Foreign.Ptr
import System.IO.Unsafe (unsafePerformIO)
import qualified Data.Vector.Storable as SV
---
title: "Bug DLL"
author: "Stéphane Laurent"
date: "10 octobre 2017"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
@stla
stla / OwenT.cpp
Created December 19, 2017 15:28
Simple implementation of the Owen T-function
#include <cmath>
#include <cfloat>
#include <boost/math/special_functions/erf.hpp>
#include <boost/math/constants/constants.hpp>
const double onedivtwopi = boost::math::constants::one_div_two_pi<double>();
const double onedivroottwo = boost::math::constants::one_div_root_two<double>();
int sign(double x){
return (std::signbit(x) ? -1 : 1);
@stla
stla / CompoundFiveTetrahedra.R
Created February 7, 2018 14:25
Compound of five tetrahedra with rgl
library(rgl)
# vertices ####
phi <- (1+sqrt(5))/2
a <- 1/sqrt(3)
b <- a/phi
c <- a*phi
vertices <-
rbind(
c( a, a, a),
@stla
stla / CompoundTenTetrahedra.R
Created February 7, 2018 14:27
Compound of ten tetrahedra with rgl
library(rgl)
# vertices ####
phi <- (1+sqrt(5))/2
a <- 1/sqrt(3)
b <- a/phi
c <- a*phi
vertices <-
rbind(
c( a, a, a),