Re: random header script?

2002-06-24 Thread darren chamberlain

* Thomas Hurst [EMAIL PROTECTED] [2002-06-23 08:00]:
 If you still want to use a script but don't want to eat
 filesize * structure overhead and IO every invocation, you'll want
 to seek to somewhere random in the file and read until you get a
 complete line, ala (in Ruby):
 
 begin
 File.open(file) do |f|
 f.seek(rand(File.size(file)))
 f.gets
 puts f.gets
 end
 rescue EOFError
 retry
 end
 
 This will, however, guarantee the first line will never be read, and
 choose longer lines over shorter ones.

I have a fortune file (standard strfile format) that I use, and
occasionally my vi modeline (line 1) comes up as a fortune.  This is an
ideal solution... ;)

(darren)

-- 
Most rock journalism is people who can't write interviewing people
who can't talk for people who can't read.
-- Frank Zappa



Re: random header script?

2002-06-23 Thread Thomas Hurst

* Ken Weingold ([EMAIL PROTECTED]) wrote:

 I think I remember a while back someone haveing a script to take lines
 randomly from a text file to put into a custom header.  Does anyone
 have this?

Replace \n with \n%\n and run it through strfile.  Then run fortune
over the generated data file.  If you have a lot of lines, this will be
significantly more effecient than a naive implimentation (such as the
read all lines and randomly generate an index to the generated list:
nice brute force method :), and give flexibility to search by regexp,
length, etc.

If you still want to use a script but don't want to eat
filesize * structure overhead and IO every invocation, you'll want
to seek to somewhere random in the file and read until you get a
complete line, ala (in Ruby):

begin
File.open(file) do |f|
f.seek(rand(File.size(file)))
f.gets
puts f.gets
end
rescue EOFError
retry
end

This will, however, guarantee the first line will never be read, and
choose longer lines over shorter ones.

A better alternative is to index the file first, creating a list of
offsets in the file for each entry in fixed length fields.  The above
technique can then be used effectively, since you can both mod the seek
to record boundaries and know you're not choosing any one entry over any
other.  Then you just shove the offset into a seek on the data file.

Depends how much fun you think you can cope with ;)

-- 
Thomas 'Freaky' Hurst  -  [EMAIL PROTECTED]  -  http://www.aagh.net/
-
Chef, n:
Any cook who swears in French.



Re: random header script?

2002-06-21 Thread Ken Weingold

On Thu, Jun 20, 2002, David T-G wrote:
 % One issue.  It seems to run the script only once, when I start mutt, so I always
 
 RTFArchives, grasshopper :-)

I tried, but 1) the mutt site was down last night, and 2) I couldn't
even think of what to search for.  I tried a few things in Google, but
nothing.  How often do you see me ask a question that requires a RTFM?
Okay, don't answer that. ;-)

 % my_hdr X-Message-Flag: `$HOME/bin/random.pl`
 
 Wrap it in single quotes, perhaps making it a default send-hook, to
 ensure that it gets interpreted at call time instead of muttrc-read time.

Send-hook sounds good, as Cedric also said.  But what about single
quotes?

Thanks.


-Ken



Re: random header script?

2002-06-21 Thread Ken Weingold

Okay, so here's a purely aesthetic question.  Using send-hook works
just fine, but it puts the header after all my my_hdr's.  Anyway to
get it before them?


-Ken



Re: random header script?

2002-06-21 Thread Charles Krug

On Fri, Jun 21, 2002 at 08:36:43AM -0400, Ken Weingold wrote:
 On Thu, Jun 20, 2002, David T-G wrote:
  % One issue.  It seems to run the script only once, when I start mutt, so I always
  
  RTFArchives, grasshopper :-)
 
 I tried, but 1) the mutt site was down last night, and 2) I couldn't
 even think of what to search for.  I tried a few things in Google, but
 nothing.  How often do you see me ask a question that requires a RTFM?
 Okay, don't answer that. ;-)
 

I found that the sample .muttrc by Telsa is a nice complement to the
mutt-for-all.  MFA gives an exhaustive listing of all possible
options, while Telsa's gives a good explanation for the ones that are a
smidge more complicated.




