emacs tip of the week #3: ido-switch-buffer

Hopefully you are already using ido or something similar to enhance emacs tab completion.

I only use ido-switch-buffer ((ido-mode ‘buffer) in .emacs) as I dislike ido-find-file. What I don’t like is accidentally typing \C-x\C-b for buffer-menu-other-window (or whatever it is) when I meant \C-x b. So I put this in .emacs:

(global-set-key "\C-x\C-b" 'ido-switch-buffer)

 

list comprehensions and any in python

One reason I like python is the functional aspects to it.

Recently working on my command line email checker imapchkr I wanted to find out if any account object had a new mail count > 0. I had a list of these objects (which are actually namedtuples). This was neatly done with a list comprehension and any:

if any([msg.unread > 0 for msg in counts]):
    # display the messages

 

simple is better

Keeping things simple (and independent) is very important in my opinion. But since it is often faster (at the beginning), and especially needs much less thinking and experience to make things unnecessarily complex, that’s unfortunately what most people do… So, the purpose of this site is to show some “simple alternatives”—or at least some “things”, where I tried hard to (a) keep them simple and (b) split them into independent parts.

Source: simple is better

Monitoring packet loss on your home internet connection

  1. Get a raspberry pi, install raspbian on it and put it on your home network
  2. Install smokeping (apt-get install smokeping)
  3. Configure smokeping (edit /etc/smokeping/config.d/Targets) so that at least one of the targets is a stable internet host (eg Google DNS 8.8.8.8). Restart
  4. View http://rasp-pi-ip/smokeping/smokeping.cgi
  5. Get sad results like the below 🙁
smokeping screenshot

smokeping screenshot

Simple example of using the threading Timer class in python

[cc lang=”python”]
#!/usr/bin/env python
# simple example of threading.Timer in python

import time, threading

class Counter(object):
def __init__(self, initial = 0, update_interval = 5):
self.counter = initial
self.update_interval = update_interval

def inc(self):
self.counter += 1
# Timer only runs once so call recursively in inc()
threading.Timer(self.update_interval, self.inc).start()

a = Counter()
b = Counter(50, 10)
c = Counter(1000, 1)

for ct in (a, b, c):
# increment counter and start timer thread in each object
ct.inc()

while True:
# loop forever
time.sleep(1)
print “%s %s %s” % (a.counter, b.counter, c.counter)
[/cc]