2010-11-01

to title case, at the shell

This filter turns the input into "Title Case".

cat [whatever] \
| sed 's/.*/\L&/; s/[a-z]*/\u&/g'

Courtesy of this post.

2010-08-26

Python string concatenation

Looks like the fastest way to assemble your strings, in general, is by generating lists and then calling '{separator}'.join ({string list}), according to Oliver Crow.

2010-05-12

Boost, Autoconf configure error

After upgrading tu Ubuntu 10.04, I started having a problem using an Autoconf-generated configure script to detect the Boost libraries. Ultimately, the problem turned out to be that the libraries just were not installed anymore! Here's what the configure output looked like:

checking for boostlib >= 1.38.0... yes
checking whether the Boost::Filesystem library is available... yes
configure: error: Could not link against  !
Note the two spaces before the "!". That's where the library name should be, if it were even found. So apparently I had the headers left over somehow, but the library had been uninstalled. Something to keep in mind if you see such an error...

2010-04-19

Extract a single file from a tarball

If you've got a tarball with a particular file that you want to extract to standard output, use a command like the following:

tar zxf0 {the tarball} {path to desired file within tarball}

2010-03-11

Gnuplot Histogram

If you want to bin data in Gnuplot, something like this should work (taken from a mailing list):

bw = 5   # substitute what you want 
bin(x,width)=width*floor(x/width) 
plot 'data' using (bin($1,bw)):(1.0) smooth freq with boxes

Screen Scrollback

In screen, it's easy enough to set up a scrollback history buffer of the desired length (although I forget exactly how to do it). But it's not obvious how to scroll the window back. You need to use copy mode. Assuming 'C-a' is your screen hotkey, use 'C-a ?' to check for the keyboard shortcut.

For me, you can enter copy mode with 'C-a [', after which you are free to move the cursor around, which scrolls the window. It looks like normal Vi or Emacs shortcuts are fine for scrolling. You can cancel copy mode and go back to the bottom with 'C-c'; or you can press space, scroll elsewhere, and press space again to highlight and copy text and then go back to the bottom.

2010-03-04

Concatenating Images with ImageMagick

It turns out that it's very easy to concatenate images with ImageMagick. For example,

montage +frame +shadow +label -tile NxM -geometry +0+0 *.jpg joined.jpg
where N is the number of tiles across and M is the number of tiles down. Courtesy of Curioso.

2010-03-01

xclip on Ubuntu

In an earlier post (Shell tidbits) I gave a script that uses xclip to send the clipboard into a temporary file, edit it in a text editor like gvim, and then put the new contents back into the clipboard when the text editor is closed. Unfortunately, Ubuntu supplies xclip-0.08-8, which doesn't have proper UTF-8 support. This was causing weird artifacts in my e-mails. The issue dissappears completely if you install xclip from the source package available on its SourceForge homepage.

2010-02-27

Making Verizon's website go

You need the following in your /etc/sysctl.conf:

net.ipv4.tcp_wmem = 4096 16384 131072
net.ipv4.tcp_rmem = 4096 87380 174760
Disclaimer: I have no idea what this does, so use at your own risk... like I am.

ffmpeg on Ubuntu

For extra ffmpeg codecs:

sudo apt-get install sudo apt-get install libavcodec-extra-52
To convert from wav to mp3,
ffmpeg -i song.wav -acodec libmp3lame -ab 192k song.mp3

2010-02-10

Shell tidbits

Found reminders of a couple useful scripting tidbits today.

Check the number of commandline arguments in a bash script with $#. Check for a commandline argument containing only alphanumeric values with if test "`echo $1 | egrep -v '\W'`x" != "x".

This stuff is relevant for my edit-in-gui-editor script, which basically lets you edit the clipboard in a text editor like vim. I use it to write e-mails, blog posts, whatever. Here's the whole script.


#!/bin/bash
# open a temporary file in a gui editor with the contents of the clipboard
# you can set the editor to use by setting GUI_EDITOR in ~/.bashrc

# if you specify a commandline argument, it becomes the temp file's
# extension, e.g. 'edit-in-gui-editor html'
if test "$#" = "1"
then
 if test "`echo $1 | egrep -v '\W'`x" != "x"
 then
  EXTENSION=$1
 else
  EXTENSION=".txt"
 fi
else
 EXTENSION=".txt"
fi

# pick the editor to use.
DEFAULT_GUI_EDITOR="gvim -f"
if test "`which ${GUI_EDITOR%% *}`x" != "x"
then
 GUI_EDITOR="$GUI_EDITOR"
else
 GUI_EDITOR="$DEFAULT_GUI_EDITOR"
fi

# make the tempfile
TMPFILE_ORIGINAL=`mktemp`
TMPFILE="$TMPFILE_ORIGINAL.$EXTENSION"
mv $TMPFILE_ORIGINAL $TMPFILE

# do the editing
xclip -selection clipboard -o > $TMPFILE
$GUI_EDITOR $TMPFILE
xclip -selection clipboard -i $TMPFILE

# done!
exit 0

2010-02-02

First Post

Howdy. If you're reading this, then it means you've found my new blog. I guess I just want (need?) a place to post all the random little things I learn at times.

Today's find: in the sudoers file (edited with visudo), NOPASSWD entries must be last. The form of the entry I needed was:

%admin    ALL = (ALL) NOPASSWD: [commands]