Skip to content

Instantly share code, notes, and snippets.

@manucorporat
manucorporat / gist:8229938
Created January 3, 2014 00:14
C++'s dynamic_cast implemented for Objective-C
#define DYNAMIC_CAST(__CLASS__, __OBJ__) ((__CLASS__*)([__OBJ__ isKindOfClass:[__CLASS__ class]] ? __OBJ__ : nil))
@manucorporat
manucorporat / gist:5726177
Last active December 18, 2015 04:29
Smart way to profile algorithms in C. Full project with examples coming soon!!
#include <stdio.h>
#include <stdbool.h>
#include <sys/time.h>
typedef struct _profile_buf {
const char *title;
unsigned long long total;
unsigned long long index;
struct timeval timestamp;
} profile_buf;
@manucorporat
manucorporat / gist:5277108
Created March 30, 2013 15:30
Simulation in python of the probability that two randomly chosen numbers are coprime, is close to 6 / PI^2
# Simulation created by Manuel Martinez-Almeida
# http://en.wikipedia.org/wiki/Coprime_integers
import fractions
import math
import random
def calculateProbability(end, steps):
count = 0
@manucorporat
manucorporat / gist:4637010
Last active December 11, 2015 17:48
First test, Computer Sciences, Universidad de Valladolid, January 2013.
// PART 3
static void metodo3(NotaAlumnoAsignatura [] a)
{
int current = a[0].numAlumno;
double total = 0;
int nuNotas = 0;
try {
PrintWriter salida = new PrintWriter(new FileWriter("Notas.txt"));
for(int i = 0; i < a.lenght; ++i) {