Multiuser screen

June 15th, 2011 § 0 comments § permalink

To make a screen multiuser:

-a : multiuser on

You can also include _multiuser on_ in .screenrc to make all screens start multiuser

Then you connect to it with screen -x

Removing whitespace with sed

May 17th, 2011 § 0 comments § permalink

Use sed to remove leading whitespace:


sed 's/^[ \t]*//'

The particular reason I want to do this is to turn my todo-list (a tree of tasks, marked off by when i completed them), into a sorted record of what I’ve done on a particular day. In other words, I want to go from this:


Code
Thule
OED javascript
other tasks
2011-04-17 16:57:33 Sort out markdown for vim 45m
blah
Thing I haven't done

To this:


2011-04-17 15:58:32 update blog with more cmds 3m
2011-04-17 15:58:59 modify timestamp to include date 20m [,,T,,D wil do for now]
2011-04-17 16:57:33 Sort out markdown for vim 45m
2011-04-17 17:39:04 [email to ejc about resources for journalists

Which can be done by removing whitespace, limiting to lines containing dates, and sorting


$ cat todo/todo.otl| sed 's/^[\t ]*//' | grep 2011 | sort

mode function in python

May 16th, 2011 § 0 comments § permalink

Oddly, there seems to be no mode function in the python standard library. It feels like something that should have an optimized C version squirreled away somewhere. ‘Mode’ is too ambiguous to be easily searchable, alas. Anyway, here’s a version that should be reasonably fast

from collections import defaultdict
def mode(iterable):
    counts = defaultdict(int)
    for item in iterable:
        counts[item] += 1
    return max(counts, key = counts.get)

Should be reasonably fast (for pure-python), though could eat up a lot of memory on an iterable contaning large items.

following irc with inotail

May 6th, 2011 § 0 comments § permalink

Being always in a several irc channels, it’s helpful to have an overview of what’s going on without tabbing through a dozen windows. Fortunately I can follow the logs using inotail:


$ find /home/dan/.purple/logs/ -name "`date +%F`*" | xargs inotail -fv

This would also work with tail — the only problem is that _tail_ with so many files would put some strain on the filesystem.

Getting server messages via irc

May 6th, 2011 § 0 comments § permalink

irccat is a bot designed to facilitate sending server messages to an irc channel

The irccat bot joins all your channels, and waits for messages on a specified ip:port on your internal network. Anything you send to that port will be sent to IRC by the bot. IRCCat – as in, cat to IRC.

Using netcat, you can easily send events to irc from shell scripts:

echo “Something just happened” | nc -q0 somemachine 12345

That will send to the default channel only (first in the config file). You can direct messages to specific combinations of channels (#) or users (@) like so:

playing mp3s in orer

May 4th, 2011 § 0 comments § permalink

I often use mplayer to play all files in a directory:

mp ./*

*mp*, by the way, is simply an alias for mplayer, used to play things faster and with speed control:


$ which mp
mp: aliased to mplayer -speed 1.21 -af scaletempo=speed=tempo

But what if I want to play them in date order? (useful to replay a stream with streamripper). I need a shell loop. A for loop will choke on filenames with spaces
:


$ for i in `ls -tr`
do
mp "$i"
done

A while loop seems to give me some problem of mplayer reading too much from stdin:


$ ls -1tr | while read i
do; mp '$i'
done

So I end up using an array:


$ mp3files=( ./*mp3 )
$ for d in "${mp3files[@]}"; do
mp "$d"
done

phew! that was far too much work

open matching in vim

April 18th, 2011 § 0 comments § permalink

To open in vim all files matching a regex:

$ grep -l foo ./* | xargs vim -p

Where Am I?

You are currently browsing the snippets category at Dan O'Huiginn.