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 / gen_scripts.py
Created November 25, 2011 23:10
SGE script
# Generate shell scripts for SGE.
def create_script(id, x, s, r, c, jpc):
f = open("job%(id_)d.sh" % {'id_' : id}, 'w')
f.write("#---------------------------Start program.job------------------------\n" \
"#!/bin/bash\n" \
"\n" \
"# The name of the job, can be whatever makes sense to you\n" \
"#$ -N phdp-c%(c_)dr%(r_).2f\n" \
"\n" \
@PhDP
PhDP / testweave.py
Created December 13, 2011 22:02
Weave example
# Example with weave
#
# Required packages (linux): python-scipy, python-dev
#
# phdp@thinkpad:~$ python testweave.py
# 9784957257.9
import numpy as np
from scipy.weave import inline
@PhDP
PhDP / species.go
Created December 15, 2011 21:28
A species object
package main
import (
"fmt"
"io"
"os"
)
type Species struct {
Name string // Name of the species (dah!)
@PhDP
PhDP / common.h
Created January 22, 2012 19:55
Constants in a header file
// common.h
#ifndef COMMON_H_
#define COMMON_H_
#ifndef EAM_CONSTANT1
#define EAM_CONSTANT1 0.5929439
#endif
#ifndef EAM_VERSION
@PhDP
PhDP / assert.c
Created January 26, 2012 10:54
assert example
// gcc assert.c -o assert
// gcc -DNDEBUG assert.c -o assert
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int main()
{
@PhDP
PhDP / main.c
Created February 4, 2012 15:26
Create a directory in C
// gcc main.c -o main
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
mkdir("newdir", S_IRWXU); // S_IRWXU is the mode, it gives read/write/search access to the user.
@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);
@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 / 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 / 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;