Re: random header script?

2002-06-21 Thread Rob 'Feztaa' Park


--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Alas! Ken Weingold spake thus:
 Okay, so here's a purely aesthetic question.  Using send-hook works
 just fine, but it puts the header after all my my_hdr's.  Anyway to
 get it before them?

Possibly, use send hooks for all your other my_hdr's too (put them after
this one). Would be inefficient, but it would get your X-message-flag
before them instead of after, afaict.

--=20
Rob 'Feztaa' Park
http://members.shaw.ca/feztaa/
--
The lawgiver, of all beings, most owes the law allegiance.  He of all men
should behave as though the law compelled him.  But it is the universal
weakness of mankind that what we are given to administer we presently imagi=
ne
we own.
-- H.G. Wells

--r5Pyd7+fXNt84Ff3
Content-Type: application/pgp-signature
Content-Disposition: inline

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9EzfVPTh2iSBKeccRAk05AJ9WMu4MxUGYZ0vZrA+6sn1nne0L1gCeLVU7
PvZypPL1nlJfzrPuvDv/1b8=
=Um4e
-END PGP SIGNATURE-

--r5Pyd7+fXNt84Ff3--



Re: random header script?

2002-06-21 Thread David T-G

Ken --

...and then Ken Weingold said...
% 
% On Thu, Jun 20, 2002, David T-G wrote:
...
%  
%  RTFArchives, grasshopper :-)
% 
% I tried, but 1) the mutt site was down last night, and 2) I couldn't

Of course, the archives don't live there, so all you really need to do is
use google to find a mail archive site...  But now I'm being a pest ;-)


% even think of what to search for.  I tried a few things in Google, but

Yeah, that can be tricky.


% nothing.  How often do you see me ask a question that requires a RTFM?
% Okay, don't answer that. ;-)

Mmmmphmmph! :-)


% 
%  % my_hdr X-Message-Flag: `$HOME/bin/random.pl`
%  
%  Wrap it in single quotes, perhaps making it a default send-hook, to
%  ensure that it gets interpreted at call time instead of muttrc-read time.
% 
% Send-hook sounds good, as Cedric also said.  But what about single

BTW, you may find that

  my_hdr 'X-Message-Flag: `$HOME/bin/random.pl`'

will still work -- and then you'll have the simple answer to your
question of aesthetics :-)  Try playing with it...


% quotes?

When it's wrapped in single quotes it won't get interpreted at the time
it's read; it will simply get read, and then later it will be
interpreted.  If it's not in quotes, the command is done when you pass
through the muttrc and the value is substituted in and left there (just
like it is for every message later, but it's done just once earlier this
way).


% 
% Thanks.

Sure thing!


% 
% 
% -Ken


HTH  HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg29136/pgp0.pgp
Description: PGP signature


Re: random header script?

2002-06-21 Thread Ken Weingold

On Fri, Jun 21, 2002, David T-G wrote:
 BTW, you may find that
 
   my_hdr 'X-Message-Flag: `$HOME/bin/random.pl`'
 
 will still work -- and then you'll have the simple answer to your
 question of aesthetics :-)  Try playing with it...

With single or double quotes like that, it gets eaten and not
inserted.  I noticed before sending in edit-headers, the quotes are
preserved and taken literally.  Same thing works fine as a send-hook.


-Ken



Re: random header script?

2002-06-21 Thread Ken Weingold

On Fri, Jun 21, 2002, AxUm wrote:
  I think I remember a while back someone haveing a script to take lines
  randomly from a text file to put into a custom header.  
 
 I usually use fortune ... 

fortune -o is more fun. :)


-Ken



random header script?

2002-06-20 Thread Ken Weingold

I think I remember a while back someone haveing a script to take lines
randomly from a text file to put into a custom header.  Does anyone
have this?  Basically I want to insert into that Outhouse header
random lines from a text file I made from the Surrealist Compliment
Generator. :)

Thanks.


-Ken



Re: random header script?

2002-06-20 Thread Rob 'Feztaa' Park

