Thursday Sep 15, 2005

Has he lost his marbles?

Here is the geek challenge this week...

81424374 22536341 3262817393 4374 33736361 21 813253327142636232 3262236331436241 742373437181 81422181 222174432321535393 82743274 814232 53636352 6333 21 813253327142636232 8163 326223633132 21 748173436241 6333 81329281. 4333 936382 42218332 31322363313231 81424374 61327474214132 715332217432 5332218332 21 23636161326281 4362 814232 22536341... 81424374 744263825331 2232 338262 8163 743232 426391 53636241 8262814353 74636132636232 71637481 814232 31322363313231 81329281. 814232 61214362 4374748232 91438142 81424374 23633132 4374 81422181 4381 4374 2162 329271216281436362 23633132 216231 81428274 8121523274 8271 61637332 7471212332 8163 2232 32622363313231 833273748274 31322363313231. 41636331 53822352 336373 91422181 438174 9163738142.

Thursday Aug 11, 2005

Click till you drop... if you dare...

Thanks to Thin Guy for pointing me down the road of clicking for several minutes... Don't Press if you dare.

For what it's worth.

Thursday May 12, 2005

Geek Challenge: Mass rename

Here is the geek challenge this week... or month.. or whenever I get around to posting these challeneges... anyways back on topic. So you have a directory full of files that you need to copy into another directory but the problem is that you have namespace collision so you want to rename the files to be copied with a new name.

I run into this problem when I am pulling images off my digital camera. The camera assigns names like DSCFXXXX.JPG . This is all well and good until I want to store images that have the same name for a variety of reasons like they were on different flash cards and the camera number from 0001 for each card. So after unloading all of the images off the cards in seperate dirs I would like to combine them into the same dir. So dir1 has files DSCF0001.JPG through DSCF0150.JPG, and dir2 then has files DSCF0001.JPG through DSCF0120.JPG.

So what do I feel is a valid solution is, to create a script that will rename files in a given dir starting with a new number. For the example above I would go into dir2 and rename the files to start at DSCF0151.JPG and up. One catch is that what if I had the directories flipped and I wanted to rename the files in dir1 to start at DSCF0121.JPG and up... ah then one has to be careful since 0121 all ready exists in that directory...

Anyways have fun w/ the challenge. Please feel free to leave your solutions in the comments of this entry.

Remember that comments are free form but accept HTML so you might want to use the <pre> tags around the code.

Monday Mar 14, 2005

Geek Challenge: undef the perl code

So after yesterday's GC (geek challenge) a friend sent along the following.
#!/bin/perl

#Debug
print $foo->{bar}->{baz};

if ( exists $foo->{'bar'} ) {
        print "def"
} else {
        print "undef"
}

But it always prints def - why?

For what it's worth.

Update: I have updated the code snip... sorry I had the wrong code block in there before.

Geek Challenge: Find the problem

Geek Challenge today bringso you the following. So I spend to long finding the error in the function below... see if you can find it.
#ksh snip
pb_src () {
    f_parent=$1
    f_child=$2
    f_src=$3
    f_comment=$4

    su - bob -c "putback -p $f_parent -w $f_child" -c\\"$f_comment\\"  $f_src
}
Man did I kick myself when I found the error... leave your guesses in the comments.

For what it's worth.

Wednesday Mar 09, 2005

Geek Challenge: Catch the answer

Geek Challenge: Catch the answer in ksh

The challenge this week if you choice to accept it is this, in ksh: Present the user a yes/no question, take in the answer, determine path to follow based on the answer. So for example, say I was to ask the user if they would like a to see the listing from the current directory. If they user enters y or Y then you display the current directory listing, if they enter anything else you move on in the code.

<snip>
print -n "Would you like to see the current dir listing? [y/n]: "
read answer
if [ "$answer" = "y" ]; then
    ls $PWD
fi
</snip>

Now off to all of you for other ways

For what it's worth.

Tuesday Feb 08, 2005

Geek Challenge: Parallel Execution

Welcome to our second installment of Geek Challenge. I feel that the first one went over well so I will keep it going.

This weeks challenge might be a little trickier and I am limiting the shells Bourne-derived shells. So here we go. The goal of this geek challenge is to find the best approach to running several task that are not dependent on each other in parallel, catching their exit code, and then displaying a message. Here is a serial example:

#!/bin/ksh

FOO="
    one
    two
    three
"
for BAR in $FOO ; do
    cp $BAR /tmp/$BAR
    echo "copy of $BAR exited with $?"
done
Okay Geek squad you have your challenge, now go get 'em.

For what it's worth.

Tuesday Feb 01, 2005

Geek Challenge: Am I an INT?

Welcome to what might turn into a recurring topic: Geek Challenge. So to get us started I thought I would offer up a simple challenge.

Geek Challenge: Am I an INT?
Select your favorite shell (sh/ksh/csh/perl/...) and come up with cleanest way of determining if the contents of a variable are an integer.

Leave your solutions in the comments. To get us started here is a quick hack from a colleague for sh.

expr $foo + 1 >/dev/null 2>&1
if [ $? == 0 ]; then
    echo its an int
fi

For what it's worth.

About

dlacher

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today