I am new to Ruby and I could use some expert advice as to ho

Ruby M. wrote:

I know of some people right now who are feverishly working to make
Ruby “the” answer to everything regardless of what the real problem
they are trying to resolve is and they are spending a whole lotta time
doing it too

…and they are responsible for either:

  1. their lack of pragmatism
  2. or the next big speed breakthrough in how things are done with Ruby!
    :slight_smile:

Cheers,
Mohit.
9/25/2007 | 8:41 AM.

Ruby M. wrote:

I know of some people right now who are feverishly working to make
Ruby “the” answer to everything regardless of what the real problem
they are trying to resolve is and they are spending a whole lotta time
doing it too.
Got links?

On 9/24/07, Ilmari H. [email protected] wrote:

    buf[i] |= 0x80808080;

(and the other necessary changes, of course).

And a version with 64-bit ints was even faster. But it had a bug too.

Anyone wish to contribute working versions :)?

Guess not, so here’s one:

$ time ./scramble64 trace trace.scramblec

real 0m0.022s
user 0m0.004s
sys 0m0.020s

$ export RUBYOPT= # -rubygems takes ~40ms
$ time ruby -rscramble -e ‘scramble_nobu(“trace”)’

real 0m0.049s
user 0m0.016s
sys 0m0.032s

$ diff trace.scramble*
$

$ cat scramble64.c

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#define BUF_SIZE 4096

int main(int argc, char** argv) {
int i, j, k, rsz, wsz;
FILE *in_f, *out_f;
unsigned long long isz;
struct stat st;
long long buf[BUF_SIZE];

if (argc != 3) {
printf(“USAGE: %s INFILE OUTFILE\n”, argv[0]);
return 1;
}

isz = sizeof(long long);

in_f = fopen(argv[1], “r”);
if (NULL == in_f) {
printf(“Failed to open input file %s\n”, argv[0]);
return 2;
}

out_f = fopen(argv[2], “w”);
if (NULL == out_f) {
printf(“Failed to open output file %s\n”, argv[1]);
fclose(in_f);
return 4;
}

fstat(fileno(in_f), &st);
for(i=0,j = st.st_size / (iszBUF_SIZE); i<j; i++) {
rsz = fread(buf, isz, BUF_SIZE, in_f);
for(k=0; k<rsz; k++)
buf[k] |= 0x8080808080808080;
wsz = fwrite(buf, isz, rsz, out_f);
if (wsz != rsz) {
printf(“Failed to write to output file\n”);
break;
}
}
rsz = fread(buf, 1, isz
BUF_SIZE, in_f);
for(k=0; k<rsz; k++)
((char*)buf)[k] |= 0x80;
wsz = fwrite(buf, 1, rsz, out_f);
if (wsz != rsz) {
printf(“Failed to write to output file\n”);
}

fclose(in_f);
fclose(out_f);
return 0;
}

On 24 sept. 07, at 14:50, Ruby M. wrote:

It is truly sad that people, like me, are labeled as being “trolls”
whenever we try to interject some reality into a world where people
clearly do not want anything that resembles reality.

Presenting lies as reality, among many other reasons, is what makes
you a troll. Something like “I can code Windows services usign Python
if I wanted to but I cannot code Windows services using Ruby whether
I wanted to or not” is nothing more than a lie.

http://raa.ruby-lang.org/project/win32-service/0.5.2

On Sep 24, 6:50 pm, “Ilmari H.” [email protected]
wrote:

Guess not, so here’s one:
real 0m0.049s
#include <sys/types.h>
long long buf[BUF_SIZE];
printf(“Failed to open input file %s\n”, argv[0]);
fstat(fileno(in_f), &st);
rsz = fread(buf, 1, iszBUF_SIZE, in_f);
for(k=0; k<rsz; k++)
((char
)buf)[k] |= 0x80;
wsz = fwrite(buf, 1, rsz, out_f);
if (wsz != rsz) {
printf(“Failed to write to output file\n”);
}

fclose(in_f);
fclose(out_f);
return 0;}

Here’s my version in FreeBasic.

#define BUF_SIZE 4096

function scramble( filename as string ) as double
dim outname as string
dim as integer in_handle, out_handle, i, size
dim buffer( 0 to BUF_SIZE - 1 ) as byte
dim p as longint ptr

outname = filename & “.scrambled”
in_handle = freefile
if open( filename, for binary access read, as in_handle) then
? "Can’t read "; filename
end 2
end if
out_handle = freefile
if open( outname, for binary access write as out_handle) then
? "Can’t write to "; outname
close in_handle
end 4
end if
while not eof( in_handle )
size = seek( in_handle )
get #in_handle, , buffer()
size = seek( in_handle ) - size
p = @buffer(0)
while p < @buffer( BUF_SIZE )
*p = *p or &h8080808080808080
p += 1
wend
if put( #out_handle, , buffer(0), size ) then
? "Failed while writing to "; outname
exit while
end if
wend
close '-- Caution. Closes all open files.
return 0.0
end function

if command(1) = “” then
? “Give me a filename next time.”
end 1
end if
print -timer + scramble( command(1) ) + timer

Eric H. wrote:

Ruby M. wrote:

It is truly sad that people, like me, are labeled as being “trolls”
whenever we try to interject some reality into a world where people
clearly do not want anything that resembles reality.

Every opinion is a reality. – Timothy Leary

We simply don’t want to hear your opinion here.

I don’t think that’s quite accurate. An opinion that ruby is not the
fastest of languages is hardly unwelcome. Such a thoroughly
undiplomatic tone of voice, however, is.

Ruby M. wrote:

It is truly sad that people, like me, are labeled as being “trolls”
whenever we try to interject some reality into a world where people
clearly do not want anything that resembles reality.

Every opinion is a reality. – Timothy Leary

We simply don’t want to hear your opinion here.

On Sat, 2007-09-22 at 17:38 +0900, Nobuyoshi N. wrote:

end

end

Nobuyoshi, you are holy!

Arlen