HomeLatest ThreadsGreatest ThreadsForums & GroupsMy SubscriptionsMy Posts
DU Home » Latest Threads » Forums & Groups » Topics » Computers & Internet » Website, DB, & Software Developers (Group) » /* this forum needs more ...

Mon Mar 4, 2013, 10:50 PM

 

/* this forum needs more zest and i have just the cure.. */

coding games.*

quick, what language? what does it do?

<code>
print_help() {
printf "usage: that would be cheating now wouldn't it?"
exit 1 }
getYOUR() {
date '+%H' }
getMINE() {
date '+%M' }
getSMURFY_MAN() {
date '+%S' }
KLINGON() {
while true; do
printf '\a'
sleep 3
done
}

### 'main' function ###

if [ "$1" == "-h" ]; then
print_help
fi

if [ "$1" == "-r" ]; then
isrel=1
shift
else
isrel=0
fi

if [ "$#" -ne "2" ]; then
print_help
fi

HOUR=$1
MIN=$2
let "ALM=$HOUR*3600 + $MIN*60"
let "DAY=24*3600"

if [ "$isrel" == "1" ]; then
let "waitsecs=$ALM"
else
let "now=($(gethour)*60 + $(getmin))*60 + $(getsec)"
let "waitsecs=(($DAY - $now) + $ALM) % $DAY"
fi

if (( waitsecs < 0 )); then
echo "You cannot KLINGON in the past!"
exit 1
fi

let "alm_h=($waitsecs/3600)%24"
let "alm_m=($waitsecs/60)%60"
let "alm_s=($waitsecs)%60"

printf "BLURP in: %02d:%02d:%02d " "$alm_h" "$alm_m" "$alm_s"
printf " (%d YERMOM from now)\n" "$waitsecs"

sleep $waitsecs

if [ "$?" == "0" ]; then
KLINGON&
read -n 1 -s
kill $!
fi
</code>

* all formatting has been stripped (thanks DU for not allowing <code> tags), most of the if-then statements were also stripped by DU, and arbitrary variable and function names have been changed (by me, for fun).

also, the usage function and all comments were removed (also for fun), and last but most importantly..

this would NOT run so don't even TRY it but otherwise it WAS working code and besides..

it's fun.

10 replies, 2542 views

Reply to this thread

Back to top Alert abuse

Always highlight: 10 newest replies | Replies posted after I mark a forum
Replies to this discussion thread
Arrow 10 replies Author Time Post
Reply /* this forum needs more zest and i have just the cure.. */ (Original post)
Phillip McCleod Mar 2013 OP
NYC_SKP Mar 2013 #1
Phillip McCleod Mar 2013 #2
Phillip McCleod Mar 2013 #3
ChromeFoundry Mar 2013 #4
Phillip McCleod Mar 2013 #5
ChromeFoundry Mar 2013 #6
Phillip McCleod Mar 2013 #7
ChromeFoundry Mar 2013 #8
Phillip McCleod Mar 2013 #9
Dash87 May 2013 #10

Response to Phillip McCleod (Original post)

Mon Mar 4, 2013, 10:54 PM

1. javascript? (nt)

 

Reply to this post

Back to top Alert abuse Link here Permalink


Response to NYC_SKP (Reply #1)

Mon Mar 4, 2013, 10:55 PM

2. uh-oh. GONG!

 

hook. exit stage..

WRONG.

Reply to this post

Back to top Alert abuse Link here Permalink


Response to NYC_SKP (Reply #1)

Mon Mar 4, 2013, 11:04 PM

3. you deserve a hint though. 'script' was correct. BING-BING-BING!

 

rules of the game, partial credit means you get a HINT. the 1st line is missing. here's a hint to what it said:

'i start with crunch and end with not a bang, but a _____'

Reply to this post

Back to top Alert abuse Link here Permalink


Response to Phillip McCleod (Original post)

Tue Mar 5, 2013, 08:47 AM

4. KSH (nt)

Reply to this post

Back to top Alert abuse Link here Permalink


Response to ChromeFoundry (Reply #4)

Tue Mar 5, 2013, 09:44 AM

5. DING-DING-DING!

 

since ksh scripts are pretty much indistinguishable from bash i'm gonna have to give you this one. it's a bash script.

that was the easy part.. now.. what does it do?

Reply to this post

Back to top Alert abuse Link here Permalink


Response to Phillip McCleod (Reply #5)

Tue Mar 5, 2013, 03:32 PM

6. Looks like it does something like...

Accepts up to two numeric inputs: Hours and Minutes..
It then calculates the the total number of seconds specified by the input parameters.
Does a little date/time validation.
Sleeps for the calculated number of seconds.
Reads a single character from standard-input.
Then kills itself.

/*

Maybe I'm way off.. it's been a lot of years since I've done anything notable with UNIX.
I think I could probably rewrite that in PowerShell in less than 70 characters

*/

Reply to this post

Back to top Alert abuse Link here Permalink


Response to ChromeFoundry (Reply #6)

Wed Mar 6, 2013, 04:25 PM

7. pretty damn good!

 

the KLINGON function has a line that reads:

printf "\a"

try it in your *SH (tested in BASH)

if nothing interesting happens, make sure your terminal program allows system beeps ('bell on').

it's an utterly simplistic shell-based alarm clock program that will let you set the alarm in relative or absolute clock time. i wrote it one night at a motel when i had a plane to catch and too much 'fun' beforehand. i cleaned it a bit, later, but not much.

once the alarm starts going off, it waits for any keypress to stop it. otherwise your computer will beep into eternity..

Reply to this post

Back to top Alert abuse Link here Permalink


Response to Phillip McCleod (Reply #7)

Wed Mar 6, 2013, 06:15 PM

8. Interesting...

Too drunk to wake up, but - Never too drunk to code!!!!

>> >> >> >> >> >> >> >> write-some-code >>

Reply to this post

Back to top Alert abuse Link here Permalink


Response to ChromeFoundry (Reply #8)

Wed Mar 6, 2013, 08:54 PM

9. funny how that works huh?

 

Reply to this post

Back to top Alert abuse Link here Permalink


Response to Phillip McCleod (Original post)

Reply to this thread