473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Funny pieces of code

I've found some funny pieces of code in one project... I don't know: to
laught or to cry =)

function toHex(decimal) {
switch(decimal) {
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default:
decimal = "" + decimal;
}
return decimal;
}

function decToHex(num) {
return(toHex(Math.floor(num / 16)) + toHex(num % 16));
}

//------------------------------------------------------------------------

function isNumber(s) { for (var i = 0; i < s.length; i++) { var c =
s.charAt(i); if (!isDigit(c)) return false; } return true; }

function isDigit (c){return ((c >= "0") && (c <= "9")) }

function isLetter (c){return ( ((c >= "a") && (c <= "z")) || ((c >=
"A") && (c <= "Z")) ) }

var whitespace = " \t\n\r";
function isWhitespace (s){
if((s == null) || (s.length == 0)) return true;
for(var i = 0; i < s.length; i++){
if(whitespace.indexOf(s.charAt(i)) == -1) return false;
}
return true;
}

Oct 30 '06 #1
9 3469

sc********@gmail.com wrote:
I've found some funny pieces of code in one project... I don't know: to
laught or to cry =)

function toHex(decimal) {
switch(decimal) {
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default:
decimal = "" + decimal;
}
return decimal;
}

function decToHex(num) {
return(toHex(Math.floor(num / 16)) + toHex(num % 16));
}

//------------------------------------------------------------------------

function isNumber(s) { for (var i = 0; i < s.length; i++) { var c =
s.charAt(i); if (!isDigit(c)) return false; } return true; }

function isDigit (c){return ((c >= "0") && (c <= "9")) }

function isLetter (c){return ( ((c >= "a") && (c <= "z")) || ((c >=
"A") && (c <= "Z")) ) }

var whitespace = " \t\n\r";
function isWhitespace (s){
if((s == null) || (s.length == 0)) return true;
for(var i = 0; i < s.length; i++){
if(whitespace.indexOf(s.charAt(i)) == -1) return false;
}
return true;
}
Did you want someone to answer a question concerning the script you
quote? It has something to do with a fairly common procedure:
hex/decimal number system conversions. Does it not work, do you want
someone to explain it, or what? Or perhaps I have not had enough coffee
this morning and missed something.

Oct 30 '06 #2
Lee
cwdjrxyz said:
>

sc********@gmail.com wrote:
>I've found some funny pieces of code in one project... I don't know: to
laught or to cry =)

function toHex(decimal) {
switch(decimal) {
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default:
decimal = "" + decimal;
}
return decimal;
}

function decToHex(num) {
return(toHex(Math.floor(num / 16)) + toHex(num % 16));
}

//------------------------------------------------------------------------

function isNumber(s) { for (var i = 0; i < s.length; i++) { var c =
s.charAt(i); if (!isDigit(c)) return false; } return true; }

function isDigit (c){return ((c >= "0") && (c <= "9")) }

function isLetter (c){return ( ((c >= "a") && (c <= "z")) || ((c >=
"A") && (c <= "Z")) ) }

var whitespace = " \t\n\r";
function isWhitespace (s){
if((s == null) || (s.length == 0)) return true;
for(var i = 0; i < s.length; i++){
if(whitespace.indexOf(s.charAt(i)) == -1) return false;
}
return true;
}

Did you want someone to answer a question concerning the script you
quote? It has something to do with a fairly common procedure:
hex/decimal number system conversions. Does it not work, do you want
someone to explain it, or what? Or perhaps I have not had enough coffee
this morning and missed something.
It's all done the hard way. It may be old enough that RegExp
couldn't be trusted to exist/work on all platforms, but
Number.toString(16) has been around for a long time.
--

Oct 30 '06 #3
Lee wrote:
It's all done the hard way. It may be old enough that RegExp
couldn't be trusted to exist/work on all platforms, but
Number.toString(16) has been around for a long time.
YES! Its all done possibly the worst way. I've never saw SO DUMB code.

Oct 30 '06 #4
sc********@gmail.com said the following on 10/30/2006 12:54 PM:
Lee wrote:
>It's all done the hard way. It may be old enough that RegExp
couldn't be trusted to exist/work on all platforms, but
Number.toString(16) has been around for a long time.

YES! Its all done possibly the worst way. I've never saw SO DUMB code.
Never coded for the old generation browsers then, eh? Just think, in 5
years you could look back at your code now and think "I've never saw SO
DUMB code"!

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 30 '06 #5
Randy Webb wrote:
Never coded for the old generation browsers then, eh? Just think, in 5
years you could look back at your code now and think "I've never saw SO
DUMB code"!
Yes, Randy, you're right. But is is a piece of code from _current time
project_.
It is not a code for old generation browsers.
I think it is just coded by C programmer without JS knowledge.

BTW when I looking at old code (C/C++/...) sometimes I think "It is
beautiful!", but this code looks ugly (but funny).

Oct 30 '06 #6
sc********@gmail.com wrote:
BTW when I looking at old code (C/C++/...) sometimes I think "It is
beautiful!", but this code looks ugly (but funny).
C++ is old?????

Oooh boy, I must be ancient....

Now Fortran IV, there was a man's programming language....

