Skip to content

Instantly share code, notes, and snippets.

View PhDP's full-sized avatar
🏠
Working from home

Philippe Desjardins-Proulx PhDP

🏠
Working from home
View GitHub Profile
@PhDP
PhDP / rngint.c
Created March 30, 2012 13:02 — forked from isag/random integer
Generate integers in the semi-closed range with gsl
// clang -O3 -DHAVE_INLINE rngint.c -o rngint -lgsl -lgslcblas
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
// Get an integer in the [a,b) semi-closed range.
@PhDP
PhDP / linear-upper.py
Created April 11, 2012 11:39
Convert a linear index to X-Y coordinates from an upper triangular matrix
def getX(i):
return int(-0.5 + 0.5 * sqrt(1 + 8 * (i - 1))) + 2
def getY(i):
return getX(i) * (3 - getX(i)) / 2 + i - 1
def getXY(i):
return (getX(i + 1) - 1, getY(i + 1) - 1)
@PhDP
PhDP / create_pool.c
Created April 12, 2012 10:32 — forked from isag/create_pool.c
A way to create a species pool from assembly process
void create_assembled_pool(Params *p, double **pool, int divpool, double fert)
{
// define and initialize the ecosystem list
//-----------------------------------------
sll ecosys;
sll_init(&ecosys,(void*)free_species);
// create the basal resources
//---------------------------
basal(p,&ecosys,fert);
@PhDP
PhDP / randgsl.c
Created April 12, 2012 11:13
Random numbers with gsl
//: clang -DHAVE_INLINE -O3 randgsl.c -o randgsl -lgsl -lgslcblas
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
int main(int argc, const char *argv[])
@PhDP
PhDP / scope.c
Created April 12, 2012 11:19
Expliquer le concept de scope
{
int a = 1;
int b = 2;
{
int a = 3; // Ce 'a' est complètement différent du premier 'a'
a += 10; // Cherche un 'a' dans ce scope, il est trouve un (celui qui vaut 3).
int c = 5;
printf("%d\n", a); // Donne 13
printf("%d\n", b); // Donne 2. Ici il ne trouve pas de 'b' déclarer dans ce scope mais il cherche dans le scope précédent et trove 'b'.
printf("%d\n", c); // Donne 5.
@PhDP
PhDP / treat_th.c
Created April 21, 2012 15:21 — forked from isag/treat_th.c
use the treads for pool replicaes
typedef struct
{
unsigned int id;
Params *p;
}
pth;
void treatments(void *param, unsigned long s)
{
//------------//
@PhDP
PhDP / abstract.txt
Created October 5, 2012 16:08
abstract?
Public preprint servers such as arXiv.org have become central to the scientific
process in fields such as physics, mathematics, and economics. These preprint
servers allow researchers to make their research rapidly available to the
broader community prior to peer review, which facilitates discussion, review,
and rapid communication of scientific results. Preprints are increasingly seen
as an important component of open science, because the research can be discussed
by the scientific community as soon as it is finished, instead of being
virtually hidden until officially published. However, in contrast to other
disciplines, the field of biology has effectively no preprint culture, with the
exception of small pockets of primarily highly quantitative research (e.g.,
@PhDP
PhDP / primes.rb
Created November 13, 2012 15:32
primes
# Print a sequence of primes. It's not written to be fast, it's just to demonstrate
# than an infinite sequence can be compressed in a small program and thus have low
# (Kolmogorov) complexity.
def printprimes(max)
primes = []
for i in 2.. max do
primes << i if primes.inject(true) {|res, elt|
res and i % elt != 0
}
end
getPrimes = f [2, 3] 5
f ps n max = if n >= max then
ps
else if pr n then
f (ps ++ [n]) (n + 2) max
else
f ps (n + 2) max
where pr y = foldl (&&) True (map (\x -> mod y x > 0) ps)
@PhDP
PhDP / main.cc
Created January 28, 2013 04:21
Random program generator for optimists
// Compile with g++ -std=c++11 -O2 main.c -o main
#include <iostream>
#include <fstream>
#include <string>
#include <random>
#include <ctime>
#include <cstdlib>
using namespace std;