Skip to content

Instantly share code, notes, and snippets.

View rsnemmen's full-sized avatar

Rodrigo Nemmen rsnemmen

View GitHub Profile
@rsnemmen
rsnemmen / string2array.c
Created July 31, 2017 21:31
Breaks down a string containing a list of numbers into a float array. C code.
/*
Breaks down a string containing a list of numbers in a float array.
Recipe copied from here: https://stackoverflow.com/a/1862712/793218
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@rsnemmen
rsnemmen / array3d.c
Created July 31, 2017 01:28
Allocates a 3D array in C and populates it with random numbers. You can use the notation A[i][j][k] to access its elements
/*
Example demonstrating how to allocate and use a multdimensional
array.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@rsnemmen
rsnemmen / array2d.c
Last active July 31, 2017 01:28
Demonstrates how to allocate a 2D array in C, populating it with uniform random numbers. You can use the notation A[i][j] to access its elements
/*
Example demonstrating how to allocate and use a multdimensional
array.
Reference: http://pleasemakeanote.blogspot.com.br/2008/06/2d-arrays-in-c-using-malloc.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@rsnemmen
rsnemmen / indent for email.sublime-macro
Last active July 13, 2017 00:11
Sublime text 2 macro to indent text for an e-mail response. When you use this, it will turn a line "blah blah blah" from your text file into "> blah blah blah"
[
{
"args":
{
"characters": ">"
},
"command": "insert"
},
{
"args":
@rsnemmen
rsnemmen / compress_sets.py
Last active June 16, 2017 16:11
Given a pattern string and a number, this script will compress all files that match the pattern. Each compressed file will contain a number n of the original files
#!/usr/bin/env python
"""
This script solves a very specific problem: I am uploading files
to figshare and exceeding the limits on the number of uploaded
files. Since the file size limit is 5GB and I need to upload a
large quantity of files, I want to compress sequences of data files
and upload only the compressed ones.
Given a pattern string and a number, this script will compress
all files that match the pattern. Each compressed file will
@rsnemmen
rsnemmen / Makefile
Created June 10, 2017 14:38
Generic template for a Makefile
# Generic template for a Makefile
# put here the root name of your code
PROGRAM = randomauger_omp
CC = gcc-6
FC = gfortran
FFLAGS = -fopenmp -O2
CFLAGS = -fopenmp -O2
@rsnemmen
rsnemmen / pi.c
Created June 9, 2017 13:49
How to use the number Pi in C
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[]){
printf("%f \n", M_PI);
return(0);
}
@rsnemmen
rsnemmen / random.c
Created June 9, 2017 03:37
Generates 1000 pseudo random numbers (integers)
/*
Generates 1000 pseudo random numbers (integers).
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int i, imax=1000;
@rsnemmen
rsnemmen / args.c
Created June 9, 2017 03:36
Illustrates how to read command-line arguments in C. Prints usage info if not provided with any argument.
/*
Illustrates how to get arguments from the command-line.
Usage:
args 10.0
will print out the number you entered. If not given any
argument, will print out usage info.
*/
@rsnemmen
rsnemmen / arraydyn.c
Created June 9, 2017 03:35
Simple example illustrating how to dynamically allocate array in C. Number of elements in array provided via command-line argument.
/*
Gets a command-line argument that provides the number of
elements in an array. Dynamically allocates the array.
Generates random numbers and print them.
Usage:
args 10
will print out the 10 random numbers.