Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. I know C++ but not yet Python. I also guess my C++ will be quite rusty since it's been 5+ years since I last wrote it
  2. I like Spotify. I can't wait for this to be released! Will I also get 20 hours of free video then? Is there also a HTTP/FTP back-up for those who don't have a near P2P network? Will it be able to work with mirrors (P2P+HTTP+..)?
  3. The grass is always greener... So maybe their puzzles are more interesting then ours?
  4. I did in my editing session but my internet connection went dead and didn't come back on until now (after they replaced the modem). So here goes: @OP: <table> <tr> <?php for ($i = 0, $total = 0, $number = mt_rand(1,100); $i++ < 100/*cols*/; $total += $number, $number = mt_rand(1,100)): ?> <td style="background:<?php print !($number % 3) ? '#C00' : (!($number % 2) ? '#0C0' : '#FFF'); ?>"><?php print $number; ?></td> <?php endfor; ?> </tr> </table> Average: <?php print $total / 100/*cols*/; ?> A more expanded example would be: <table> <tr> <?php $total = 0; $number = mt_rand(1,100); // get a starting random number for ($i = 0; $i < 100/*number of cells you want to generate*/; ++$i) { $color = '#FFF'; // default color if (($number % 3) == 0) { // same as !($number % 3) $color = '#C00'; // red } else if (($number % 2) == 0) { $color = '#0C0'; // blue } print '<td style="background:' . $color . '">' . $number . '</td>'; $total += $number; $number = mt_rand(1,100); // new random number to feed the next iteration } ?> </tr> <caption>Average: <?php print $total / 100; ?></caption> </table> This will create 100 columns, if you want to create a specific set of rows/cols you should amend the code. The above examples should give you a good understanding of how you can generate the different cells with the numbers and calculate the average at the end.
  5. Each of the cells in the table will hold a random number between 1 and 100 (hint: look at mt_rand() function). If the number is a multiple of 3, display the cell with a red background color; if not a multiple of 3 but a multiple of 2, display the cell with a blue background color. Finally, display the average for all cells. <table> <tr> <?php for ($i = 0, $total = 0, $number = mt_rand(1,100); $i++ < 100/*cols*/; $number = mt_rand(1,100), $total += $number): ?> <td style="background:<?php print !($number % 3) ? '#C00' : (!($number % 2) ? '#0C0' : '#FFF'); ?>"><?php print $number; ?></td> <?php endfor; ?> </tr> </table> Average: <?php print $total / 100/*cols*/; ?>
  6. ignace

    Classes

    In procedural you would write something like: function login($username, $password) { global $user; if (login successfull) { $user = $userdata; } } In OO you would write: class User { private $data; public function login($username, $password) { if (login successfull) { $this->data = $userdata; } } } The difference is that in procedural: 1. You do not control access to the $user variable which allows name collissions with 3rd party scripts and thus unexpected/uncontrolled behavior in your code. 2. Your function becomes highly dependent on the context it is used in (only works if a $user variable exists). This is also why they advice you not to use global variables inside your functions.
  7. ignace

    Classes

    Like thorpe said classes encapsulate behavior and state. Without classes you would be looking at global variables and functions that manipulate those variables. However you do not control access to those global variables so the variables your functions depend on can be modified by any 3rd party script you introduce since both you and the 3rd party script happen to have a $user variable. To avoid any name collisions you would use a class or now with 5.3 namespaces (although namespaces are not entirely safe).
  8. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=339119.0
  9. Or use OPA (http://www.opalang.org) to build your own Chat.
  10. @andy10901 "Our basic Hosting packages will include Corn Jobs" What's a Corn Job?
  11. It's good to see that I'm not the only one sometimes posting a response in the wrong thread
  12. A robots.txt doesn't prohibit them from scanning it anyway. Can you elaborate what you want to achieve? If no one may look into the directory you can use a .htaccess to disable directory scanning using: Options -Indexes This is the recommended method.
  13. Euhm... Create a .htaccess file and see if your rewrite works? Download WampServer if you haven't got a local server running for testing.
  14. If you only want to increase your post count make it then at the very least subtle.
  15. dayNaming(); dayDisplay(); monthNaming(); betterSec(); betterMin(); This is what I mean with bad function naming. Everybody would have to make a wild guess as to what these functions do or read through it's function body while instead they should be just black boxes. dayNaming() would be better if you called it something along the lines of convertWeekDayToFullName() as that describes it's behavior and pass the weekDay in instead of just grabbing it from the global namespace, I advice you to do this for all functions using global variables. You also have duplicate code betterMin() and betterSec() do the same thing, generalize the function and give it a proper name.
  16. It's fine for a first script but it has a lot of flaws. Before you start writing software for someone else to use, try to write some software for your own and re-use it on multiple projects. You'll start to notice the flaws in your script. Some pointers: 1. Use of global variables in a function 2. Bad variable/function naming 3. Strongly coupled to specific HTML 4. Hard to test
  17. Indeed. We wouldn't be able to call ourselves Sith Lords if we did.
  18. It found your RAM attractive? Either you or someone else downloaded it obviously as you can download it for free.
  19. It's used by script kiddies around the world, so yes it's a backdoor
  20. It's actually quite nice of that hacker to tell us what we should look out for? Here's a blog post about the script you found (c99madshell): http://www.derekfountain.org/security_c99madshell.php
  21. I unpacked it and pasted the source code here: http://pastebin.com/kJHP8BcZ
  22. ignace

    Google+

    Were you expecting smoke signals or nice pictures on the wall then?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.