Posts

Showing posts from December, 2011

xrange with float steps - Python

The great thing about this code, is that the definition its a generator. (You can easily identify the keyword yield)

def drange(start, stop, step): r = start while r < stop: yield r r += step >>>i0=drange(0.0, 1.0, 0.1) >>>["%g" % x for x in i0] ['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1'] >>> source

Region Of Interest Ascii - IDL

An IDL little snippet to read Regions of Interest from an ascii file function load_roi, file_name ; Open file in read-only mode. openr, fd, file_name, /GET_LUN ; Read total pixel from 1 ROI. size = 0 readf, fd, size ; Read the indices of the pixels in the ROI result = intarr(size) readf, fd, result ; Close the file. close, fd return, result end Coded by Sil!

How to create symbolic link in Mac Os Lion

ln -s <absolute_path> <name_of_link>

Timeit function

Here i present a little function (with an example below) to time some bunch of code using timeit.
# -*- coding: utf-8 *-* import timeit class Chronoit(): """ A little class to handle timeit output. The output is in seconds. """ def __init__(self, main_statement, setup_statement, total_iterations): self.main_stmt = main_statement self.setup_stmt = setup_statement self.total_iter = total_iterations t = timeit.Timer(self.main_stmt, self.setup_stmt) self.show_results(t.timeit(number=self.total_iter)) def show_results(self, time_elapsed): time_per_pass = time_elapsed / self.total_iter if time_per_pass > 60.0: minutes_per_pass = time_per_pass / 60.0 secs_per_pass = time_per_pass % 60.0 print "#" * 50 print "Timing" print "setup stmt: \"" + self.setup_stmt.split("\n")[1] + &…

Modem Zyxel p-660R-T1 v3s Arnet

User: adminPassword: alvlgeddl