Favourite hammers

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Favourite hammers

Postposted on Mon Jan 23, 2012 3:13 pm

As in "... everything looks like a nail"

If you're anything like me, you have a couple of programming tools you use more often than most, or try to use over some other solution, because they're just that awesome.

Some linux-based ones to start you off:

Since I spend a fair amount of time writing scripts to co-ordinate starting/stopping processes, or rewriting someone else's script to make it a bit more generic and remove any magic, one of my favourites has to be dirname. Putting cd `dirname $0` at the top of your script means you suddenly don't have to worry about where you are when you run the script. You don't have to worry about "will it start in the right directory when I run it under cron?" It just works. Before I discovered this one, I had a giant case statement in base based on hostnames, to cd to the right location. Ugh.

The thing I try to find excuses to use more often, is inotify. Whenever we have a problem to solve that involves the filesystem, someone always decides the best way is to set up a job to run at some handwavy number of hours after the thing is supposed to have finished, and it'll all just work. Until that thing gets more complicated and you start having to move things around that you no longer understand six months later. And don't even get me started on trying to minimize periodic downtime when these things are involved. Inotify gives you an event "watch descriptor" and tells you when an event you have subscribed to happens on a directory. We recently had a task where we receive some daily data and need to copy it to another directory with a modified name, then synchronize that directory to a couple other servers. Of course, the "5 minute cron job" idea came out. Shortly after calming down, I discovered that someone has written inotifywait, an inotify interface for terminals, all packaged up in an RPM. Learning the interface, piping that into a while loop, getting the renames I needed to do on the files right, and running the rest of the logic sorted took a couple of hours from dev to running code.

Discuss :-)
Living proof of John Gabriel's theorem
IntelMole
Grand Gerbil Poohbah
 
Posts: 3529
Joined: Sat Dec 29, 2001 7:00 pm
Location: The nearest pub

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 4:22 pm

I probably abuse the sed tool and recursive shell scripts... not quite as obfuscated as Perl, but heading there! :lol:
(this space intentionally left blank)
just brew it!
Administrator
Gold subscriber
 
 
Posts: 37705
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 5:07 pm

Oh man, there's a guy at work I sometimes ask for a hand with the odd task.

He is usually convinced that the answer is perl. Sometimes he is right.

Usually I give up and write it in half the time in python - another of my hammers :-D
Living proof of John Gabriel's theorem
IntelMole
Grand Gerbil Poohbah
 
Posts: 3529
Joined: Sat Dec 29, 2001 7:00 pm
Location: The nearest pub

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 5:39 pm

C++, nails everything down right and popper.
Core 2 Duo E6300, MSI P45 NEO-F, Club 3D GTX 260, 4Gb DDR2-800Mhz, Audigy X-Fi Fatal1ty Champ1on ed., 0.5Tb+1Tb Seagate Barracuda 7200.12, 630W AXP, Samsung SyncMaster BX2450, ViewSonic VP171b
Madman
Minister of Gerbil Affairs
 
Posts: 2317
Joined: Tue Apr 01, 2003 4:55 am
Location: Latvia

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 5:42 pm

Estwing.
It is one of the blessings of old friends that you can afford to be stupid with them. Ralph Waldo Emerson.
Captain Ned
Global Moderator
Gold subscriber
 
 
Posts: 20259
Joined: Wed Jan 16, 2002 7:00 pm
Location: Vermont, USA

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 6:26 pm

This is my favorite hammer: http://wiki.guildwars.com/wiki/Vera
EsotericLord
Gerbil First Class
 
Posts: 135
Joined: Mon Jan 11, 2010 1:23 pm

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 9:39 pm

awk and C with maybe a bit of Bourne shell scripting and the odd sed one liners.
notfred
Grand Gerbil Poohbah
 
Posts: 3736
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 11:32 pm

Bash, Python, and the big C++ hammer (along with the STL and boost attachments)!
Buub
Maximum Gerbil
Silver subscriber
 
 
Posts: 4200
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA

Re: Favourite hammers

Postposted on Mon Jan 23, 2012 11:59 pm

i script a lot... random stuff... using bash/php/perl/etc...

example of one that wget's multiple sequential files:

wgetm.sh
Code: Select all
#!/bin/sh

if [ $# -lt 3 ]; then
        printf "..Usage: $0 urlFormat seqStart seqEnd [wget_args]\n"
        printf "Example: ./wgetm.sh http://localhost.com/logs/file01s%03d.log 1 50\n"
        printf ".Direct: wget http://localhost.com/logs/file01s{001..050}.log\n\n"
        exit
fi

urlFormat=$1; seqStart=$2; seqEnd=$3; shift 3

printf "$url_format\\n" `seq $seqStart $seqEnd` | wget -i- "$@"


Ran into this when I tried to "wget" an entire folder, and something was preventing it from downloading everything in that folder...
thegleek
Darth Gerbil
Gold subscriber
 
 
Posts: 7365
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 1 guest