ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
Fuck off, write it yourself!
-
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?
-
Wordpress?
-
$this->db->select('titles.title_status_id'); Put this line in comments
-
Computer Guess Num Game | Computer Guesses Your Number
ignace replied to xxplosions's topic in PHP Coding Help
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. -
Class, Oop Php, Passing Parameters, Method Calls, String Functions
ignace replied to dani33l_87's topic in PHP Coding Help
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. -
Computer Guess Num Game | Computer Guesses Your Number
ignace replied to xxplosions's topic in PHP Coding Help
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. -
Computer Guess Num Game | Computer Guesses Your Number
ignace replied to xxplosions's topic in PHP Coding Help
@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. -
Computer Guess Num Game | Computer Guesses Your Number
ignace replied to xxplosions's topic in PHP Coding Help
What are you talking about? What security risk? -
mine too! But i already got a custom built compu
-
First Year Course Re Form For Setting Enrollment To School/course
ignace replied to terrancegavan's topic in PHP Coding Help
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 -
Wasn't Sure Where To Post This - Possible Vulnerability?
ignace replied to Beeeeney's topic in Website Critique
Yup. Though a .htaccess may be less cumbersome. -
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 = ?
-
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.
-
Ta da! https://github.com/zendframework/zf2/tree/master/library/Zend/Db GIYF
-
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.
-
Starting With The Binary System - Operating System Creation
ignace replied to ferrari's topic in Miscellaneous
The boot process is explained here: http://computer.howstuffworks.com/pc3.htm -
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.
-
Starting With The Binary System - Operating System Creation
ignace replied to ferrari's topic in Miscellaneous
You should really look into RapsberryPI since it allows you to get familiar with just that. -
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.
-
Starting With The Binary System - Operating System Creation
ignace replied to ferrari's topic in Miscellaneous
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/ -
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).