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 / 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 / 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 / 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 / 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 / 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 / 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 / folders.c
Created March 29, 2012 10:22
Creating files/folders with system calls to mkdir in C
// clang folders.c -o folders
// Creating folders with system calls to mkdir
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
const int layer1 = 5;
@PhDP
PhDP / main.c
Created March 29, 2012 10:21
Pointer examples
#include <stdlib.h>
#include <stdio.h>
int main()
{
int a = 5;
int *b = &a;
printf(" a = %d\n", a);
printf(" &a = %p\n", &a);
@PhDP
PhDP / pause.c
Created March 17, 2012 17:38
Pause in C
//: clang -Wall pause.c -o pause
#include <stdlib.h>
#include <stdio.h>
// Wait for the user to press enter to continue.
void pause();
int main()
{
@PhDP
PhDP / isll.c
Created February 8, 2012 14:50
int isll_rm_tail(isll *l)
// Slow -> O(n). Return 1 if a node was removed, 0 otherwise. Untested :P
int isll_rm_tail(isll *l)
{
if (l->head == NULL)
{
return 0;
}
if (l->head == l->tail)
{
return isll_rm_next(l, NULL);