Skip to content

Instantly share code, notes, and snippets.

@ramonesteban
ramonesteban / detecting_holes.py
Created April 23, 2013 06:00
Fragmento del programa para detección de agujeros
def minimums_in_histogram(self, hist):
minimums = list()
for i, value in enumerate(hist):
try:
if hist[i-2] > value and hist[i-1] > value and value <= hist[i+1]:
minimums.append(i)
except:
pass
return minimums
@ramonesteban
ramonesteban / ellipses.py
Created April 18, 2013 14:28
Fragmento de código para la detección de elipses y círculos
def bfs(self, image, start_pixel_pos, color):
pixels = image.load()
width, height = get_image_size(image)
queue = []
copy = []
count = 0
queue.append(start_pixel_pos)
original = pixels[start_pixel_pos]
while 0 < len(queue):
@ramonesteban
ramonesteban / traffic_cbr.tcl
Created April 16, 2013 19:31
Prueba de tráfico CBR en simulación con NS-2
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
set nf [open out.nam w]
$ns namtrace-all $nf
set nd [open out.tr w]
$ns trace-all $nd
proc finish {} {
@ramonesteban
ramonesteban / delay.awk
Created April 16, 2013 18:45
Script para evaluar el retraso de tráfico CBR en el simulador NS-2
BEGIN {
highest_packet_id = 0;
}
{
action = $1;
time = $2;
from = $3;
to = $4;
type = $5;
pktsize = $6;
@ramonesteban
ramonesteban / action.py
Created April 16, 2013 11:13
Fragmento del código para la detección de elipses
def draw_ellipses_found(self, image, ellipses_found):
draw = ImageDraw.Draw(image)
max_w, max_h = get_image_size(image)
counter = 0
for ellipse in ellipses_found:
x, y, xd, yd = ellipse
print 'Ellipse detected at center (%d, %d)' % (x, y)
print '> Semidiameters:', xd, yd
draw.ellipse((x-xd, y-yd, x+xd, y+yd), outline=(255, 255, 0), fill=None)
@ramonesteban
ramonesteban / search_ellipse.py
Created April 16, 2013 11:11
Fragmento de la función para buscar elipses
def search_ellipse(self, can_be_ellipses, image, Gx, Gy):
width, height = get_image_size(image)
pixels_gx = Gx.load()
pixels_gy = Gy.load()
l = 80
ellipses_found = []
for ellipse in can_be_ellipses:
pixels = image.load()
votes = []
@ramonesteban
ramonesteban / huffman.py
Last active December 16, 2015 02:29
Codificación Huffman
def frequency_dictionary(text):
dictionary = dict()
for i in range(len(text)):
if dictionary.has_key(text[i]):
dictionary[text[i]] += 1
else:
dictionary[text[i]] = 1
return dictionary
class Node:
@ramonesteban
ramonesteban / multicast_bst.tcl
Created April 8, 2013 07:21
Simulación del protocolo BST
set ns [new Simulator -multicast on]
$ns color 1 Red
$ns color 30 Purple
$ns color 31 Green
set f [open out.tr w]
$ns trace-all $f
$ns namtrace-all [open out.nam w]
proc finish {} {
@ramonesteban
ramonesteban / unicast_dv.tcl
Created April 8, 2013 07:20
Simulación del protocolo DV
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
set file1 [open out.tr w]
$ns trace-all $file1
set file2 [open out.nam w]
$ns namtrace-all $file2
proc finish {} {
@ramonesteban
ramonesteban / twodisplays.pde
Created March 12, 2013 01:08
Contador 00 a 99 con Arduino Mega
const int firstPinDisplayOne = 2;
const int firstPinDisplayTwo = 22;
const int difPin = firstPinDisplayTwo-firstPinDisplayOne;
const int timer = 400;
const int a = 2;
const int b = 3;
const int c = 4;
const int d = 5;
const int e = 6;
const int f = 7;