:-)
Oct 30 '06 #7
sc********@gmail.com said the following on 10/30/2006 1:46 PM:
Randy Webb wrote:
>Never coded for the old generation browsers then, eh? Just think, in 5
years you could look back at your code now and think "I've never saw SO
DUMB code"!
Yes, Randy, you're right. But is is a piece of code from _current time
project_.
And it is typical of "current time project" code if you spend any time
on the web viewing source code. I am not sure who said it originally (I
think Jim Ley but not positive) that if you want to see the best JS code
in the world, comp.lang.javascript is the place to see it. The reason is
that code posted here is open to constructive criticism (and any code
posted here gets it, whether verbal or not) whereas code written in a
boiler room to make a profit isn't subjected to that review - it is only
subjected to non-IE users bitching at the screen when the page doesn't
work properly because the idiot that wrote it thought IE was the only
browser on the web.
It is not a code for old generation browsers.
I think it is just coded by C programmer without JS knowledge.
Or any other programmer who either didn't know better or didn't care.
BTW when I looking at old code (C/C++/...) sometimes I think "It is
beautiful!", but this code looks ugly (but funny).
It *is* ugly and funny!

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 30 '06 #8

sc********@gmail.com wrote:
Lee wrote:
It's all done the hard way. It may be old enough that RegExp
couldn't be trusted to exist/work on all platforms, but
Number.toString(16) has been around for a long time.

YES! Its all done possibly the worst way. I've never saw SO DUMB code.
Things do change rapidly on the web. Let us start with a script from
1996.

1996 original

// Michael P. Scholtis (mp****@planetx.bloomu.edu) // All rights
reserved. January 15, 1996 // You may use this JavaScript example as
you see fit, as long as the // information within this comment above is
included in your script. function MakeArray(n){ this.length=n; for(var
i=1; n>=i; i++) this[i]=i-1; return this } hex=new MakeArray(16);
hex[11]="A"; hex[12]="B"; hex[13]="C"; hex[14]="D"; hex[15]="E";
hex[16]="F"; function ToHex(x){ // Changes a int to hex (in the range 0
to 255) var high=x/16; var s=high+""; //1 s=s.substring(0,2); //2 the
combination of these are the same as the trunc function
high=parseInt(s,10); //3 var left=hex[high+1]; // left part of the
hex-value var low=x-high*16; // calculate the rest of the values
s=low+""; //1 s=s.substring(0,2); //2 the combination of these are the
same as the trunc function low=parseInt(s,10); //3 var
right=hex[low+1]; // right part of the hex-value var
string=left+""+right; // add the high and low together return string; }
function rainbow(text){ text=text.substring(3,text.length-4); // gets
rid of the HTML-comment-tags color_d1=255; // any value in 'begin' 0 to
255 mul=color_d1/text.length; for(i=0;text.length i;i++){
color_d1=255*Math.sin(i/(text.length/3)); // some other things you can
try >"=255-mul*i" to fade out, "=mul*i" to fade in, or try
"255*Math.sin(i/(text.length/3))" color_h1=ToHex(color_d1);
color_d2=mul*i; color_h2=ToHex(color_d2);
document.write(""+text.substring(i,i+1)+"<\/font>"); } } // --End
Hiding Here -- This is a rainbow text effect which you may upload to
your own site and use as you wish. Unfortunately you can only add about
10 lines of text here and then you have to use the code over again in
the next paragraph. You only need to use the code that's in the body
tag over again, not the part in the head tag. Let's see what happens
here if I continue to add text and see if it continues to change the
color of the text. And I'll just ramble on here a little more so you
can see the effect here and how it changes the text color. Cool effect
Huh!

Sorry the above has had white space removed. Note that it has hex
conversion. Now, if we consider the head script, we find that if we use
r,g,b colors instead of hex, we can avoid the hex conversion
completely, and the head script can be written:

js/rt.

/* Written by cw****@webtv.net in Feb. 2003 */
function paint(blah){
var x; var i; var c1=255; var x=blah.length; var f=c1/x; var c0=255;
for (i=0;x>i;i++){
c1=255*Math.round(Math.sin(i/(x/3))); var c2=Math.round(f*i);
document.write('<span style="color:
rgb('+c0+','+c1+','+c2+')">'+blah.substring(i,i+1) +'<\/span>');
}
}

The revised page using the above head script is at:
http://www.cwdjr.net/text/RainbowText.html . Today you can thus save a
huge amount of code.

This page shows age. All we need is a midi of the Beatle's "Lucy In The
Sky" and a few dancing cow animated gifs to make the page true to that
long gone era.

Oct 30 '06 #9

cwdjrxyz wrote:
The revised page using the above head script is at:
http://www.cwdjr.net/text/RainbowText.html .
The page I gave you has a slight flaw in the effect. The correct one is
at http://www.cwdjr.net/text/rainbow_text.html . This page gives the
head script on the main page rather than as an external script. I
served this page as text/html to avoid the trouble of serving as
application/xhtml+xml for browsers that can accept it and for browsers
that require html 4.01 strict. In any event, I doubt if many would want
to use this old dated effect these days :-). I really am going to have
to clean out the closets on the computer and server someday to get rid
of junk such as this that I do not use.

Oct 30 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
8
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
5
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is...
0
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
2
by: Jenny | last post by:
Hello All! I have a long XML file that I should transmit to other computer using http. Problem is that the whole XML Document is too large for one transmitting. What is the nicest way to...
2
by: Jenny | last post by:
Hello All! I have a long XML file that I should transmit to other computer using http. Problem is that the whole XML Document is too large for one transmitting. What is the nicest way to...
1
by: Flemming Hansen | last post by:
Hi guys, I want to load a binary file in to an array by splitting the file in 8 bit pieces. I mean: FileStream s = new FileStream(path, FileMode.OpenOrCreate); // Open StreamReader r = new...
15
by: fyi | last post by:
My new blog on bits and pieces of PHP coding. http://bitspiecesphp.blogspot.com/ Have used all of them. Hope they're as useful to others: Use PHP to track email sender from your web site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.