You are not logged in.

#1 2005-10-24 17:33:35

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

script help

Hi guys

how can I get the following script to remember the random numbers it's generated so far, so that it won't display the same image twice, unless there are 16+ terminals open? I guess I need some sort of permanent variable, but I don't know how to create such a thing.

#!/bin/bash

RANGE=16
RND=$RANDOM
let "RND %= $RANGE"
IMG=`ls ~/.urxvt/backgrounds/ | grep 0$RND-`
IMG_SIZE=`expr "$IMG" : '.*-([0-9]{2,}x[0-9]{2,})'`
echo $IMG_SIZE
urxvt -pixmap ~/.urxvt/backgrounds/$IMG -geometry $IMG_SIZE>> /dev/null 2>&1 &

Offline

#2 2005-10-24 18:30:50

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: script help

You could always send the previous values to a file somewhere for reference. Or, I'd suggest switching to a better scripting language.

Offline

#3 2005-10-24 18:40:50

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

Re: script help

Yeah, I guess I ought to start using Python or Perl. I'm not sure which is best though... Perl's so powerful, but the syntax is so bizarre... I like the look of python. Has anyone who's used both got an opinion to share?

Offline

#4 2005-10-24 22:22:34

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: script help

For the record, there's a million wallpaper randomizers out there - you'd be better off not reinventing the wheel and using an existing one.

Offline

#5 2005-10-25 13:32:03

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: script help

For the record, sometimes that's part of the fun.

Offline

#6 2005-10-25 13:47:39

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

Re: script help

No offence Phrakture, but what's better: me stealing someone else's code to randomize a terminal background, or writing one myself so that I get better at programming in whatever language I use?

Personally I think the latter would be more beneficial.

Offline

#7 2005-10-25 17:56:30

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: script help

mr_brightside wrote:

No offence Phrakture, but what's better: me stealing someone else's code to randomize a terminal background, or writing one myself so that I get better at programming in whatever language I use?

Personally I think the latter would be more beneficial.

Well, that's subjective.  Personally, whenever I'm stuck with something, I try to work it out in my head, can't figure it out, then google and find how someone else has solved the problem.  I learn best that way, by "stealing someone else's code" (it's not stealing if it's OSS).

It really depends on where your knowledge is at.  When you do this sort of thing for a long time, languages begin to blur.  Syntax is minor, it doesn't matter anymore.  Knowing *how* to program is totally different.  In my opinion, you don't learn how to write good code by practicing - you do it by looking at good code.  It's similar to novel writting - you'll probably never have good prose and (...something else pertinent to writting a story...lol) if you've never read any books at all.

Offline

#8 2005-10-26 03:07:02

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: script help

mr_brightside wrote:

Yeah, I guess I ought to start using Python or Perl. I'm not sure which is best though... Perl's so powerful, but the syntax is so bizarre... I like the look of python. Has anyone who's used both got an opinion to share?

Perl is for old people that thought a dynamic language was cool when Perl came out. Python is for smart people who think its much cooler to have a decent dynamic language.

Yes, I've used both, and I can say with authority that Python is at least as powerful as Perl (and Java!) and the syntax is to die for.

Dusty

Offline

#9 2005-10-26 08:23:58

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

Re: script help

I agree completely with you Phrakture; knowing the methods and theory behind programming is far more important than knowing syntax. I'm a computer science student at Oxford University in the UK, and a lot of what we get taught is the theory behind programming, and the best way to approach a problem when coding.

Dusty, I'm glad to hear you're on the Python bandwagon; every comment I've seen about it was highly flattering. My tutor doesn't like it because it doesn't implement lambda very well (if you know what I'm talking about?); he uses Tcl with C, but personally I'd rather give Python a try.

Offline

#10 2005-10-26 09:44:53

dust
Member
Registered: 2005-06-04
Posts: 152
Website

Re: script help

Lisp!


Writing stories for a machine.

Offline

#11 2005-10-26 12:52:46

Kern
Member
From: UK
Registered: 2005-02-09
Posts: 464

Re: script help

i always wondered, shouldn't that be lithp ? smile

Offline

#12 2005-10-26 13:39:28

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

Re: script help

LOL lol

Offline

#13 2005-10-26 19:55:16

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: script help

mr_brightside wrote:

Dusty, I'm glad to hear you're on the Python bandwagon; every comment I've seen about it was highly flattering. My tutor doesn't like it because it doesn't implement lambda very well (if you know what I'm talking about?); he uses Tcl with C, but personally I'd rather give Python a try.

I like python best out of the mass-of-dynamic-languages today (perl, ruby, groovy?, lush, ummm there's about 30 more).  That is mainly due to clean syntax.  I just like:

for a in someArray: #blah blah

much better than

someArray.each { |a|
#blah blah
}

Admittedly ruby is cool and all, but if I want oddly elegant code, I'll go for C++.

As for the "doesn't implement lambda correctly", that, to me, sounds like a regurgitated excuse... much like "java is slow" - I know the complaints about lambda, but they're very esoteric.  I mean, you can write pages and pages of lambda functions and not run into any of the issues brought up by the opponents of the way it's implemented.

For the record, C++ supports lambda functions nicely:

std::vector<int> v;
//fill v with ints

//_1 is used to construct a lambda expression, _1 being the first argument
std::for_each(v.begin(),v.end(), std::cout << _1 << std::endl);

Offline

#14 2005-10-27 01:41:31

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: script help

phrakture wrote:

for a in someArray: #blah blah

much better than

someArray.each { |a|
#blah blah
}
someHash.each {
 |key,value|
 # blah blah
}

/me shrugs
to me that seems elegant. the object having the iteration method associated to it, instead of some global object iterator acting upon it.
probably a result of my programming origins though...


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#15 2005-10-28 21:30:47

cs25x
Member
Registered: 2004-05-04
Posts: 150

Re: script help

take you pick.

if ! [ -e /tmp/$RND ] ; then touch /tmp/$RND

or

if [ -e /tmp/$RND ] ; then 
do
you need another draw 
else 
touch /tmp/$RND
do some more;
done
fi

the negated test is probably more clumbsy. remember to zap the /tmp files before or after, as required.

there is a good bash tutorial called abs or something, freshmeat ? abs-guide-rev.html.tar.gz is about what it is called revision is 3.0 or greater these days. I think it is also available as text

There is nothing intrinsically wrong with code theft, just get the right code.
Reading OPC is the fast way to learn.


--(*(cs25x--));

Offline

#16 2005-10-28 23:42:26

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: script help

Python vs Ruby in a nutshell:

Python coders say "ruby is ok" and reby coders say "python is ok". People rarely say they love one and hate the other.

Not like the which distro or vi vs emacs debates.... or, within the python community, tabs vs spaces...

Dusty

Offline

#17 2005-10-29 00:40:32

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: script help

Dusty wrote:

Not like the which distro or vi vs emacs debates....

Dusty

I prefer vim.

Offline

#18 2005-10-29 01:00:40

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: script help

why is it that every time I post in a thread its a marker that that thread has gone off topic? :'(

Dusty

Offline

#19 2005-10-29 22:00:31

mr_brightside
Member
Registered: 2005-09-01
Posts: 78

Re: script help

LOL... just slow to get there, Dusty? tongue

Offline

#20 2005-10-29 22:24:29

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: script help

I guess so.  Too busy. Been nice to have this break to harrass y'all again.... Too bad I can't delete posts anymore.... Ah the memories.... *sigh*

I feel so old.

Dusty

Offline

Board footer

Powered by FluxBB