Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Fuck off, write it yourself!
  2. And you are the idiot who posted in a topic that hasn't had a reply in over 6 months. We all have our defects, right?
  3. Wordpress?
  4. $this->db->select('titles.title_status_id'); Put this line in comments
  5. Which could have been reduced to 1 and still make your point. Where would I have implied they would have to be used at the same time? You can't run functions in parallel you know? I could do the same you did by doing this, without duplicating code: function computer_guess($number, $callback) { .. } function computer_guess1($number) { return computer_guess($number, function($min, $max) { /* rand strategy #1 */ }); } function computer_guess2($number) { return computer_guess($number, function($min, $max) { /* rand strategy #2 */ }); } .. It was an example to prove my point: "never make assumptions" and don't think: "it will never happen" because it will! Functions are re-usable components leaving input validation to the outer code means your code could break at some point when the function is re-used and input validation is forgotten before calling your function not to mention that you have to copy the validation code over and over again whenever you use the function. This is nothing personal. You made a mistake and I called you on it just like you called me on my mistake with your rand strategy with the sole goal of learning. I just wanted to show you that in order to write robust software your functions should perform the input validation not the calling code for the obvious reason you are otherwise copying or will have variations in validation across your codebase. If you want 1 to 100 you do it like this: if ($number >= 1 && $number <= 100) { Don't use preg_match for something the programming language can do.
  6. I just want to add that this functionality should indeed be in the Person class not outside of it, otherwise you will just be copying code around your project whenever you need the person's first name. class Person { private $fullName; public function __construct($fullName) { $this->fullName = $fullName; } public function getFullName() { return $this->fullName; } public function getFirstName() { $words = str_word_count($this->getFullName(), 1); return $words[0]; } } Also just returning the first word could as easily be 'Dr.' which is not what was intended.
  7. Are you really that ignorant? So you think there is a real valid reason for not generalizing your code when you have 5 similar functions with only the $guess varying? >_< Functions are re-usable components. This means you re-use the function not the code written around it. Therefor should your function always assume there was NO validation on the data passed through. LOL // no need to bother to prevent sql injection, it will never happen! MMDE said so! $sql = "SELECT * FROM users WHERE user = '$user' AND pass = '$pass';"; $res = mysqli_query($conn, $sql); .. } You are right. I brain farted here because all your code is jammed against each other I guess.
  8. @MMDE When it comes to programming you have much to learn.. 1) Your 5 functions can be reduced to 1 using callbacks: function computer_guess($number, $guess_callback){ $min = 0; $max = 999; $guess = call_user_func($callback, $min, $max); for ($guesses = 1; $guess != $number; $guesses++, $guess = call_user_func($callback, $min, $max)){ if ($number < $guess) { $max = $guess-1; } else { $min = $guess+1; } } return $guesses; } echo 'Computer guessed the number 50 in ' . guess(50, function($min, $max) { return round($max-(($max-$min)/2)); }) . ' guesses!'; 2) The logic in your function is flawed: A ) computer_guess1(1000); Creates an infinite loop as the computer will never be able to guess the number. While a simple: if ($number > $max) return 'Does not compute!'; Would have prevented that. B ) If the user changes the max to a much higher number, say PHP_INT_MAX, it will take a very long time to find the number instead you should have used what is already mentioned and what normal people tend to do, use 50% incr/decr to narrow down the range in which the number is located. Once you have located the proper range (answer 10 gives a higher, 15 gives a lower) should you do a last 50% and listen for the answer to know from which offset you need to decr/incr.
  9. What are you talking about? What security risk?
  10. mine too! But i already got a custom built compu
  11. Keep it to one topic please http://forums.phpfreaks.com/topic/270368-first-year-course-re-form-for-setting-enrollment-to-schoolcourse/
  12. Well, create all required files first. Then using SplFileObject you can retrieve all lines as such: $file = new SplFileInfo('data/course.csv'); $fileObj = $file->openFile('rb+'); // read $fileObj->setFlags($fileObj::READ_CSV); $fileObj->setCsvControl(' :: ', '', ''); foreach ($fileObj as $line) { print_r($line); } This should print out all the lines in your files. To write you do the reverse: $file = new SplFileInfo('data/enrollment.csv'); $fileObj = $file->openFile('wb+'); // write $fileObj->setCsvControl(' :: ', '', ''); foreach ($students as $enrollment) { $fileObj->fputcsv($enrollment); } You may want to wrap this inside a class: class ProprietaryCsvFile { const DELIMITER = ' :: '; const ENCLOSURE = ''; const ESCAPE = ''; private $file; private $reader; private $writer; public function setFile(SplFileInfo $file) { if (!$file instanceof SplFileInfo) { throw new InvalidArgumentException; } $this->file = $file; $this->refresh(); } public function refresh() { $this->reader = null; $this->writer = null; } private function getReader() { if (!$this->reader) { $obj = $this->file->openFile('rb+'); $obj->setFlags($obj::READ_CSV | $obj::SKIP_EMPTY | $obj::DROP_NEW_LINE); $obj->setCsvControl($this::DELIMITER, $this::ENCLOSURE, $this::ESCAPE); $this->reader = $obj; } return $this->reader; } private function getWriter() { if (!$this->writer) { $obj = $this->file->openFile('wb+'); $obj->setCsvControl($this::DELIMITER, $this::ENCLOSURE, $this::ESCAPE); $this->writer = $obj; } return $this->writer; } public function read() { return $this->getReader()->fgetcsv(); } public function readAll() { $lines = new ArrayObject(); foreach ($this->getReader() as $line) { $lines->append($line); } return $lines; } public function write(array $line) { $this->getWriter()->fputcsv($line); } public function writeAll(array $lines) { foreach ($lines as $line) { $this->write($line); } } } $file = new ProprietaryCsvFile; $file->setFile(new SplFileInfo('data/students.csv')); print_r($file->readAll()); Returns all students. To check if a the maximum enrollment has not been exceeded and the student isn't already enrolled is just reading out the proper files and running some checks. What your teach. wrote here was that you should keep it basic <form/> <table/> <input/> stuff and is nothing special so nothing hackable there
  13. Yup. Though a .htaccess may be less cumbersome.
  14. ignace

    Webdav

    A simple yes or no. SELECT files.* FROM users_files JOIN users ON users_files.user_id = users.user_id JOIN files ON users_files.file_id = files.file_id WHERE users.user_id = ?
  15. ignace

    Webdav

    Well, do they login to the webdav? If they do, then it's quite easy to send back only the files they have access to.
  16. How about PDO itself? Why would you want to wrap PDO inside a class? From your example above I don't see you add anything useful.
  17. Ta da! https://github.com/zendframework/zf2/tree/master/library/Zend/Db GIYF
  18. ignace

    Webdav

    You need to use the ACL: http://code.google.com/p/sabredav/wiki/ACL Assuming the users have to login to access the WebDAV, you can filter the nodes they have access to with the ACL.
  19. ignace

    Webdav

    It's all right there: http://code.google.com/p/sabredav/wiki/VirtualFilesystems
  20. The boot process is explained here: http://computer.howstuffworks.com/pc3.htm
  21. There are more handy tools available pressing F12 for example in Chrome or Firefox shows a developer console. Also tools like ChromePHP or FirePHP are really handy for debugging from the server-side of things without having to resort to things like var_dump and print_r.
  22. You should really look into RapsberryPI since it allows you to get familiar with just that.
  23. Yes. var is the same as public, but I strongly recommend you adhere to the set* get* methods instead of allowing direct modification of the properties.
  24. So, you want to create an OS? PHP is not suited for this task, instead you should look at Java or C. Also I really advice against writing this from scratch since it's easy to get it wrong and really screw up your computer. Resources: http://www.codeproject.com/KB/system/MakingOS.aspx http://www.linuxfromscratch.org/ http://susestudio.com/#login If you really just want to experiment and familiarize yourself with the hardware side of things. I strongly recommend you try: http://www.raspberrypi.org/
  25. Please verify what you write before writing it down and assuming: class MyClass { $classVar1; } Results in: Properties should always have a visibility defined (var, public, private, or protected, though the use of var is discouraged).
×
×
  • 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.