Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22375 > unrolled thread
| Started by | emf <emfril@gmail.com> |
|---|---|
| First post | 2013-12-23 14:31 -0500 |
| Last post | 2013-12-31 21:44 +0000 |
| Articles | 20 on this page of 49 — 13 participants |
Back to article view | Back to comp.lang.javascript
Compressing js file? emf <emfril@gmail.com> - 2013-12-23 14:31 -0500
Re: Compressing js file? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-23 22:08 -0200
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-23 16:40 -0800
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-24 13:23 -0500
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-26 21:56 -0500
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 09:52 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 08:18 -0500
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 16:59 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-27 15:32 -0500
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 15:12 -0500
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:17 -0500
Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-28 20:20 +0000
XHR with timing issues (was: Compressing js file?) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-27 22:33 +0100
Re: XHR with timing issues (was: Compressing js file?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-27 23:26 +0100
Re: XHR with timing issues Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-28 12:08 +0100
Re: XHR with timing issues emf <emfril@gmail.com> - 2013-12-28 09:04 -0500
Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-27 22:33 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 00:16 -0500
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 11:13 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 11:26 -0500
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-28 13:53 -0500
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-28 21:00 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2013-12-29 21:47 -0500
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-12-31 14:05 -0800
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 02:50 -0500
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 01:16 -0800
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 08:13 -0500
Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-01 14:17 +0000
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:31 -0800
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-01 18:38 -0500
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-01 15:45 -0800
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-02 11:43 -0500
Re: Compressing js file? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-02 09:34 -0800
OT: Compressing js file? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-02 19:52 +0100
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:19 -0500
Re: Compressing js file? emf <emfril@gmail.com> - 2014-01-03 07:31 -0500
Re: Compressing js file? Tim Streater <timstreater@greenbee.net> - 2014-01-02 09:14 +0000
Re: Compressing js file? Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-01 16:25 +0000
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-01 21:36 +0100
Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:06 +0100
Re: Compressing js file? wolfgang zeidler <invalid@invalid.invalid> - 2013-12-29 20:27 +0100
Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-29 18:02 +0000
Re: Compressing js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-30 18:17 +0100
Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 10:52 +0000
Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-31 13:38 +0000
Re: Compressing js file? John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-31 15:02 +0000
Re: Compressing js file? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-01 16:42 +0000
Re: Compressing js file? Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-01 21:32 +0000
Re: Compressing js file? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-31 21:44 +0000
Page 1 of 3 [1] 2 3 Next page →
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-23 14:31 -0500 |
| Subject | Compressing js file? |
| Message-ID | <l9a32q$vkf$1@speranza.aioe.org> |
Since Java has security problems and soon I might have to buy a certificate, I decided to convert my Natal Transits Calculator Java program to JavaScript: Java program, calculating 5 planets: https://files.nyu.edu/emf202/public/jv/nataltransits.html JavaScript program, calculating 2 planets (page still under construction): https://files.nyu.edu/emf202/public/nt/natalTransits.html The issue is this: The programs use a large ephemeris file. The size of the original ephemeris.csv with 5 planets is 2.141 KB. It's in the form of 19000101,01i08,27i43,10i08,25c13,15c15 19000102,01i20,27i50,10i12,25c12,15c14 ... The size of the jar file that includes the compressed ephemeris.csv, the program files, and the code files is only 735 KB! The size of the ephemeris.js with only 2 planets is 1,606 KB. It includes the ephem array that is in the form: var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"], ... ]; The choice of including only 2 planets was *not* made mainly on file size considerations. And BTW, with the JavaScript program I was able to use the Unicode sign symbols, something problematic with the Java program. (I hope everybody out there can see them.) My question is: Is there a way to make the data file smaller and still be able to read it with the JavaScript program? And by smaller, of course, I do not mean eliminating the spaces between the elements of the array that would save only 3%. Thanks, Eustace PS. I remember that last time I visited the newsgroup, more than 1 year ago, it was more active. Where have all the other programmers gone? -- Google's *top* Spherical Triangle Calculator search result! https://files.nyu.edu/emf202/public/js/spherical.html
[toc] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2013-12-23 22:08 -0200 |
| Message-ID | <l9aj9m$7vm$1@speranza.aioe.org> |
| In reply to | #22375 |
On 23-12-2013 17:31, emf wrote: > Since Java has security problems and soon I might have to buy a > certificate, I decided to convert my Natal Transits Calculator Java > program to JavaScript: Then you might be using Scala instead, because JavaScript is not a better option in terms of security. <snip> > My question is: Is there a way to make the data file smaller and still > be able to read it with the JavaScript program? Maybe gzip or minification? I know there are some JavaScript libraries that work with zipped files too, but I'll pass on this one. > PS. I remember that last time I visited the newsgroup, more than 1 year > ago, it was more active. Where have all the other programmers gone? > There have been some important casualties in c.l.js: Kangax, David Mark, Richard Cornford, Asen Bozhilov, Dmitry Soshnikov. The long-term survivors seem to be Thomas Lahn, Dr John Stockton, Evertjian. -- Joao Rodrigues (J.R)
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2013-12-23 16:40 -0800 |
| Message-ID | <9b7e78ae-b456-42bb-bab4-d5ac2d10650b@googlegroups.com> |
| In reply to | #22375 |
On Monday, December 23, 2013 1:31:41 PM UTC-6, emf wrote: > Since Java has security problems and soon I might have to buy a > certificate, I decided to convert my Natal Transits Calculator Java > program to JavaScript: > > Java program, calculating 5 planets: > > https://files.nyu.edu/emf202/public/jv/nataltransits.html > > JavaScript program, calculating 2 planets (page still under construction): > > https://files.nyu.edu/emf202/public/nt/natalTransits.html > > The issue is this: > > The programs use a large ephemeris file. The size of the original > ephemeris.csv with 5 planets is 2.141 KB. It's in the form of > > 19000101,01i08,27i43,10i08,25c13,15c15 > 19000102,01i20,27i50,10i12,25c12,15c14 > ... > > The size of the jar file that includes the compressed ephemeris.csv, the > program files, and the code files is only 735 KB! > > The size of the ephemeris.js with only 2 planets is 1,606 KB. It > includes the ephem array that is in the form: > > var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"], > ... ]; > > The choice of including only 2 planets was *not* made mainly on file > size considerations. And BTW, with the JavaScript program I was able to > use the Unicode sign symbols, something problematic with the Java > program. (I hope everybody out there can see them.) > > My question is: Is there a way to make the data file smaller and still > be able to read it with the JavaScript program? > > And by smaller, of course, I do not mean eliminating the spaces between > the elements of the array that would save only 3%. I'd suggest leaving the data in csv form. On the fly, parse the desired elements using a regular expression to get its components. Alternatively|additionally, use gzip.
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-24 13:23 -0500 |
| Message-ID | <l9cjfl$hmq$1@speranza.aioe.org> |
| In reply to | #22379 |
On 2013-12-23 19:40 Michael Haufe (TNO) wrote: > On Monday, December 23, 2013 1:31:41 PM UTC-6, emf wrote: >> Since Java has security problems and soon I might have to buy a >> certificate, I decided to convert my Natal Transits Calculator Java >> program to JavaScript: >> >> Java program, calculating 5 planets: >> >> https://files.nyu.edu/emf202/public/jv/nataltransits.html >> >> JavaScript program, calculating 2 planets (page still under construction): >> >> https://files.nyu.edu/emf202/public/nt/natalTransits.html >> >> The issue is this: >> >> The programs use a large ephemeris file. The size of the original >> ephemeris.csv with 5 planets is 2.141 KB. It's in the form of >> >> 19000101,01i08,27i43,10i08,25c13,15c15 >> 19000102,01i20,27i50,10i12,25c12,15c14 >> ... >> >> The size of the jar file that includes the compressed ephemeris.csv, the >> program files, and the code files is only 735 KB! >> >> The size of the ephemeris.js with only 2 planets is 1,606 KB. It >> includes the ephem array that is in the form: >> >> var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"], >> ... ]; >> >> The choice of including only 2 planets was *not* made mainly on file >> size considerations. And BTW, with the JavaScript program I was able to >> use the Unicode sign symbols, something problematic with the Java >> program. (I hope everybody out there can see them.) >> >> My question is: Is there a way to make the data file smaller and still >> be able to read it with the JavaScript program? >> >> And by smaller, of course, I do not mean eliminating the spaces between >> the elements of the array that would save only 3%. > > I'd suggest leaving the data in csv form. On the fly, parse the > desired elements using a regular expression to get its components. > Alternatively|additionally, use gzip. I was not aware that I could read a file with JavaScript. I googled it and I started looking on this. I'll follow up here if I encounter insurmountable obstacles and need further expert advice. BTW, I corrected the code so that the program runs in IE too. Thanks, Eustace -- Google's top Spherical Triangle Calculator search result! https://files.nyu.edu/emf202/public/js/spherical.html
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-26 21:56 -0500 |
| Message-ID | <l9iq8h$hsi$1@speranza.aioe.org> |
| In reply to | #22379 |
On 2013-12-23 19:40 Michael Haufe (TNO) wrote:
> On Monday, December 23, 2013 1:31:41 PM UTC-6, emf wrote:
>> Since Java has security problems and soon I might have to buy a
>> certificate, I decided to convert my Natal Transits Calculator Java
>> program to JavaScript:
>>
>> Java program, calculating 5 planets:
>>
>> https://files.nyu.edu/emf202/public/jv/nataltransits.html
>>
>> JavaScript program, calculating 2 planets (page still under construction):
>>
>> https://files.nyu.edu/emf202/public/nt/natalTransits.html
>>
>> The issue is this:
>>
>> The programs use a large ephemeris file. The size of the original
>> ephemeris.csv with 5 planets is 2.141 KB. It's in the form of
>>
>> 19000101,01i08,27i43,10i08,25c13,15c15
>> 19000102,01i20,27i50,10i12,25c12,15c14
>> ...
>>
>> The size of the jar file that includes the compressed ephemeris.csv, the
>> program files, and the code files is only 735 KB!
>>
>> The size of the ephemeris.js with only 2 planets is 1,606 KB. It
>> includes the ephem array that is in the form:
>>
>> var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"],
>> ... ];
>>
>> The choice of including only 2 planets was *not* made mainly on file
>> size considerations. And BTW, with the JavaScript program I was able to
>> use the Unicode sign symbols, something problematic with the Java
>> program. (I hope everybody out there can see them.)
>>
>> My question is: Is there a way to make the data file smaller and still
>> be able to read it with the JavaScript program?
>>
>> And by smaller, of course, I do not mean eliminating the spaces between
>> the elements of the array that would save only 3%.
>
> I'd suggest leaving the data in csv form. On the fly, parse the
> desired elements using a regular expression to get its components.
> Alternatively|additionally, use gzip.
I had read about AJAX and reading files, but had not payed attention to
its possibilities and had managed to forget about it. Using a csv file
is of course better since it's 1178 KB while the js was 1606 KB. (I have
uploaded it at https://files.nyu.edu/emf202/public/nt/ephemeris.csv).
I'll come to the gzip and other issues at a later point.
For now I've written a test webpage to access a local csv file. The code is:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>Read File</title>
<script type="text/javascript">
var reader, ephem = [];
reader = new XMLHttpRequest();
function loadFile() {
reader.open('get', 'ephemeris.csv', true);
reader.send(null);
}
function leapDay(yyyy) {
var lDay;
lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy % 400 ===
0) ? 1 : 0;
return lDay;
}
function isValid(yyyy, mm, dd) {
var valid;
if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
&& !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
valid = true;
} else {
valid = false;
}
return valid;
}
function findBDay() {
var yyyy, mm, dd, yyyyS, mmS, ddS, birthday, i;
yyyy = +document.dataForm.yField.value;
mm = +document.dataForm.mField.value;
dd = +document.dataForm.dField.value;
if ( ((yyyy < 1900) || (yyyy > 2049)) || (!isValid(yyyy, mm,
dd)) ) {
i = -1;
} else {
yyyyS = yyyy.toString();
mmS = (mm < 10) ? "0" + mm : mm;
ddS = (dd < 10) ? "0" + dd : dd;
document.dataForm.mField.value = mmS;
document.dataForm.dField.value = ddS;
birthday = yyyyS + mmS + ddS;
//alert("Press OK to continue.");
for (i = 0; i < ephem.length; i += 1) {
if (birthday === ephem[i][0]) {
break;
}
}
}
return i;
}
function ephemArray(data) {
var i, j, birthday, saturn, uranus;
for (i = 0; i < data.length / 22; i += 1) {
ephem[i] = [];
}
for (i = 0; i < data.length / 22; i += 1) {
j = i * 22;
birthday = data.substr(j, 8);
saturn = data.substr(j + 9, 5);
uranus = data.substr(j + 15, 5);
ephem[i][0] = birthday;
ephem[i][1] = saturn;
ephem[i][2] = uranus;
}
}
function loadData() {
var data;
if(reader.readyState === 4) {
data = reader.responseText;
ephemArray(data);
}
}
function findBirthData() {
var bDay;
loadFile();
reader.onreadystatechange = loadData;
bDay = findBDay();
if (bDay >= 0) {
document.dataForm.outputArea.value +=
"\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " " +
ephem[bDay][2];
} else {
document.dataForm.outputArea.value +=
"\n" + "Invalid entry";
}
}
</script>
</head>
<body onLoad="document.dataForm.outputArea.value='';">
<form name="dataForm" action="">
Enter birthday (yyyy-m-d):
<input type="text" name="yField" value="" size=4> -
<input type="text" name="mField" value="" size=2> -
<input type="text" name="dField" value="" size=2>
<input type="button" value=" Find "
onclick="findBirthData()">
<textarea name="outputArea" rows="16" cols="43"></textarea></td>
</form>
</body>
</html>
The problem is that unless I un-comment the alert in the findBDay
function, the first time I click on the button nothing happens because
ephem hasn't yet be loaded. When I click the button a second time it
works OK.
I tried to start the loadFile() with <body onload="...> but it doesn't
work. I've also tried to delay the execution of the for loop in the
findBDay function while ephem.length is 0, but haven't managed to find a
working solution. Only the alert works, but of course this is not a
satisfactory solution.
Suggestions?
emf
--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-12-27 09:52 +0100 |
| Message-ID | <XnsA2A364854EA0Eeejj99@194.109.133.133> |
| In reply to | #22419 |
emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
> function leapDay(yyyy) {
> var lDay;
> lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy % 400 ===
> 0) ? 1 : 0;
> return lDay;
> }
Better call this isLeapYear(y),
[I presume that is what you ment]
use the Javascript Date object,
and have it return true/false:
[warning: Javascript Januari = month 0]
function isLeapYear(y) {
return !(new Date(y, 1, 29).getMonth()-1);
};
> function isValid(yyyy, mm, dd) {
> var valid;
> if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
> && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
> mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
> valid = true;
> } else {
> valid = false;
> }
> return valid;
> }
same objection to dubious function naming
and lack of possible compactness here:
function isValidDate(y, m, d) {
var t = new Date(y, m-1, d);
return t.getMonth()+1 == m && t.getDate() == d;
};
if you prefer,
[and if you still need the isLeapDayYear at all?]
you could now also do:
function isLeapYear(y) {
return isValidDate(y, 2, 29);
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-27 08:18 -0500 |
| Message-ID | <l9jumc$rbe$1@speranza.aioe.org> |
| In reply to | #22420 |
On 2013-12-27 03:52 Evertjan. wrote:
> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>
>> function leapDay(yyyy) {
>> var lDay;
>> lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy % 400 ===
>> 0) ? 1 : 0;
>> return lDay;
>> }
>
> Better call this isLeapYear(y),
> [I presume that is what you ment]
> use the Javascript Date object,
> and have it return true/false:
> [warning: Javascript Januari = month 0]
>
> function isLeapYear(y) {
> return !(new Date(y, 1, 29).getMonth()-1);
> };
>
>
>> function isValid(yyyy, mm, dd) {
>> var valid;
>> if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
>> && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
>> mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
>> valid = true;
>> } else {
>> valid = false;
>> }
>> return valid;
>> }
>
> same objection to dubious function naming
> and lack of possible compactness here:
>
> function isValidDate(y, m, d) {
> var t = new Date(y, m-1, d);
> return t.getMonth()+1 == m && t.getDate() == d;
> };
>
> if you prefer,
> [and if you still need the isLeapDayYear at all?]
> you could now also do:
>
> function isLeapYear(y) {
> return isValidDate(y, 2, 29);
> };
I first wrote my date subroutines in QBasic in the early '90s soon after
taking a 1 credit course at a Community College. I've kept updating them
as my understanding of programming changed over the years, as I do with
the code of my webpages. Their latest reincarnation is in the JavaScript
program:
https://files.nyu.edu/emf202/public/js/dateCalculator.html
which still works perfectly well and it has historical importance for
me, besides presenting a historian's view on the issue. I haven't,
however, updated the page for some time, and I am well aware I need to
do it, because since I wrote it I've learned Java, which modified my
views for variable names etc. a lot.
Every time I visit this newsgroup and the issue comes up, Dr. John
Stockton always finds some (valid) reason to express his dissatisfaction
with my program, and I've come to accept it as an inevitable fact of life.
I wish I would delve now on your suggestions, but it will have to wait
until I decide to sit down and revise the whole date program.
Cheers,
Eustace
--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-12-27 16:59 +0100 |
| Message-ID | <XnsA2A3ACC496F85eejj99@194.109.133.133> |
| In reply to | #22424 |
emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
> On 2013-12-27 03:52 Evertjan. wrote:
>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>
>>> function leapDay(yyyy) {
>>> var lDay;
>>> lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy % 400 ===
>>> 0) ? 1 : 0;
>>> return lDay;
>>> }
>>
>> Better call this isLeapYear(y),
>> [I presume that is what you ment]
>> use the Javascript Date object,
>> and have it return true/false:
>> [warning: Javascript Januari = month 0]
>>
>> function isLeapYear(y) {
>> return !(new Date(y, 1, 29).getMonth()-1);
>> };
>>
>>
>>> function isValid(yyyy, mm, dd) {
>>> var valid;
>>> if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
>>> && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
>>> mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
>>> valid = true;
>>> } else {
>>> valid = false;
>>> }
>>> return valid;
>>> }
>>
>> same objection to dubious function naming
>> and lack of possible compactness here:
>>
>> function isValidDate(y, m, d) {
>> var t = new Date(y, m-1, d);
>> return t.getMonth()+1 == m && t.getDate() == d;
>> };
>>
>> if you prefer,
>> [and if you still need the isLeapDayYear at all?]
>> you could now also do:
>>
>> function isLeapYear(y) {
>> return isValidDate(y, 2, 29);
>> };
>
> I first wrote my date subroutines in QBasic in the early '90s soon after
> taking a 1 credit course at a Community College. I've kept updating them
> as my understanding of programming changed over the years, as I do with
> the code of my webpages. Their latest reincarnation is in the JavaScript
> program:
>
> https://files.nyu.edu/emf202/public/js/dateCalculator.html
>
> which still works perfectly well and it has historical importance for
> me, besides presenting a historian's view on the issue. I haven't,
> however, updated the page for some time, and I am well aware I need to
> do it, because since I wrote it I've learned Java, which modified my
> views for variable names etc. a lot.
>
> Every time I visit this newsgroup and the issue comes up, Dr. John
> Stockton always finds some (valid) reason to express his dissatisfaction
> with my program, and I've come to accept it as an inevitable fact of life.
>
> I wish I would delve now on your suggestions, but it will have to wait
> until I decide to sit down and revise the whole date program.
Dear Eustace,
Then why do you post those functions, if not to discuss them in this
discussion group?
Methinks such optimalisation mind games cannot wait till you do a complete
revision, as then you would not have the time nor the inclination to play
with these concepts and improve on detailed knowledge of the possibilities
of this modern computer language. [Yes, I project my way of thinking and
learning on you, sorry if you don't like that].
That does not mean you should implement it now in your code, but why not
play with it, like I just did, so that it comes naturally when you enter the
revision state?
Giving comrehensice and sensible names to functions, subroutines if you
like, has come a long way and makes remarks remarkably less obligatory as
compared to the days of assembler programming.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-27 15:32 -0500 |
| Message-ID | <l9ko3r$vdt$1@speranza.aioe.org> |
| In reply to | #22428 |
On 2013-12-27 10:59 Evertjan. wrote:
> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>
>> On 2013-12-27 03:52 Evertjan. wrote:
>>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>>
>>>> function leapDay(yyyy) {
>>>> var lDay;
>>>> lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy % 400 ===
>>>> 0) ? 1 : 0;
>>>> return lDay;
>>>> }
>>>
>>> Better call this isLeapYear(y),
>>> [I presume that is what you ment]
>>> use the Javascript Date object,
>>> and have it return true/false:
>>> [warning: Javascript Januari = month 0]
>>>
>>> function isLeapYear(y) {
>>> return !(new Date(y, 1, 29).getMonth()-1);
>>> };
>>>
>>>
>>>> function isValid(yyyy, mm, dd) {
>>>> var valid;
>>>> if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
>>>> && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
>>>> mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
>>>> valid = true;
>>>> } else {
>>>> valid = false;
>>>> }
>>>> return valid;
>>>> }
>>>
>>> same objection to dubious function naming
>>> and lack of possible compactness here:
>>>
>>> function isValidDate(y, m, d) {
>>> var t = new Date(y, m-1, d);
>>> return t.getMonth()+1 == m && t.getDate() == d;
>>> };
>>>
>>> if you prefer,
>>> [and if you still need the isLeapDayYear at all?]
>>> you could now also do:
>>>
>>> function isLeapYear(y) {
>>> return isValidDate(y, 2, 29);
>>> };
>>
>> I first wrote my date subroutines in QBasic in the early '90s soon after
>> taking a 1 credit course at a Community College. I've kept updating them
>> as my understanding of programming changed over the years, as I do with
>> the code of my webpages. Their latest reincarnation is in the JavaScript
>> program:
>>
>> https://files.nyu.edu/emf202/public/js/dateCalculator.html
>>
>> which still works perfectly well and it has historical importance for
>> me, besides presenting a historian's view on the issue. I haven't,
>> however, updated the page for some time, and I am well aware I need to
>> do it, because since I wrote it I've learned Java, which modified my
>> views for variable names etc. a lot.
>>
>> Every time I visit this newsgroup and the issue comes up, Dr. John
>> Stockton always finds some (valid) reason to express his dissatisfaction
>> with my program, and I've come to accept it as an inevitable fact of life.
>>
>> I wish I would delve now on your suggestions, but it will have to wait
>> until I decide to sit down and revise the whole date program.
>
> Dear Eustace,
>
> Then why do you post those functions, if not to discuss them in this
> discussion group?
You are right. I made a mistake. I should have included just 1 line in
the code:
<script type="text/javascript" src="dateCalculations.js"></script>
so that I wouldn't inadvertently have shifted the focus away from the
immediate problem. Here is the revised code with 3 new alerts:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>Read File</title>
<script type="text/javascript" src="dateCalculations.js"></script>
<script type="text/javascript">
var reader, ephem = [];
reader = new XMLHttpRequest();
function ephemArray(data) {
var i, j, birthday, saturn, uranus;
for (i = 0; i < data.length / 22; i += 1) {
ephem[i] = [];
}
for (i = 0; i < data.length / 22; i += 1) {
j = i * 22;
birthday = data.substr(j, 8);
saturn = data.substr(j + 9, 5);
uranus = data.substr(j + 15, 5);
ephem[i][0] = birthday;
ephem[i][1] = saturn;
ephem[i][2] = uranus;
}
alert("1 " + ephem.length);
}
function loadData() {
var data;
if(reader.readyState === 4) {
data = reader.responseText;
ephemArray(data);
}
}
function loadFile() {
reader.open('get', 'ephemeris.csv', true);
reader.send(null);
}
function findBDay() {
var yyyy, mm, dd, yyyyS, mmS, ddS, birthday, i;
yyyy = +document.dataForm.yField.value;
mm = +document.dataForm.mField.value;
dd = +document.dataForm.dField.value;
if ( ((yyyy < 1900) || (yyyy > 2049)) || (!isValid(yyyy, mm,
dd)) ) {
i = -1;
} else {
yyyyS = yyyy.toString();
mmS = (mm < 10) ? "0" + mm : mm;
ddS = (dd < 10) ? "0" + dd : dd;
document.dataForm.mField.value = mmS;
document.dataForm.dField.value = ddS;
birthday = yyyyS + mmS + ddS;
alert("3 " + ephem.length);
for (i = 0; i < ephem.length; i += 1) {
if (birthday === ephem[i][0]) {
break;
}
}
}
return i;
}
function findBirthData() {
var bDay;
loadFile();
reader.onreadystatechange = loadData;
alert("2 " + ephem.length);
bDay = findBDay();
if (bDay >= 0) {
document.dataForm.outputArea.value +=
"\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " " +
ephem[bDay][2];
} else {
document.dataForm.outputArea.value +=
"\n" + "Invalid entry";
}
}
</script>
</head>
<body onLoad="document.dataForm.outputArea.value='';">
<form name="dataForm" action="">
Enter birthday (yyyy-m-d):
<input type="text" name="yField" value="" size=4> -
<input type="text" name="mField" value="" size=2> -
<input type="text" name="dField" value="" size=2>
<input type="button" value=" Find "
onclick="findBirthData()">
<textarea name="outputArea" rows="16" cols="43"></textarea></td>
</form>
</body>
</html>
I have included 3 alerts to get the ephem.length. In alert 1 the length
is given correctly as 54787. In alert 2, before calling the findBDay
functions it has become 0! In alert 3, inside the bDay function, it has
reverted to 54787.
In the chart below - means that the alert has been commented out. OK
means that I get results without having to click again on the button.
alert 1 alert 2 alert 3 results
54787 0 54787 OK
- 0 54787 OK
54787 - 0 OK
54787 0 - OK
- - 0 OK
- 0 - OK
- - 0 OK
- - - !OK
So if any one alert is executed, we get results with the first click.
Alert 1 always gives 54787.
Alert 2 always gives 0.
Alert 3 gives 54787 if alert 2 has execute before, otherwise it gives 0.
We get results on the first click if any of the 3 alerts has been executed.
Can anybody make sense out of this? I cannot.
Eustace
--
Google's top Spherical Triangle Calculator search result!
https://files.nyu.edu/emf202/public/js/spherical.html
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-28 15:12 -0500 |
| Message-ID | <l9nc1b$18c$1@speranza.aioe.org> |
| In reply to | #22438 |
On 2013-12-27 15:32 emf wrote:
> On 2013-12-27 10:59 Evertjan. wrote:
>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>
>>> On 2013-12-27 03:52 Evertjan. wrote:
>>>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>>>
>>>>> function leapDay(yyyy) {
>>>>> var lDay;
>>>>> lDay = ((yyyy % 4 === 0 && yyyy % 100 !== 0) || yyyy %
>>>>> 400 ===
>>>>> 0) ? 1 : 0;
>>>>> return lDay;
>>>>> }
>>>>
>>>> Better call this isLeapYear(y),
>>>> [I presume that is what you ment]
>>>> use the Javascript Date object,
>>>> and have it return true/false:
>>>> [warning: Javascript Januari = month 0]
>>>>
>>>> function isLeapYear(y) {
>>>> return !(new Date(y, 1, 29).getMonth()-1);
>>>> };
>>>>
>>>>
>>>>> function isValid(yyyy, mm, dd) {
>>>>> var valid;
>>>>> if (yyyy > 0 && mm > 0 && mm <= 12 && dd > 0 && dd <= 31
>>>>> && !(dd === 31 && (mm === 4 || mm === 6 || mm === 9 ||
>>>>> mm === 11)) && !(mm === 2 && dd > 28 + leapDay(yyyy))) {
>>>>> valid = true;
>>>>> } else {
>>>>> valid = false;
>>>>> }
>>>>> return valid;
>>>>> }
>>>>
>>>> same objection to dubious function naming
>>>> and lack of possible compactness here:
>>>>
>>>> function isValidDate(y, m, d) {
>>>> var t = new Date(y, m-1, d);
>>>> return t.getMonth()+1 == m && t.getDate() == d;
>>>> };
>>>>
>>>> if you prefer,
>>>> [and if you still need the isLeapDayYear at all?]
>>>> you could now also do:
>>>>
>>>> function isLeapYear(y) {
>>>> return isValidDate(y, 2, 29);
>>>> };
>>>
>>> I first wrote my date subroutines in QBasic in the early '90s soon after
>>> taking a 1 credit course at a Community College. I've kept updating them
>>> as my understanding of programming changed over the years, as I do with
>>> the code of my webpages. Their latest reincarnation is in the JavaScript
>>> program:
>>>
>>> https://files.nyu.edu/emf202/public/js/dateCalculator.html
>>>
>>> which still works perfectly well and it has historical importance for
>>> me, besides presenting a historian's view on the issue. I haven't,
>>> however, updated the page for some time, and I am well aware I need to
>>> do it, because since I wrote it I've learned Java, which modified my
>>> views for variable names etc. a lot.
>>>
>>> Every time I visit this newsgroup and the issue comes up, Dr. John
>>> Stockton always finds some (valid) reason to express his dissatisfaction
>>> with my program, and I've come to accept it as an inevitable fact of
>>> life.
>>>
>>> I wish I would delve now on your suggestions, but it will have to wait
>>> until I decide to sit down and revise the whole date program.
>>
>> Dear Eustace,
>>
>> Then why do you post those functions, if not to discuss them in this
>> discussion group?
>
> You are right. I made a mistake. I should have included just 1 line in
> the code:
>
> <script type="text/javascript" src="dateCalculations.js"></script>
>
> so that I wouldn't inadvertently have shifted the focus away from the
> immediate problem. Here is the revised code with 3 new alerts:
>
> <!DOCTYPE html>
> <html>
> <head><meta charset="utf-8" />
> <title>Read File</title>
> <script type="text/javascript" src="dateCalculations.js"></script>
> <script type="text/javascript">
>
> var reader, ephem = [];
> reader = new XMLHttpRequest();
>
> function ephemArray(data) {
> var i, j, birthday, saturn, uranus;
> for (i = 0; i < data.length / 22; i += 1) {
> ephem[i] = [];
> }
> for (i = 0; i < data.length / 22; i += 1) {
> j = i * 22;
> birthday = data.substr(j, 8);
> saturn = data.substr(j + 9, 5);
> uranus = data.substr(j + 15, 5);
> ephem[i][0] = birthday;
> ephem[i][1] = saturn;
> ephem[i][2] = uranus;
> }
> alert("1 " + ephem.length);
> }
>
> function loadData() {
> var data;
> if(reader.readyState === 4) {
> data = reader.responseText;
> ephemArray(data);
> }
> }
>
> function loadFile() {
> reader.open('get', 'ephemeris.csv', true);
> reader.send(null);
> }
>
> function findBDay() {
> var yyyy, mm, dd, yyyyS, mmS, ddS, birthday, i;
> yyyy = +document.dataForm.yField.value;
> mm = +document.dataForm.mField.value;
> dd = +document.dataForm.dField.value;
> if ( ((yyyy < 1900) || (yyyy > 2049)) || (!isValid(yyyy, mm,
> dd)) ) {
> i = -1;
> } else {
> yyyyS = yyyy.toString();
> mmS = (mm < 10) ? "0" + mm : mm;
> ddS = (dd < 10) ? "0" + dd : dd;
> document.dataForm.mField.value = mmS;
> document.dataForm.dField.value = ddS;
> birthday = yyyyS + mmS + ddS;
> alert("3 " + ephem.length);
> for (i = 0; i < ephem.length; i += 1) {
> if (birthday === ephem[i][0]) {
> break;
> }
> }
> }
> return i;
> }
>
> function findBirthData() {
> var bDay;
> loadFile();
> reader.onreadystatechange = loadData;
> alert("2 " + ephem.length);
> bDay = findBDay();
> if (bDay >= 0) {
> document.dataForm.outputArea.value +=
> "\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " " +
> ephem[bDay][2];
> } else {
> document.dataForm.outputArea.value +=
> "\n" + "Invalid entry";
> }
> }
> </script>
> </head>
> <body onLoad="document.dataForm.outputArea.value='';">
> <form name="dataForm" action="">
> Enter birthday (yyyy-m-d):
> <input type="text" name="yField" value="" size=4> -
> <input type="text" name="mField" value="" size=2> -
> <input type="text" name="dField" value="" size=2>
> <input type="button" value=" Find "
> onclick="findBirthData()">
> <textarea name="outputArea" rows="16" cols="43"></textarea></td>
> </form>
> </body>
> </html>
>
> I have included 3 alerts to get the ephem.length. In alert 1 the length
> is given correctly as 54787. In alert 2, before calling the findBDay
> functions it has become 0! In alert 3, inside the bDay function, it has
> reverted to 54787.
>
> In the chart below - means that the alert has been commented out. OK
> means that I get results without having to click again on the button.
>
> alert 1 alert 2 alert 3 results
> 54787 0 54787 OK
> - 0 54787 OK
> 54787 - 0 OK
> 54787 0 - OK
> - - 0 OK
> - 0 - OK
> - - 0 OK
this is duplicate; the correct is:
54787 - - !OK
> - - - !OK
>
> So if any one alert is executed, we get results with the first click.
>
> Alert 1 always gives 54787.
>
> Alert 2 always gives 0.
>
> Alert 3 gives 54787 if alert 2 has execute before, otherwise it gives 0.
>
> We get results on the first click if any of the 3 alerts has been executed.
>
> Can anybody make sense out of this? I cannot.
>
> Eustace
Forget the other alerts. Just add 2 alerts before printing in the output
area:
if (bDay >= 0) {
alert(ephem.length);
alert(ephem.length);
document.dataForm.outputArea.value +=
"\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " "
+ ephem[bDay][2];
} else {
document.dataForm.outputArea.value +=
"\n" + "Invalid entry";
}
The first will return 0 and the second 54787! Clearly the first alert
restores the array. This should be a JavaScript bug.
If instead of these 2 alerts we introduce these 2:
alert(typeof(ephem[1]));
alert(typeof(ephem[1]));
they return undefined and object.
So far I have found 2 methods of restoring the array: Introducing an
alert in a later function, or double=clicking the button.I am looking
for a possible third way of bypassing the problem that does not require
user intervention, though it seems I may have to settle with requesting
the user to double-click the Find button.
emf
--
Google's top Spherical Triangle Calculator search result!
https://files.nyu.edu/emf202/public/js/spherical.html
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2014-01-01 02:17 -0500 |
| Message-ID | <la0fee$q8t$2@speranza.aioe.org> |
| In reply to | #22456 |
On 2013-12-28 15:12 emf wrote:
> On 2013-12-27 15:32 emf wrote:
>> On 2013-12-27 10:59 Evertjan. wrote:
>>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
>>>
>>>> On 2013-12-27 03:52 Evertjan. wrote:
>>>>> emf <emfril@gmail.com> wrote on 27 dec 2013 in comp.lang.javascript:
...
>
> Forget the other alerts. Just add 2 alerts before printing in the output
> area:
>
> if (bDay >= 0) {
> alert(ephem.length);
> alert(ephem.length);
> document.dataForm.outputArea.value +=
> "\n" + ephem[bDay][0] + " " + ephem[bDay][1] + " "
> + ephem[bDay][2];
> } else {
> document.dataForm.outputArea.value +=
> "\n" + "Invalid entry";
> }
>
> The first will return 0 and the second 54787! Clearly the first alert
> restores the array. This should be a JavaScript bug.
>
> If instead of these 2 alerts we introduce these 2:
>
> alert(typeof(ephem[1]));
> alert(typeof(ephem[1]));
>
> they return undefined and object.
>
> So far I have found 2 methods of restoring the array: Introducing an
> alert in a later function, or double=clicking the button.I am looking
> for a possible third way of bypassing the problem that does not require
> user intervention, though it seems I may have to settle with requesting
> the user to double-click the Find button.
>
> emf
The problem was corrected after I moved the loadFile() command right
after the loadFile() function. It does make more sense this way.
emf
--
Natal Transits Calculator
https://files.nyu.edu/emf202/public/nt/nataltransits.html
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2013-12-28 20:20 +0000 |
| Message-ID | <ZypAXcArKzvSFw7O@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #22420 |
In comp.lang.javascript message <XnsA2A364854EA0Eeejj99@194.109.133.133>
, Fri, 27 Dec 2013 09:52:53, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:
>function isValidDate(y, m, d) {
> var t = new Date(y, m-1, d);
> return t.getMonth()+1 == m && t.getDate() == d;
>};
ISTM that the OP's argument d, originally two-decimal-digit, will
invariably have a numerical value in the inclusive range 0 to 99. His
dates should be either reliably constructed with exactly 8 digits or
checked to have exactly 8 digits.
For which values of y, m, d is the getDate test beneficial?
<http://jibbering.com/faq/> section 5.2, statement with != .
Aside: To the OP : only if Evertjan does not do it first.
--
(c) John Stockton, nr London UK Reply address via Merlyn Home Page.
news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
<http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-12-27 22:33 +0100 |
| Subject | XHR with timing issues (was: Compressing js file?) |
| Message-ID | <52bdf20e$0$9512$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #22419 |
emf wrote: > The problem is that unless I un-comment the alert in the findBDay > function, the first time I click on the button nothing happens because > ephem hasn't yet be loaded. When I click the button a second time it > works OK. You'd better call open(..., ..., true) on the XHR object *after* you have set the onreadystatechange property. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-12-27 23:26 +0100 |
| Subject | Re: XHR with timing issues (was: Compressing js file?) |
| Message-ID | <81664507.ZzQzUoCc2L@PointedEars.de> |
| In reply to | #22440 |
Christoph Michael Becker wrote: > emf wrote: >> The problem is that unless I un-comment the alert in the findBDay >> function, the first time I click on the button nothing happens because >> ephem hasn't yet be loaded. When I click the button a second time it >> works OK. > > You'd better call open(..., ..., true) on the XHR object *after* you > have set the onreadystatechange property. How did you get *that* idea? In some implementations, the call resets the property value. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-12-28 12:08 +0100 |
| Subject | Re: XHR with timing issues |
| Message-ID | <52beb13b$0$6655$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #22444 |
Thomas 'PointedEars' Lahn wrote: > Christoph Michael Becker wrote: > >> emf wrote: >>> The problem is that unless I un-comment the alert in the findBDay >>> function, the first time I click on the button nothing happens because >>> ephem hasn't yet be loaded. When I click the button a second time it >>> works OK. >> >> You'd better call open(..., ..., true) on the XHR object *after* you >> have set the onreadystatechange property. > > How did you get *that* idea? In some implementations, the call resets the > property value. My bad -- I had intented to write: You'd better call send() on an XHR object initialized with open(..., ..., true) *after* you have set the onreadystatechange property. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-28 09:04 -0500 |
| Subject | Re: XHR with timing issues |
| Message-ID | <l9mlpj$aca$1@speranza.aioe.org> |
| In reply to | #22447 |
On 2013-12-28 06:08 Christoph Michael Becker wrote: > Thomas 'PointedEars' Lahn wrote: > >> Christoph Michael Becker wrote: >> >>> emf wrote: >>>> The problem is that unless I un-comment the alert in the findBDay >>>> function, the first time I click on the button nothing happens because >>>> ephem hasn't yet be loaded. When I click the button a second time it >>>> works OK. >>> >>> You'd better call open(..., ..., true) on the XHR object *after* you >>> have set the onreadystatechange property. >> >> How did you get *that* idea? In some implementations, the call resets the >> property value. > > My bad -- I had intented to write: > > You'd better call send() on an XHR object initialized with open(..., > ..., true) *after* you have set the onreadystatechange property. OK. though I did not have problems with it, but then I haven't yet started working on the web. -emf -- Natal Transits Calculator https://files.nyu.edu/emf202/public/jv/nataltransits.html
[toc] | [prev] | [next] | [standalone]
| From | wolfgang zeidler <invalid@invalid.invalid> |
|---|---|
| Date | 2013-12-27 22:33 +0100 |
| Message-ID | <l9krnd$ppg$1@news.m-online.net> |
| In reply to | #22375 |
emf wrote:
> [...]
>
> The size of the ephemeris.js with only 2 planets is 1,606 KB. It
> includes the ephem array that is in the form:
>
> var ephem = [["19000101","27i43","10i08"], ["19000102","27i50","10i12"], ... ];
>
> [...]
>
> My question is: Is there a way to make the data file smaller and still
> be able to read it with the JavaScript program?
++--------------------------------------++
|| saving bytes for "19000101" etc. ||
++--------------------------------------++
[A]:
var ephem = [[19000101,"27i43","10i08"], [...
and replacing calls like
x = ephem [n] [0]
with
x = ephem [n] [0] . toString ()
should save ~ 6.5%.
[B]:
var ep_off = 19000000
var ephem = [[101,"27i43","10i08"], [...
and replacing calls like
x = ephem [n] [0]
with
x = ( ep_off + ephem [n] [0] ) . toString ()
should save more than 20%.
[C], assuming ephem [n] [0] always
contains the date ( 1900/01/01 + n days ):
Replace calls like
x = ephem [n] [0]
with
x = ephem_func_0 ( n )
with an easy_to_write-function ephem_func_0.
You won't need the first column of ephem furthermore
and you will save ~ 35%.
++--------------------------------------------++
|| saving bytes for "27i43","10i08"" etc. ||
++--------------------------------------------++
[A], imho a little dirty way to write code
( but sometimes done by me ):
var ephem = [19000101,"27i43","10i08", 19000102,...
Replace calls like
x = ephem [n] [0]
y = ephem [n] [m] // m > 0
with
x = ephem [n*3]
y = ephem [n*3+m]
and save ~ 6.5%.
[B], imho a _very_ dirty way to write code:
var ephem = [19000101,"27i4310i08", 19000102,...
Replace calls like
x = ephem [n] [0]
y = ephem [n] [1]
z = ephem [n] [2]
with
x = ephem [n*2] // or ephem [n<<1] to avoid multiplikation
y = ephem [n*2+1] . substr ( 0 , 5 )
z = ephem [n*2+1] . substr ( 5 , 5 )
and save ~ 16.5%.
[C]:
if ( you don't need all rows of ephem at once or
you don't need all columns of ephem at once )
and there is an easy way to calculate ephem [n] [m]
replace calls like
y = ephem [n] [m] // m > 0
with
y = ephem_func_m ( n )
and save a lot of bytes.
>
> Thanks,
>
> Eustace
>
> PS. I remember that last time I visited the newsgroup, more than 1 year
> ago, it was more active. Where have all the other programmers gone?
>
Regards, Wolfgang,
--
http://wzwz.de/mail
---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-28 00:16 -0500 |
| Message-ID | <l9lmri$4kp$1@speranza.aioe.org> |
| In reply to | #22441 |
On 2013-12-27 16:33 wolfgang zeidler wrote: > emf wrote: >> [...] > > >> The size of the ephemeris.js with only 2 planets is 1,606 KB. It >> includes the ephem array that is in the form: >> >> var ephem = [["19000101","27i43","10i08"], >> ["19000102","27i50","10i12"], ... ]; >> >> [...] >> >> My question is: Is there a way to make the data file smaller and still >> be able to read it with the JavaScript program? > > ++--------------------------------------++ > || saving bytes for "19000101" etc. || > ++--------------------------------------++ > > [A]: > var ephem = [[19000101,"27i43","10i08"], [... > and replacing calls like > x = ephem [n] [0] > with > x = ephem [n] [0] . toString () > should save ~ 6.5%. > > [B]: > var ep_off = 19000000 > var ephem = [[101,"27i43","10i08"], [... > and replacing calls like > x = ephem [n] [0] > with > x = ( ep_off + ephem [n] [0] ) . toString () > should save more than 20%. Another idea is to omit the date altogether. And if I use csv instead, [19000101,"27i43","10i08"],. : 28 characters becomes 27i43,10i08. : 12 characters which is about 57% reduction. Then I would subtract 1900-01-01 from the one entered to get the index of the array and avoid going through a loop. I'll have to consider these and your other suggestions after I have given up on compressing the file. If I could compress it, I won't consider further reductions necessary. Thanks, Eustace -- Natal Transits Calculator https://files.nyu.edu/emf202/public/jv/nataltransits.html
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-12-28 11:13 +0100 |
| Message-ID | <XnsA2A472386F7ECeejj99@194.109.133.133> |
| In reply to | #22445 |
emf <emfril@gmail.com> wrote on 28 dec 2013 in comp.lang.javascript:
> Another idea is to omit the date altogether. And if I use csv instead,
>
> [19000101,"27i43","10i08"],. : 28 characters
> becomes
> 27i43,10i08. : 12 characters
>
> which is about 57% reduction. Then I would subtract 1900-01-01 from the
> one entered to get the index of the array and avoid going through a loop.
>
> I'll have to consider these and your other suggestions after I have
> given up on compressing the file. If I could compress it, I won't
> consider further reductions necessary.
While I do not see much use in compression,
integer math is fun,
so if you want it, try to compress/decompress to/from base 36,
using the functions Javascript has in store,
toString() and parseInt():
<script type="text/javascript">
dateCompression(19130101);
dateCompression(20131228);
function dateCompression(d) {
document.write(d + ' [original number]<br>');
var substrac = 19500000;
d = d - substrac;
var dCompressed = d.toString(36).toUpperCase();
document.write(dCompressed + ' [string base 36]<br>');
var dNew = parseInt(dCompressed,36) + substrac;
document.write(dNew + ' [reconstructed number]<br><br>');
};
</script>
The number dnew is in binary
expressed as a decimal string by document.write(),
while the base 36 is a string by itself.
The inputparameter d can be a number or string, try:
dateCompression('19130101');
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2013-12-28 11:26 -0500 |
| Message-ID | <l9mu33$v8d$1@speranza.aioe.org> |
| In reply to | #22446 |
On 2013-12-28 05:13 Evertjan. wrote:
> emf <emfril@gmail.com> wrote on 28 dec 2013 in comp.lang.javascript:
>
>> Another idea is to omit the date altogether. And if I use csv instead,
>>
>> [19000101,"27i43","10i08"],. : 28 characters
>> becomes
>> 27i43,10i08. : 12 characters
>>
>> which is about 57% reduction. Then I would subtract 1900-01-01 from the
>> one entered to get the index of the array and avoid going through a loop.
>>
>> I'll have to consider these and your other suggestions after I have
>> given up on compressing the file. If I could compress it, I won't
>> consider further reductions necessary.
>
> While I do not see much use in compression,
> integer math is fun,
> so if you want it, try to compress/decompress to/from base 36,
> using the functions Javascript has in store,
> toString() and parseInt():
>
> <script type="text/javascript">
>
> dateCompression(19130101);
> dateCompression(20131228);
>
> function dateCompression(d) {
> document.write(d + ' [original number]<br>');
> var substrac = 19500000;
> d = d - substrac;
> var dCompressed = d.toString(36).toUpperCase();
> document.write(dCompressed + ' [string base 36]<br>');
> var dNew = parseInt(dCompressed,36) + substrac;
> document.write(dNew + ' [reconstructed number]<br><br>');
> };
>
> </script>
>
> The number dnew is in binary
> expressed as a decimal string by document.write(),
> while the base 36 is a string by itself.
>
> The inputparameter d can be a number or string, try:
>
> dateCompression('19130101');
As I said elsewhere, eventually I may consider eliminating the date
altogether. I am wondering, however, if I could compress the planetary
positions, which can be expressed as integer minutes. (For example,
17c22 equals (((c-a)*30) + 17) * 60 + 22, where c-a = 2.) How much could
I save compressing these?
emf
--
Google's top Spherical Triangle Calculator search result!
https://files.nyu.edu/emf202/public/js/spherical.html
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web