2 ways to fight spam on twitter

I absolutely adore the popular new microblogging service, twitter. But lately, it's been overrun with spammers. I'm sure many of you are as unhappy as I am to see such a promising and exciting new service despoiled, so I'd like to share a couple tips I've picked up along the way, on how you and I, how we, can help combat this.

  1. Twitter has an @spam account for reporting spam. When you see spam, simply RT is to @spam. Sometimes they can be slow to respond, so if you don't get a response after a few minutes, you can RT it again.

  2. Particulary egregious spam needs swift action. If a spammer is being especially horrible, RT their tweets to all your friends and followers, encouraging them to RT to @spam. Muliple offended parties will more quickly get the spam fighting team's attention - it may even become a trending topic, where it can easily gain momentum and be noticed. This is highly effective.

Please pass this along to others and do your part to decrease the volume of spam on twitter, and keep it the wonderful place @where we #blog.

bash cd with sed

Tinkering around with something today, cause I end up in directories like:

/client/company1/archive/in/837

wanting to go to

/client/company2/archive/in/837

I wrote it a few ways - so far I think I like this the best. So yeah, with this function in my .bashrc I can say

s company1 company2

to sed pwd and do that directory hop.

# cd with sed
# example:
# /usr/lib/foo$ s lib src
# /usr/src/foo$
s() {
 local cd="$PWD"
 if [ "$1" = "--complete" ]; then
  awk -v q="${2/s /}" -v p="$PWD" '
   BEGIN {
    split(p,a,"/")
    for( i in a ) if( a[i] && tolower(a[i]) ~ tolower(q) ) print a[i]
   }
  '
 else
  while [ $1 ]; do
   cd="$(echo $cd | sed "s/$1/$2/")"
   shift; shift
  done
  shopt -s cdspell
  cd $cd
  shopt -u cdspell
 fi
}
complete -C 's --complete "$COMP_LINE"' s

It takes pairs of arguments and seds arg to arg+1. The shopt stuff fixes some typos - I dunno why I don't like it enabled all the time - but I feel like it has a bit more panache than just a [ -d "$cd" ] && cd $cd.

(Updated to add tab completion)

python detecting cjk
def cjk(str):
    '''
    rudimentary CJK detection
    seems like a lot of it is between these two ranges.
    cf. http://www.alanwood.net/unicode/fontsbyrange.html
    '''
    ranges = [(12272,12287), (19968, 40959)]
    for i in str:
        j = ord(i)
        for (low, high) in ranges:
            if j > low and j < high:
                return True
    return False
bash serve localhost through NAT

I saw localtunnel the other day, and being how I am, wanted something similar, but simpler and under my control. Turns out it's basically a shell one-liner. I've wrapped it in a nice function here:

# tunnel a local port to a (random) remote one
# requires 'GatewayPorts yes' in sshd_conf on the remote host
doink() {
    [ $1 ] || { echo "usage: doink <host> [port]"; return; }
    local port=$(expr $RANDOM % 16384 + 49152)
    echo "serving localhost:${2:-80} at $1:$port"
    ssh -N $1 -R $port:localhost:${2:-80}
}

It forwards a port (80 by default) to a random high-port on a remote machine over ssh. The only issue is you have to have GatewayPorts yes defined in sshd_config, which is not the default. But then something like doink example.com would serve your localhost's port 80 at http://example.com:someport.

mplayer lastfm

Here's a little mplayer wrapper that submits to lastfm using lastfmsubmitd. There's a shell version of this floating around, I rewrote that in python. Something like:

for x in *.mp3; do lmp "$x"; done

works nice.

lmp : python (@github)