Tiny Linux Hacks

Occasionally I learn to do things a little smarter with linux.

A Nicer USB Eject

A personal quirk but I really don’t like having USB-mounted drives display in the Ubuntu launcher (Precise Pangolin).  However, if you disable the display in the launcher, it can be a pain to unmount a USB drive.  However, there is a handy ejecter app which will display an unmount utility in the system bar at the top.

So first install the compiz setttings manager which will allow you to disable the display of mounted drives in the launcher:

sudo apt-get install compizconfig-settings-manager

and then launch compizconfig, click on Desktop, then Ubuntu Unity Plugin to the right, then the Experimental tab and look for Show Devices and set that to Never.

Now install ejecter:

sudo apt-get install ejecter

Now whenever you have a usb drive mounted, you will see a little icon in the system tray that will allow you to eject it gracefully.

What is chewing up my bandwidth?

Occasionally my laptop appears to chew bandwidth for no reason.  Getting to the bottom of that can be tricky.  Here are some useful programs to do that.

# nethogs

will tell you what program is the bandwidth hog e.g. skype but it won’t tell you specifically where it is coming from or what process is involved. To find out more, try:

# lsof -i tcp -sTCP:ESTABLISHED
# pktstat -t -i wlan0
# iptraf
# iftop -p -i wlan0 -P
# netstat -tunp or -tup

None of them are overwhelmingly intuitive and I am still working out which one works best for me.  Obviously substitute your port for wlan0 in the abovfe.

Follow-up:

Of the above I have found that

# iftop -p -i wlan0 -P

works the best for me. Sometimes you want to know which app is chewing up your bandwidth but often enough these days it is one of the many open browser pages you have so pointing to chrome or firefox is not that helpful. iftop identifies the site where the bandwidth usage is coming from. That seems to work best for me.

Great applet for external monitors

Oneiric Ocelet was a bit of a setback when it comes to managing external monitors, especially for my X201.  Happily that problem has been sorted but Ubuntu still doesn’t make it seamless to switch back and forth between external monitor and laptop screen.  But now they don’t have to because there’s the Jupiter applet.  

Wordpress Visual Editor Disappearance

I have a few wordpress blogs and they all starting having problems with the availability of the visual editor.  It stopped working completely.  Then the HTML editor stopped working as well.  Trolling the wordpress forums was disheartening as it appears that this can be caused by any number of things from, caching problems, to rogue plugins, etc.  In my case, it turned out to be Cloudflare.

Cloudflare offers great caching features for wordpress but one of the features, the auto-minify option seems to cause problems with the visual editor.  Rather than disable it, I was able to take advantage of Cloudflare’s new rules editor which allowed me to disable cloudflare for the admin area of my blog.  Just enter

yourdomain.org/wp-admin/* 

into the Cloudflare rules and your Visual Editor should come back to life.

Compressing PDFs

Often I find myself with PDFs that are inexplicably large for what they are.  Magento, for example, produces invoices that are 1Mb in size when they need only be 50Kb.  Ghostscript to the rescue.  It can compress any PDF to a variety of resolutions.  See the following:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

-dPDFSETTINGS=/screen (screen-view-only quality, 72 dpi images)
-dPDFSETTINGS=/ebook (low quality, 150 dpi images)
-dPDFSETTINGS=/printer (high quality, 300 dpi images)
-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)
-dPDFSETTINGS=/default (almost identical to /screen)

I find the ebook setting works fine for most documents

Handy search hack

I find most search tools don’t think the way I do.  Mostly I can roughly remember the name of the file or at least parts of it and what type of file it was.  Thus I want to be able to search for various text snippets that I know were in the filename even if I didn’t remember the right order or dashes, underscores, etc.  This little function does that for up to three snippets e.g.  ”srch pdf microsoft spectrum” would find me that Microsoft report on spectrum re-use.  You get the idea.  Just stick the code below into your .bashrc file.  I use this all the time.

function srch(){
  if [ $3 ]; then
     locate -i $1 | grep -i $2 | grep -i $3
  elif [ $2 ]; then
     locate -i $1 | grep -i $2
  elif [ $1 ]; then
     locate -i $1
  else
     echo "You must enter a search parameter\n"
  fi
}