Alas! Ken Weingold spake thus:
 I think I remember a while back someone haveing a script to take lines
 randomly from a text file to put into a custom header.  Does anyone
 have this?  Basically I want to insert into that Outhouse header
 random lines from a text file I made from the Surrealist Compliment
 Generator. :)

This is trivial to do in perl:

open FILE, file.txt;

while (FILE)
{
  push lines, $_;
}

print $lines[int(rand(lines))];

(it's untested, but it probably works). Of course, you'll have to modify
it to output the appropriate email header and whatnot.

-- 
Rob 'Feztaa' Park
http://members.shaw.ca/feztaa/
--
Kiss me twice.  I'm schizophrenic.



msg29097/pgp0.pgp
Description: PGP signature


Re: random header script?

2002-06-20 Thread Dan Boger

On Thu, Jun 20, 2002 at 02:49:37PM -0600, Rob 'Feztaa' Park wrote:
 This is trivial to do in perl:
 
 open FILE, file.txt;
 
 while (FILE)
 {
   push lines, $_;
 }
 
 print $lines[int(rand(lines))];

or, the more efficient way:

open FILE, file.txt or die $!;
rand($.)  1  ($line = $_) while FILE;
close FILE;
print $line;

from perldoc -q random

:)

-- 
Dan Boger
Linux MVP
brainbench.com




msg29098/pgp0.pgp
Description: PGP signature


Re: random header script?

2002-06-20 Thread Ken Weingold

Thanks for the quick replies.  It works.  Too cool.


-Ken



Re: random header script?

2002-06-20 Thread Rob 'Feztaa' Park


--RIYY1s2vRbPFwWeW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Alas! Dan Boger spake thus:
 On Thu, Jun 20, 2002 at 02:49:37PM -0600, Rob 'Feztaa' Park wrote:
  This is trivial to do in perl:
 =20
  open FILE, file.txt;
 =20
  while (FILE)
  {
push lines, $_;
  }
 =20
  print $lines[int(rand(lines))];
=20
 or, the more efficient way:
=20
 open FILE, file.txt or die $!;
 rand($.)  1  ($line =3D $_) while FILE;
 close FILE;
 print $line;
=20
 from perldoc -q random

Sure, that works; but you can't repeat it without rewinding to the
beginning of the file. With mine, you can call that print statement as
many times as you want ;)

--=20
Rob 'Feztaa' Park
http://members.shaw.ca/feztaa/
--
Q:  What's the difference between a Mac and an Etch-a-Sketch?
A:  You don't have to shake the Mac to clear the screen.

--RIYY1s2vRbPFwWeW
Content-Type: application/pgp-signature
Content-Disposition: inline

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9EmQXPTh2iSBKeccRAhDfAJ9jd9Vaiz1rizAPjDfFPAhthsEM1wCfSRLi
rLLEqUvoqxSzDSo2Erpdxog=
=y5Ly
-END PGP SIGNATURE-

--RIYY1s2vRbPFwWeW--



Re: random header script?

2002-06-20 Thread Ken Weingold

On Thu, Jun 20, 2002, Rob 'Feztaa' Park wrote:
 Sure, that works; but you can't repeat it without rewinding to the
 beginning of the file. With mine, you can call that print statement as
 many times as you want ;)

One issue.  It seems to run the script only once, when I start mutt, so I always
get the same line from the file.  Do I not have the correct syntax for
it?  This is my header:

my_hdr X-Message-Flag: `$HOME/bin/random.pl`


Thanks.


-Ken



Re: random header script?

2002-06-20 Thread David T-G

Ken --

...and then Ken Weingold said...
% 
...
% One issue.  It seems to run the script only once, when I start mutt, so I always

RTFArchives, grasshopper :-)


% get the same line from the file.  Do I not have the correct syntax for
% it?  This is my header:
% 
% my_hdr X-Message-Flag: `$HOME/bin/random.pl`

Wrap it in single quotes, perhaps making it a default send-hook, to
ensure that it gets interpreted at call time instead of muttrc-read time.


% 
% 
% Thanks.

HTH  HAND


% 
% 
% -Ken


:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg29113/pgp0.pgp
Description: PGP signature