.bashrc Fun With Subversion

Do you use Subversion a lot from the command line in bash? Then this tip is for you.

Add the following to your .bashrc

# svn completion
_svn ()
    local cur prev
    if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
        COMPREPLY=( $( compgen -W 'add blame cat checkout cleanup \
        commit copy delete diff export help import info list lock \
        log merge mkdir move propdel propedit propget proplist \
        propset resolved revert status switch unlock update' $cur ))
        COMPREPLY=( $( compgen -f $cur ))
    return 0
ccomplete -F _svn -o default -X '@(*/.svn|.svn)' svn

Save your .bashrc, source it (using source .bashrc) and now Subversion commands will complete. For example, enter svn upd press the Tab key and you'll get svn update.

Think of all the keystrokes you'll be saving.

Update: I just found Subversion's own bash completion script which has a ton more options. Mine is easier to maintain. :)

Add a comment
Category: shell Tags:

Got Ugly SQL?

SQL Formatter screen shot

Sometimes you have a bunch of SQL statements that are very long, very verbose and very unreadable. Would you spend minutes of your time to format the SQL in strings so that it's readable? Would you paste the ugly SQL in your source code letting some future maintainer try and decipher it? Well, I'm about to save you a metric ton of time as well as your reputation with maintainers of your code. Use SQL Formatter and it'll do all the grunt work for you.

It's bloody easy to use. Just Accept the usage agreement, paste in your offending SQL statement and choose the formatting and output you want. Bingo! Nicely formatted SQL. You can even choose to format it as a string in the language of your choice so you can just copy and paste it into your source.

If you don't feel comfortable using an online tool, there's a desktop version that's postcardware.

Give it a whirl!

Add a comment
Category: programming Tags:

Keeping It Real Safe And Real Easy

Subversion logo

OK, I've fallen in love with putting my home directory in Subversion. The benefits are enormous. They include (but are not limited to):

  • ease of setting up environment on new system
  • backup
  • ability to go “back in time” using Subversion tags

Mind you I don't put everything in there, just the important stuff like my shell configuration files and my vim configuration files. Other important files (like pictures and music I spent ages ripping) are backed up in other ways.

Here's what I currently have saved in svn:

$ svn ls http://my.svn.server/svn/home-dir/trunk/

So now when I'm on a system, I'll have the same look and feel and same functionality as the utilities I use will be available in my ~/bin directory.

For those astute readers, you'll notice that I don't have a .vimrc file in there. That's because I'm using an excellent tip from Amir Salihefendic about taming your vim config. Basically on each system I have a specialized but simple .vimrc that sources the vim_local for what it needs.

I've found this setup works great on the many different systems I use throughout a given week (e.g. Windows, Mac and Linux). And I'm safe in the knowledge that my configuration files won't disappear should my machines suddenly implode.

Add a comment
Category: tools Tags:

Debugging Is Sexy Good Times

I love me some JSON. The problem with it is that it's not too human readable when you need to see what it's returning. Sure you could litter your code with alerts or console.debug (if you are using Firebug and Firefox to figure out what values are you getting back.

But if you've got the Firefox/Firebug setup (and why don't you if you don't?) then you can just use the Firebug console to display the JSON data. Say for instance you have the following data returned from your service (but imagine it's a bazillion lines long):

               "SubObject": {"SubAttrib1":"bar"}

Just wrap that in an eval function, plug it into the console and you get back a nice little tree of your data in the DOM view.

console screencap

Now isn't that sexy?

Add a comment
Category: programming Tags:


Hello and welcome to sethmason.com. This site is basically an experiment to set up a site that's a resume of sorts. It will feature articles about technology that reflect my depth of knowledge.

The site itself is set up using TextPattern. Normally, I would eat my own dog food and use a Java based content management system but I wanted to give PHP and Textile a test. So far, I'm impressed.

For more information about myself, check out my about page. And feel free to leave a comment.

Add a comment
Category: personal Tags:

Writing Tests For Fun And Profit

Learning a new programming language historically starts off with the classic “Hello World” example. I've probably written a variation on that a bazillion times. From there you take more steps into advanced parts of the language. If you are smart, you save your example programs to refer back to them later. But there's a better way. And that better way is to write test cases that exercise the capabilities of the language you are trying to learn. This also works for new libraries within a language you are trying to learn.

The advantages of writing test cases are plentiful. It gets you writing actual code which helps you remember, they can be usually be run easily, they serve as an extra source of documentation about what you are trying to do (e.g. “How do I use gsub again? Oh yeah, it's in that string test I wrote?”) and finally writing tests is fun.

An Example

After ignoring it for way too long, I recently started trying out the Yahoo! User Interface Library. It's a JavaScript library with scads of useful utilities for buidling web applications. So, I pulled up the documentation and started writing a tests based on what's documented. Since it's JavaScript, I used JsUnit since I'm used to JUnit on the Java side of things. And voila we have our first test:

    <title>Test Yahoo</title>
    <script type="text/javascript" 
    <script type="text/javascript" 
    <script type="text/javascript">
        function testIsArray() {
    A test document.

(I know it's very simple but I just wanted to get a feel for the first method in the global library and type it so my brain remembered it.)

So, now I drop the test file into my test runner and here we have the results:

It's all green!

Can't you just feel your brain expanding with the possibilities?

Add a comment
Category: programming Tags:

© Seth Mason 2014

Themed using aboutwilson

Powered by Pelican