See also: Heapify

Pages: 1 2 3 4 5 6 7 8 9 10 11

A neater way to print something every x iterations in Python

To print some information every 10 loop iterations can be a bit messy. Given the following, simple loop:

for x in lots_of_stuff:
    process(x)

The "dumbest" way would be:

i = 0
for x in lots_of_stuff:
    process(x)
    if i % 10 == 0:
        print "Some progress info"
    i += 1

A more elegant solution would be to use the enumerate built-in:

for i, x in enumerate(lots_of_stuff):
    process(x)
    if i % 20 == 0:
        print "Some progress info"

Much nicer, but this doesn't work with while loops

...

Read more

There are 4 comments on this post.

New site!

After a frustrating development cycle we're back. With a new site. You may not notice many if any changes. It's mostly been fixing problems back-end with the system and putting in new features for our members. We do now have some public features that should make things more interesting. Including the projects pages!

The site layout will remain the same for the time being as I have too many other projects to be getting on with.

...

Read more

There is 1 comment on this post.

Coming soon: New site.. version 3!

The redevelopment of this site and it's mini-site is nearly finished.

Hopefully over the next couple weeks we'll finish up and we can start the roll out. Stay tuned.

...

Read more

There are no comments on this post.

Python on Windows: How to get network protocol statistics

Just something I was playing around with today that I thought I might share.

I was curious about how to get network statistics in windows so I've been reading MSDN all day trying to work it out. I've written a little bit of python using the ctypes module to access the API on network statistics. All I can say is that doing these things on Linux is so much easier as you can just access the /proc directory and parse the system files there that contain such information.

...

Read more

There are no comments on this post.

Adam Internet Usage Meter (for onpeak/offpeak)

I wrote a bandwidth-usage Dashboard Widget for Adam Internet a while ago. They have since changed their quota system to use "onpeak" and "offpeak" quotas, breaking my old Widget. I've now updated it for the new system.. I may create a nicer widget at some point, the current code is a bit of a mess, and I have an idea for presenting the on/offpeak data better...)

Admittedly there's probably around zero other Adam Internet customers reading this, but it should appear in search engines, should someone be looking for such a widget..

Anyway, how it looks:

...

Read more

There are 2 comments on this post.

My microcode decoder design

Months ago I was required to design and model some part of computer system architecture. I decided to do a very small microcode processor.

For those who are unfamiliar with microcode allow me to explain the significance. In computer system design there are two approaches to designing instruction decoders. The first is called the hardwired approach. For each possible instruction in our instruction set the decoder designers spend a lot of time with truth tables. Each bit in the instruction is mapped through logic pathways to produce an appropriate result on the processor control lines. This is a very efficient decoding approach as instructions are decoded extremely fast. The problem is that if you change the instruction set or even modify the components in the processor, the decoder will need a complete overhaul. This becomes expensive.

The second approach is called microcoding. Here we design a dynamic instruction set that can be reprogrammed (called microprogramming believe it or not). The idea is that we store the entire instruction set and the values of each control line in a very small very fast memory device. When an instruction enters the decoder, the decoder simply looks up the values of the control lines for the input instruction and writes them out onto the bus. This is not as fast as a hardwired approach because memory devices have much greater latency than logic gates however it makes changing the instruction set (adding, removing or modifying instructions) very easy. We don't have to spend a lot of time completely redesigning the decoder whenever we add, remove or modify other components in our system. We simply reconfigure the decoder to behave differently when it receives an instruction.

...

Read more

There are no comments on this post.

The Jeff Sterling Show: When Jeff met Bob [video]

Short film my brother and I made over the last few weekends. Shot on my new Canon 5D Mark II

...

Read more

There are no comments on this post.

tvnamer 1.0

As the "final commit" mentions, 387 days and 330 commits after the I started, tvnamer and tvdb_api are at a point where I'm happy to release "version 1.0"!

tvnamer is probably of most interest, it's an automagical TV episode renamer, turning files from "some.show.s01e01.hdtv.blah.avi" to "Some Show - [01x01] - The Real Episode Name.avi", using information from thetvdb.com

To install, simply do..

...

Read more

There are 2 comments on this post.

Diffie-Hellman-Merkle key exchange in a nutshell

This is a simple Python implementation. Note the global variables p and a should in general be re-generated each pass. p is any prime and a is the primitive root of p.

...

Read more

There are no comments on this post.

Stop iTunes after current song

Something I always missed from Foobar2000 is the option to "Stop playback after current song"

For some reason it never occurred to me it would be trivial to write an AppleScript to mimic this for iTunes..

tell application "System Events"
    set cur_app to name of the first process whose frontmost is true
    set visible of process cur_app to false
end tell

...

Read more

There are 2 comments on this post.

Pages: 1 2 3 4 5 6 7 8 9 10 11

RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.