Sunday, February 5, 2012

A couple of nice VIM tricks

0 comments
I really like VIM. I'm used to it and it's fast, flexible, and powerful. Once you learn how to extended it VIM opens up many new avenues to productivity.

This is a really basic trick but it's powerful. It's one of those that I spent a long time wishing vim would do only to learn that "IT COULD" do exactly what I wanted it to do!

One of the complaints about console text editors is that they don't scroll using the mouse wheel. VIM is not one of those. If you add this to your .vimrc file:

if has('mouse')
set mouse=a
endif

Vim will use the mouse wheel to let you scroll through the file you are working on!

If you code in python these next two tricks will be a big help. I work on all sorts of projects and once in awhile I'll get a file that uses spaces for tabs. I'm currently using tabs for everything because that's the standard where I work. But if I pick up a PEP8 compliant file then I'll get spaces. So to do a quick conversion while I'm in the file I put the following settings in my .vimrc:

map :%s/ \{4}/ /g

That will convert all spaces to tabs in command mode. Just reverse it or use another f key or key combination if you want to go from tabs to spaces.

This last trick is especially for python folks. Sometimes extra spaces will creep in between some text and your tabs. The interpreter doesn't like this at all and will make your life difficult by not compiling your file. If you have a space before a tab you can use this vim trick to highlight the spaces so that you can easily find them.

"Mark trailing whitespace and spaces before tabs
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
set listchars=tab:>-,trail:.,extends:>

Be a little careful with this one because some themes you choose or syntax files will make this silently fail.

All the best.

Monday, March 28, 2011

fping -- A nice addition to the networking toolbox

0 comments
I work in a networking environment and so I've been looking for tools to do quick jobs without having to go out and get an SNMP setup going. One of the tasks I have is occasionally tracking down a device or router by it's MAC address.

The great network utility nmap will do it but for a quick job I found fping http://fping.sourceforge.net/.

In order to find out the IP of an errant router by its MAC address you use arp -a or arp -n to look in your ARP cache. In order to get it in there you can write a script to ping every host in a subnet or you can use fping.

$ fping -c 1 192.168.0.0/24

This will rapidly ping the subnet filling the arp cache with the IP to MAC address mappings.

Then you can use (depending on your arp implementation, mine is a Debian variant)

$ arp -n

To print out a list of IP's and MAC addresses.

You may have to use

$ arp -a

To make things go a little faster if you have a big list you can grep for the last few digits of the MAC

arp -n (or a) |grep -i 863b2

You'll get your IP and you won't have to go sniffing with the very capable but complex tool wireshark or some similar.

All the best!

Saturday, November 6, 2010

VirtualBox

0 comments
It's difficult to be around tech these days and not have heard about virtualization. VirtualBox http://www.virtualbox.org/ is one of the products that brings virtualization to the desktop.

I used to use VMware player. Once I was introduced to VirtualBox I switched all of my systems to use it. It's easy to install and manage and you get a great range of capabilities with the one product. VirtualBox has a great community of users that makes getting support relatively easy. It runs on most all popular platforms and extends your capabilities as a tech professional.

I run Ubuntu 10.04 LTS as my host system with Virtualbox running Win 7, two installs of Win XP pro, Fedora 14, CentOS6, Linux Mint, Open SUSE, and most recently Free BSD. I use these virtual machines to test scripts, applications, and browser comparability with web application that I'm developing. I also use them to develop and test platform specific deployments of server side products.

In addition to test environments I use virtual machines to give me some capability that another OS or distribution can't, and I'll just try out some new tech toy or tool that I couldn't do easily without having access to a full boot partition or even another box. For instance, I'm trying out Linux Mint with XFCE.

Coupling all of the base capability to the great tools the VirtualBox folks deliver in the guest additions and then capping it off with seamless mode the software opens up many learning and professional doors that would be difficult or expensive without access to the virtual machine.

Give it a try. I'm sure you'll get a kick out of it!

Friday, November 20, 2009

Mrxvt: for those who want more in less space

0 comments
This wonderful tool is familiar to the *nix advocates out there who use Konsole on KDE. But if you are a windows guy and take up cygwin you are in for a treat. Mrxvt gives you a tabbed interface that helps you save screen real estate and makes it easy to manage the ui's appearance. I like to run it in cygwin in multiwindow mode so that it sits side by side with windows apps. If you like Konsole or that sort of app then mrxvt is for you.

If you haven't tried it, get cygwin then ./configure;make install after you down load it. Very very cool.

mrxvt http://materm.sourceforge.net/wiki/Main/Download

Multitail: one that is hard to live without

0 comments
In the realm of utilities this one is a jewel. Multitail lets you set up colorized log following that can be done via ssh remoting as well as on the system. The newest version is absolutely killer when you build it on your cygwin and then you can point it at any number of systems.

If you have a second monitor run multitail in a big rxvt window and you can watch all the logs you'd ever want to watch.

I like multitail because you can capture the output of any program you write as a filter and multitail itself has several great filters. Its a very very useful tool. Probably one of the very best going.

Multitail http://www.vanheusden.com/multitail/

Cygwin

0 comments
To me this is the quintesential windows tool. It gives you nearly all of the unix/linux shells and tools. The real power of cygwin is that you not only get most all of the *nix functionality you can think of but you also get a great windows scripting tool in the perl, python, php, and shells. Because this is basically a windows program that acts like a *nix machine you get the best of both worlds and can do cross overs of the two.

As a bonus you get a windows compiler, ALL of the scripting languages and editors you can think of. You get both an apache 1 and apache 2. I usually will install openssh, openldap, and all of the clients for these tools so that I can ssh over to my windows box and authenticate using LDAP. Its a very nice setup.

Cygwin comes with a very nice set of windows managers for Xwin. I like the openbox or windowmaker (wmaker) managers. If you are a glutton for punishment and have a lot of ram on your box you can download and install either KDE or Gnome for cygwin. They are really slow in that environment and rely on the GTK libs from Trolltech. Sort of nice when you want to run a utility like Valgrind (mentioned later).

I consider Cygwin an essential tool. cygwin http://www.cygwin.com/