Category Archives: programming

Deluge Toggle – the world’s simplest Deluge client

I’ve recently been using Deluge to download torrents, thanks to froztbyte’s recent blog post. It seems to work very well, especially when combined with FlexGet for handling RSS feeds of torrents.

My torrents are downloaded by my desktop machine, which shares bandwidth with the rest of the devices on my network – my phone and my laptop, generally. I prefer the torrents not to use any bandwidth while I’m home, to free it all for whatever else I want it for.

Deluge offers scheduling, which is fine for weekdays – on almost any weekday the torrents can happily download during working hours and sleepy time. However, our weekends can vary wildly between home all weekend and barely home at all – it seems wasteful to schedule no downloading for the non-sleepy hours of the weekend on the off chance we’ll be home.

The Toggle plugin offers a better solution for my use-case – it stops all Deluge bandwidth usage when toggled. It integrates into the Deluge GUI and web clients.

However, I have found the web client to be quite slow and clunky on my phone, which is the primary device I want to use to toggle Deluge’s bandwidth usage – generally when I wake in the morning and go to bed at night. This is quite possibly my phone at fault, but it does make toggling Deluge’s bandwidth usage annoying, since I often need to use my laptop or the desktop machine.

Accordingly, I have written what I would imagine is the world’s simplest Deluge client: deluge-toggle. The client either reports what the current toggling status is, or toggles the bandwidth usage. That’s all it does, but that’s exactly what I needed.

I have also written an incredibly simple Flask webapp to interact with the deluge-toggle client, to save me having to use a console from my phone. I run this webapp on my desktop machine, and can now easily toggle Deluge’s bandwidth usage from anywhere that I can connect to my home network.

All of this is very simple, but it does say complimentary things about Flask and Deluge (particularly its plugin system) that this was as simple as it turned out to be.

Leave a Comment

Filed under computing, programming

Yet another post from someone admiring an Emacs feature

I’ve been using Emacs for some time now, and I’ve grown to really appreciate it. One of the nifty features introduced in Emacs 22 is the ability to execute arbitrary elisp when replacing text using regular expressions (elisp is the Lisp dialect in which Emacs itself is written and through which it can be extended). I had reason today to use the feature for a silly little problem, and I was impressed, so here’s why.

I had a set of data where I had to replace a placeholder on each line with an integer, which incremented every four lines, starting at 2. i.e:

x line 1
x line 2
x line 3
x line 4
x line 5
x line 6

should become:

2 line 1 
2 line 2 
2 line 3 
2 line 4 
3 line 5 
3 line 6

This would be quite tricky to solve with a normal regexp replace operation, but under Emacs I simply defined a new function to do the hard work:


(setq mod_id 1)

(defun four_inc (y)
        (if (eq 0 (% y 4)) (setq mod_id (1+ mod_id)) mod_id)
)

I evaluated those two pieces of elisp in place in the scratchpad I was working in (another massively nifty Emacs capacity) and then ran a regular expression replacement, replacing x with \,(four_inc \#)). The \, tells Emacs to insert the result of calling the four_inc function into the replacement text, and \# is the number of replacements already done.

This is hardly earth-shattering stuff, but it’s the ability both to extend Emacs however one desires (by writing an increment-every-4-times function in this case) and the heaps of nifty features other people have already provided (executing arbitrary elisp code in a regexp replacement for example) that explains to a large degree why I like Emacs so much.

Leave a Comment

Filed under computers, elisp, emacs, programming, Uncategorized