Transcendental function programming

Written by Charles Douglas Wehner

Programming and chess have much in common.

Those who delve deep intorepparttar mysteries of chess will have discovered that a single move can alterrepparttar 107760 entire game. The ramifications go deep. Each subsequent move (or "ply" inrepparttar 107761 jargon) is conditional upon what went before, andrepparttar 107762 great chess-masters of this world pride themselves in being able to evaluate several ply of consequences.

The elegance of a game of chess is estimated fromrepparttar 107763 efficiency by whichrepparttar 107764 player heads towards his goal. No move must be wasted. There must be no hesitation. There must be no turning back to correct an error. Inrepparttar 107765 final stages -repparttar 107766 deeper ply - one seesrepparttar 107767 reasoning behindrepparttar 107768 earlier, seemingly trivial moves.

Thenrepparttar 107769 game is over. There is a glow of satisfaction, but nothing more. Perhaps, however, there are books written forrepparttar 107770 guidance of others - that they also may knowrepparttar 107771 feeling of achievement. Yet inrepparttar 107772 final analysis it is a GAME. Passions may be aroused, devotees may consider it to be a religion, a philosophy,repparttar 107773 highest accomplishment of human intellect - and still it is a game.

Machine code programming has all these facets - and delivers a PRODUCT as its goal. It is a game and an industry combined.

The programming ofrepparttar 107774 transcendental functions involvesrepparttar 107775 use of mathematics. There are various polynomials forrepparttar 107776 creation of sine, cosine, tangent,repparttar 107777 logarithm and antilogarithm. Slavish obedience to set rules may well deliver a working product - but is itrepparttar 107778 BEST?

Can you become a chess master by memorising a book?

Let us considerrepparttar 107779 McLaurin-Taylor polynomial forrepparttar 107780 natural antilogarithm. Do you take 1, then addrepparttar 107781 argument X? Do you now multiplyrepparttar 107782 X byrepparttar 107783 X and divide by 2 before adding it on? Do you multiply X by X by X, divide by 2, divide by 3, and also add on? Is thisrepparttar 107784 best?

Horner's rule says you can PRE-divide a large number such as 1 00000000 00000000 00000000 00000000 in binary (FFFFFFFF in Hex, 4294967296 in decimal) by 2, by 3 and so on, and build it into your code. Thenrepparttar 107785 machine does not have to waste time creating constants. The rule also says that you start atrepparttar 107786 end ofrepparttar 107787 polynomial and work backwards. So if you multiplyrepparttar 107788 last coefficient by X, and add onrepparttar 107789 penultimate before multiplying again,repparttar 107790 last will have X-squared in it whilstrepparttar 107791 penultimate will have X. So it costs only one addition and one multiplication per term.

PHP in the Command Line

Written by Robert Plank

There's a single line you can add to your web host's control panel that will automatically archive your content.


Ever run commands in DOS? You've used a shell. A "shell" inrepparttar computer world is a place where you enter commands and run files by name rather than clicking around different windows.

Most web hosts let you operate a shell remotely. This means that you can type commands in window on your computer, that are actually run on your web host, thousands of miles away.

I'd like you to log in to your shell now. If you can't do it by going in to DOS and typing "telnet", your web host probably uses "SSH" -- a secure shell. You'll have to ask your host how you can log in torepparttar 107759 shell, they might tell you to download a program called "PuTTY" and give instructions how to use it.

If you can't login to your shell, or aren't allowed, you'll just have to sit back and watch what I do.

Now that you're logged in, type: echo hi

Onrepparttar 107760 next line will be printed hi

Try this: date +%Y

This printsrepparttar 107761 current year. That's 2004 for me.

So what if we combinedrepparttar 107762 two? Try: echo date +%Y

Well, that doesn't work, becauserepparttar 107763 computer thinks you're trying to echorepparttar 107764 TEXT "date +%Y" instead ofrepparttar 107765 actual COMMAND. What we have to do here is surround that text in what are called "back quotes". Unix will evaluate everything enclosed in back quotes (by evaluate, I mean it'll treat that text as if it were entered as a command.)

Your back quotes key should be located onrepparttar 107766 upper-left corner of your keyboard, underrepparttar 107767 Esc button.


Type this in: echo `date +%Y`

Gives us "2004". You could even do something like this: echo `dir`

Which putsrepparttar 107768 directory listing all on one line.

But now, we put our newfound knowledge to good use. Unix has another neat feature called piping, which means "take everything you would normally output torepparttar 107769 screen here, and shove it whatever file I tell you to." So say I had something like this:

echo "hey" > test.txt

Now type "dir" and you'll see a new file, test.txt, that wasn't there before. View it offrepparttar 107770 web, or FTP it to your computer, do whatever you have to, to readrepparttar 107771 file. It should containrepparttar 107772 word "hey".

Likewise, dir > test.txt would storerepparttar 107773 directory listing into "test.txt".


But say we wanted that text file to be named according torepparttar 107774 current date. You already haverepparttar 107775 pieces to figure all that out, if you think about it. Type: date --help to get a listing of allrepparttar 107776 possible ways to representrepparttar 107777 date. The ones you want to representrepparttar 107778 year, month and day are %Y, %m, and %d (capitalization *is* important here).

This is what you want: echo `date +%Y%m%d.html`

Running this today, January 8th, 2004, results in: 20040108.html

I've just echoed this year, followed by this month and this day, with an ".html" atrepparttar 107779 end. This will be our output file.

Now, to pipe it: echo "hey" > `date +%Y%m%d.html`

If this sort of thing were to run every day, it would save "hey" to a file called 20040108.html today, and tomorrow to a file called 20040109.html, then 20040110.html, and so on.

The easy part now, is figuring out what you want archived. I use wget, which takes an option to storerepparttar 107780 output file, so we don't need to use piping. Here's an example of how to use wget to saverepparttar 107781 page "" to a file representing today's date:

wget --output-document=`date +%Y%m%d.html`


And now, to setup your crontab. I won't explain how crontabs work, just that they'rerepparttar 107782 equivalent ofrepparttar 107783 Windows Task Scheduler, which automatically run a particular command at a given date and time. The following will save to a different filename every day.

0 0 * * * wget --output-document=`date +%Y%m%d.html` > /dev/null

Keep in mind that if you want to put it in a special directory, just putrepparttar 107784 path in, i.e. change what's inrepparttar 107785 "output document" parameter to: `date +/home/user/wwwroot/`

I've pipedrepparttar 107786 output to /dev/null because wget savesrepparttar 107787 file for us, and there's no reason to do anything else withrepparttar 107788 output.

Cont'd on page 2 ==> © 2005
Terms of Use