Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
IntelMole
Grand Gerbil Poohbah
Topic Author
Posts: 3506
Joined: Sat Dec 29, 2001 7:00 pm
Location: The nearest pub
Contact:

Favourite hammers

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
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Favourite hammers

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:
Nostalgia isn't what it used to be.
 
IntelMole
Grand Gerbil Poohbah
Topic Author
Posts: 3506
Joined: Sat Dec 29, 2001 7:00 pm
Location: The nearest pub
Contact:

Re: Favourite hammers

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
 
Madman
Minister of Gerbil Affairs
Posts: 2317
Joined: Tue Apr 01, 2003 4:55 am
Location: Latvia

Re: Favourite hammers

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
 
Captain Ned
Global Moderator
Posts: 28704
Joined: Wed Jan 16, 2002 7:00 pm
Location: Vermont, USA

Re: Favourite hammers

Mon Jan 23, 2012 5:42 pm

Estwing.
What we have today is way too much pluribus and not enough unum.
 
EsotericLord
Gerbil First Class
Posts: 136
Joined: Mon Jan 11, 2010 1:23 pm

Re: Favourite hammers

Mon Jan 23, 2012 6:26 pm

This is my favorite hammer: http://wiki.guildwars.com/wiki/Vera
 
notfred
Maximum Gerbil
Posts: 4610
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Favourite hammers

Mon Jan 23, 2012 9:39 pm

awk and C with maybe a bit of Bourne shell scripting and the odd sed one liners.
 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Re: Favourite hammers

Mon Jan 23, 2012 11:32 pm

Bash, Python, and the big C++ hammer (along with the STL and boost attachments)!
 
thegleek
Darth Gerbil
Posts: 7460
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI
Contact:

Re: Favourite hammers

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
#!/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...

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On