Skip to content

Instantly share code, notes, and snippets.

@ramonesteban
ramonesteban / consumer-producer.c
Created February 14, 2012 14:13
Simple example of consumer-producer with threads.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int burritos = 0;
void *consumer(void *threadid) {
int i;
for(i=0; i<15; i++) {
@ramonesteban
ramonesteban / cartas.m
Created March 1, 2012 21:36
Probabilidad de éxito.
function cartas(k, p, filename, repet)
completados = [0];
output = fopen(filename, "w");
for i = 1 : repet
paso = 1;
conteo = 0;
while (conteo < k)
conteo += bernoulli(p);
paso++;
endwhile
@ramonesteban
ramonesteban / caos.m
Created March 29, 2012 22:24
Evolución de la población.
function caos()
L = 0.000037;
numgen = 100;
first = 2000;
thisgen = first;
output = fopen("caos.dat", "w");
for i=1 : numgen
i;
nextgen = L*thisgen*(100000-thisgen);
fprintf(output, "%d %d\n", i, nextgen);
@ramonesteban
ramonesteban / caos.plot
Created March 29, 2012 22:26
Crea gráfica con los datos obtenidos.
set term postscript eps color 30
set key outside Right
set size 2, 1.5
set output "caos.eps"
set pointsize 2
plot "caos.dat" with lines ls 3 title ""
@ramonesteban
ramonesteban / hola.c
Created April 17, 2012 08:15
Ejemplo sencillo para tarea de ensamblador
#include <stdio.h>
int main(int argc, char** args) {
printf("Hola Mundo!\n");
return 0;
}
@ramonesteban
ramonesteban / hola.s
Created April 17, 2012 08:23
Código generado en lenguaje ensamblador
.file "hola.c"
.section .rodata
.LC0:
.string "Hola Mundo!"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
@ramonesteban
ramonesteban / fact.c
Created April 17, 2012 08:40
Obtener el factorial de un número
#include <stdio.h>
int main(int argc, char** args) {
int x;
int factorial = 1;
printf("Numero: ");
scanf("%d", &x);
while (x>1) {
factorial *= x--;
}
@ramonesteban
ramonesteban / fact.s
Created April 17, 2012 08:44
Código generado en lenguaje ensamblador para el factorial
.file "fact.c"
.section .rodata
.LC0:
.string "Numero: "
.LC1:
.string "%d"
.LC2:
.string "Factorial: %d\n"
.text
.globl main
@ramonesteban
ramonesteban / factorial.s
Created April 17, 2012 08:54
Código generado en lenguaje ensamblador para el factorial pero reducido
.LC0: #etiquetas
.string "Numero: " #cadenas
.LC1:
.string "%d"
.LC2:
.string "Factorial: %d\n"
.text
.globl main
.type main, @function
main:
@ramonesteban
ramonesteban / ramon.s
Created April 17, 2012 09:06
Mi propio ejemplo de ensamblador
.reprueba:
.string "El payaso viene por ti\n"
.aprueba:
.string "Vamos bien\n"
.valor:
.string "%d"
.text
.globl main
.type main, @function
main: