Emacs Tips

Since I've been programming more Perl than Java lately, I've started using Emacs as my primary IDE. Been checking out a few sites with tips and tricks to help me along the path of conversion from vi to Emacs. Trey Jackson's blog seems pretty promising.

Hopefully, he can keep up the tip a week format. Allegedly, he has 150 tips so he should be good for 3 or so years.

Add a comment
Category: editor Tags:

Lisp Fun

Interested in learning Lisp? A new site has launched with screencast episodes about developing an application in Lisp. The site is LispCast and so far there are three videos up. It's about building a web application that is a clone of Reddit. The subject of the videos so far are writing it, developing tests and refactoring. They each clock in at about twenty minutes and are quite helpful.

It looks like the creator, one Eric Normand, has some pretty big plans for the site. Let's hope that he is able to do it. I know I'm rooting for him.

Add a comment
Category: programming Tags:

Intellij IDEA and Linux: Not Like Peanut Butter and Chocolate

I love me some Intellij and I love me some Linux. Unfortunately, they don't play too well together. Lots of keyboard shortcuts do operating system commands.

For instance, CTRL+ALT+L reformats your code in Intellij but it never gets a chance to that because that keyboard sequence locks the desktop on Ubuntu. Besides changing quite a few keyboard shortcuts in the administration screen, does anyone have any tips or tricks?

Add a comment
Category: editor Tags:

Editing Huge Amounts of Files Easily

Where I work, we have tons of static html files that are published using our custom built Content Management System. Sometimes, we have to change a single line on every single page. For example, the latest case involved a change involving the size of ads that were on the pages. Rather than use publishing and database resources just to make this relatively simple change, I use the power of the shell. Specifically, I use find, sed and a shell script that I wrote. It's based on a shell script in the Unix Power Tools book.

First off, we need to find all the files. I usually accomplish this with something simple like

$ find /www -type f -name "*.html" -print

This simply finds that end with .html in the /www directory. You can do more complex things with find like find all files modified in the last 2 days by Frank if you needed to change files like that.

The results of this will be passed off to a file named replace.sh located in my ~/bin directory. replace.sh is reproduced here:

echo -n "editing $1: "
if test "$1" = sedscr; then
    echo -n "Not editing sedscript!"
elif test -s $1; then
         sed -f sedscr $1 > $temp
    if test -s "$temp"; then
        if cmp -s "$1" $temp; then
            echo -n "FILE NOT CHANGED: "
            # save original, just in case
            # mv $1 $1.bak
            cp $temp "$1"
        echo -n "done"
        echo -n "Sed produced an empty file \
- check your sedscript".
rm -f $temp

So, the command we would run would now look like this:

$ find /www -type f \
      -name "*.html" \
      -exec ~/bin/replace.sh {} \;

This does the same as above but passes each file found by the find command above to the ~/bin/replace.sh script.

You'll notice that the replace.sh file calls sed using a file named sedscr. The next step is creating the sedscr file.

The sedscr files simple contains sed commands. It must exist in the same directory that you call the find command above from. Here's a sample sedscr that just does a simple replace.


You can enter in as many complex sed commands as you want. It's sed so the power is there!

This simply replaces all instances of BigHonkingAd with NiceSmallAd in each of your files found by the find command. The nice thing about the replace.sh script is that it will not edit the file if the contents of your sedscr don't produce an altered file. Also, if you want the replace.sh to make a backup of your original file, just uncomment the mv line.

Using this methodology, I'm able to edit about 5000 files a minute. It could probably be faster if I used xargs and the output of replace.sh is a little verbose but this solution has worked for me for years and if it ain't broke, why fix it?

Add a comment
Category: programming Tags:

Vim Tip: Select Column

Columns in vim

How many times have you wanted to replace a column of text with something. With vim it's easy. Just use CTRL-V to select a column using a visual block.

Once it's selected, you can do a search and replace, yank, cut and other actions. For example, here's the keystrokes to change a column.

  • Put cursor and beginning of text to select
  • Press CTRL-V to begin select of the column
  • When you reach the end of your select, type 'c'
  • Type the new text. Note that this will only replace the first instance.
  • Now hit <ESC><ESC>. All the text has been changed!

The same thing works with plain old 'v' (select character by character) and SHIFT-V (select by line).

Happy vimming!

Add a comment
Category: editor Tags:

Just Cuz'

OK, I've decided that the next programming langauge I learn is Lisp. I just love all the parenthesis I guess. An excellent Lisp tutorial is Peter Siebel's book Practical Common Lisp.

Fun stuff.

Add a comment
Category: personal Tags:

Command Line Fun

If you use the command line in bash, you should check out the CDPATH environment variable. It'll make your life tons easier.

From the bash man pages, CDPATH is defined as:

The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is “.:\~:/usr”.

In my .bashrc, I've got the following defined: CDPATH='.:..:../..:~/projects'

This allows me to just type cd app when I want to go to ~/projects/app. Another great part of it is that if I am in /var/log and want to go to /var/www I only need to type cd www. The .. in the CDPATH takes care of finding it.

The important part of it is the first one. The single period allows for cd to work normally and find directories in your current directory.

Add a comment
Category: shell Tags:

Ten Keyboard Shortcuts for IntelliJ IDEA

IntellJ Shortcuts

For my day job I use Java quite a bit. And to edit I use IntelliJ IDEA. I used to use Eclipse but work paid for an IntelliJ IDEA license and I've become hooked. The refactorings and clean interface are a boon to my productivity.

Well this post isn't an IntelliJ IDEA fanboy post so let's get back on track. Here's a list of shortcuts that I find most helpful for use with IntelliJ IDEA. Note that these aren't the obvious ones (like Alt-Space for code completion). These are some hidden ones that you might not know about it.

Comment out the selected lines with //.
Copy the current line and paste it.
Delete the current line.
Delete to word end from cursor.
Delete to word start from cursor.
Select the current word. Press it again and it selects more of the code block.
Run the configuration
Debug the configuration
Find usages of the current word
Bring up the Live Template context menu. If you don't know about Live Templates, you can save major keystrokes by defining them.

For a complete list of keyboard shortcuts for IntelliJ IDEA, there's a PDF issued by JetBrains floating around.

Add a comment
Category: editor Tags:

Linux Cut and Paste

Linux logo

Since I'm in the process of switching to Ubuntu I've been hunting down tips and tricks. One great resource is the Ubuntu Blog. Today they had a great tip for copying and pasting in GNOME.

Basically, what you do is highlight the text in one application (for example Firefox), switch to another application and then click the middle mouse button where you want the text to show up. Your highlighted text is now exactly where you want it. If you don't feel like using the mouse, you can use Shift+Insert in the second application to paste the text.

Add a comment
Category: shell Tags:

Cygwin And SSH Tip

cygwin logo

Auto completion for ssh under cygwin was driving me nuts. It wasn't parsing the ~/.ssh/known_hosts file like it should have and using those values to auto-complete. Investigating, (by using ssh -v) I found out that my known_hosts didn't exist in ${HOME}/.ssh and ssh was using the one in C:/Documents and Settings/smason/.ssh. Uh, excuse me? My $HOME is /home/smason. I cd ~ and I'm in /home/smason. Bafflement ensued.

Turns out my /etc/passwd was all mucked up. It had my HOME directory set to the one in my Documents and Settings directory. I manually edited my /etc/passwd and now ssh auto completion works.

Wow, the second post in a row dealing with auto completion. I guess I really like auto-completion. Think of the keystrokes I'm saving you!

Add a comment
Category: shell Tags:

© Seth Mason 2014

Themed using aboutwilson

Powered by Pelican