Skip to content

Instantly share code, notes, and snippets.

View edrdo's full-sized avatar

Eduardo R. B. Marques edrdo

View GitHub Profile
@edrdo
edrdo / memlayout.c
Created May 12, 2017 00:51
Memory Layout in C
/**
Output in a typical compiler / architecture will be:
sizeof(a) = 24
offset(a.f16) = 0
offset(a.f32) = 4
offset(a.f08) = 8
offset(a.f64) = 16
sizeof(b) = 16
offset(b.f64) = 0
@edrdo
edrdo / PoissonProcess.java
Last active December 20, 2017 17:10
Poison process simulation
package poisson;
import java.util.Random;
/**
* Simple implementation for poisson process random number generation.
* Check http://github.com/edrdo/PoissonProcess
*
* @author Eduardo R. B. Marques
*
@edrdo
edrdo / DaysInMonth.java
Last active February 17, 2018 14:32
Simple pedagogical example for software testing purposes
// Class containing a method to determine the number of days in a month.
// I use it sometimes for pedagogical purposes in software testing/engineering courses.
public class DaysInMonth {
/**
* Get number of days in a month.
* @param m Month.
* @param y Year.
* @return Number of days of given month and year.
*/
public static int daysInMonth(int m, int y) {
@edrdo
edrdo / whittakerSmoother.m
Last active March 14, 2021 09:23
Whittaker smoothing algoritm in Matlab
% Reference: "A perfect smoother", PHC Eilers - Analytical chemistry, 2003
% This is the simplest formulation - check Eilers' article for an alternative implementation making use of sparse matrixes.
function z = whittakerSmoother(y,lambda)
m = length(y);
I = eye(m);
D = diff(I);
z = (I + lambda * D' * D)\y;
end
% Test
@edrdo
edrdo / .gitignore
Created June 6, 2018 08:52
.gitignore entries for LaTeX generated files
*.aux
*.toc
*.out
*.bbl
*.blg
*.log
*.synctex.gz
@edrdo
edrdo / poisson.py
Created June 15, 2018 13:03
Poisson process - interarrival times (Pyhton)
import random
class PoissonProcess(object):
def __init__(self, rate, seed=None):
self.prng = random.Random(seed)
self.rate = rate
def timeTillNextEvent(self):
return self.prng.expovariate(self.rate)
@edrdo
edrdo / EDFQueue.py
Created August 31, 2018 10:31
EDF task queue in Python
import heapq
import time
import os
class EDFQueue(object):
def __init__(self):
self.heap = []
def count(self):
return len(self.heap)
@edrdo
edrdo / pthread_barrier.c
Last active December 2, 2023 11:36
Pthread barriers using condition variables
/**
* Eduardo R. B. Marques.
*
* Basic pthread_barrier_XXX functionality (not part of the standard Pthreads library).
*
* Note: no error checking for now.
*/
typedef struct {
unsigned size; // threads that should join barrier
@edrdo
edrdo / string_split.sql
Created May 4, 2019 23:40
string_split (MySQL)
DROP PROCEDURE IF EXISTS string_split;
DELIMITER $
CREATE PROCEDURE string_split
(IN string TEXT, IN sep CHAR(1), OUT num INT)
BEGIN
DECLARE pos INT;
DECLARE aux TEXT;
DECLARE str text;
@edrdo
edrdo / TEA.java
Created November 27, 2019 21:25
Tiny Encryption Algorithm
package qses.tea;
/**
* Implementation of the Tiny Encryption Algorithm (TEA).
* The Tiny Encryption Algorithm is one of the fastest and most efficient
* cryptographic algorithms in existence. It was developed by David Wheeler and
* Roger Needham at the Computer Laboratory of Cambridge University.
*
* See http://www.cl.cam.ac.uk/ftp/users/djw3/tea.ps
*