Jump to content

Search the Community

Showing results for tags 'example'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 10 results

  1. The header file #include<string.h> has not been explained enough. I found this error in the C tutorial -> Structures -> What about strings in structures? -> example 2 that shows the use of strcpy() to copy a string but this will work only if #include<string.h> is used but not explained but it is only found in the "try it" code kindly add a tip about the #include<string.h> header file and why it is used or even better a section on string functions. If at all possible, adding file handling and memory management sections would be great too Thank you very much!
  2. What's the issue? The example I am referring to is the Fisher Yates implementation on this page: https://www.w3schools.com/js/js_array_sort.asp This is the code in question: var points = [40, 100, 1, 5, 25, 10]; for (i = points.length -1; i > 0; i--) { j = Math.floor(Math.random() * i) k = points[i] points[i] = points[j] points[j] = k } If you run the example you will see the elements of the array shuffle around and everything will seem to be working as expected. The issue is subtle. With the above code block the element in the last position of the array can never remain in the last position of the array, and, with each iteration, the last element that is referenced can never remain in that position. Why can't the last element contain the same value after shuffle? It has to do with this statement: j = Math.floor(Math.random() * i) Because Math.random() generates a number between 0 and 1 which is inclusive of 0 but not inclusive of 1, the integer represented by i will never be assigned to j. With the above algorithm, i starts by referencing the last index of the array and therefore j can never be the last index. Why does this matter? This algorithm is supposed to produce an unbiased permutation of the elements meaning that every permutation is equally likely. With this shuffle, any element should have an equal chance of being shuffled into any position in the array including the position it already occupies. "Yeah, but, why would this matter in REAL LIFE?" In a practical example, I've needed to solicit feedback from users in a product. This was done by presenting a question with multiple possible answers. In order to prevent bias in the responses, the order the answers were presented was randomized for each person responding. From a code standpoint, each answer would have always started from the same position in the array. With this implementation, the last answer in the array would have never been the last answer presented to the user. This would have unknowingly introduced a different element of bias and skewed the results. Updated Implementations One possible update which still uses a for loop is to use the length of the array as the starting value of i and to decrement only after j has been randomly selected: var points = [40, 100, 1, 5, 25, 10], i, j, k; for (i = points.length; i > 0;) { j = Math.floor(Math.random() * i--) k = points[i] points[i] = points[j] points[j] = k } This looks a little wonky because even though the third statement in a for loop is optional, this is not a typical implementation. If we're going to decrement i inside of the code block, people typically use a while statement: var points = [40, 100, 1, 5, 25, 10]; var i = points.length, j, k; while (i > 0) { j = Math.floor(Math.random() * i--) k = points[i] points[i] = points[j] points[j] = k } I've also declared j and k before use. Generally it is considered good practice to declare variables before using them and using undeclared variables is not allowed in "strict mode".
  3. I have tried some custom code to insert a road sign image into my lecture title, but it's not showing. Here's my snapshot screen I photoshopped (green highlight). This code is not showing up in the title. <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Liberian_Road_Signs_-_Regulatory_Sign_-_Stop.svg/120px-Liberian_Road_Signs_-_Regulatory_Sign_-_Stop.svg.png" style="width:10%;height:10%;"> Your assistance will be very much appreciated. James
  4. Hi all, please pardon me if i post to wrong section (it took me 3 days to even gain access this site). In your xsd tutorial, the Example 2 description is plain wrong, and it is confusing people. The faulty page is here: https://www.w3schools.com/xml/el_all.asp The error must be there for a long time, it even has its own post on stackoverflow https://stackoverflow.com/questions/5677154/how-do-i-make-items-optional-in-xsall Quote: "The example above indicates that the "firstname" and the "lastname" elements can appear in any order and each element CAN appear zero or one time!" To allow each subelement to be missing, the minOccurs attribute must be put to the subelements, not the xs:all itself. Please fix the embarassing error. :-)
  5. Hello everyone, I have a question about the PHP - AJAX example (http://www.w3schools.com/php/php_ajax_php.asp). In the PHP file, there is the variable " $hint ". But what is this variable used for? Here the code: $q = $_REQUEST["q"];$hint = "";// lookup all hints from array if $q is different from ""if ($q !== "") { $q = strtolower($q); $len=strlen($q); foreach($a as $name) { if (stristr($q, substr($name, 0, $len))) { if ($hint === "") { $hint = $name; } else { $hint .= ", $name"; } } }} You are declaring $hint = "". After there is no input, that could happen to $hint. Why there is the if clause? Maybe I am blind, but I don't get it. Second questions is about this code part: echo $hint === "" ? "no suggestion" : $hint; How you can use operators without function, what does ' $hint === "" ' and what does ' : ' ?I already red the whole example more than twice... but I don't get it. A short explanation or a link to another website which is explaining these would be awesome. Thank you in advance! (By copy and pasting, the example works, but I wanna understand it)(I am not native English speaker, please excuse my mistakes)
  6. Yes I'm a newbie in AJAX '&&' JavaScript. As I'm a pupil here, I find hurdle almost in any code... There is an AJAX code with some number value in it, like 4 - 200, but I can't understand the nature of this digits or what they are indicating... function loadDoc() { var xhttp; if (window.XMLHttpRequest) { // code for modern browsers xhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { document.getElementById("demo").innerHTML = xhttp.responseText; } You see: "== 4 && xhttp.status == 200)" ... what for? Thanks to anyone who'll reply to this 'double-dumb' question!!
  7. According to http://www.w3.org/TR/html5/document-metadata.html#the-base-element shouldn't the example in http://www.w3schools.com/tags/tag_base.asp have a base tag that points to the current page (not just the directory)? That would solve some problems with link fragments and query strings as outlined in e.g. http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag EDIT: This is a possible way I'd modify the example: <head><base href="http://www.w3schools.com/page.html'>http://www.w3schools.com/page.html" target="_blank"></head><body><img src="images/stickman.gif" width="24" height="39" alt="Stickman"><a href="http://www.w3schools.com">W3Schools</a></body>
  8. some of the Angular examples don't work with current version (1.3.11) of angular.js the example at http://www.w3schools...y_ng_controller works fine until you change the version from 1.2.26 to 1.3.11 so changing the line <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> to <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script> breaks the example. This also applies to other examples that use controllers.
  9. CMS/Forum Session/cookie management and security, picking a good example. I am starting an opensource GPL forum project primarily for the sake of learning. I have been looking at the different implementations for user authentication and session management of different CMS and forum packages.Trying to go through and learn what is being done. Also wondering which makes for the best example of a good clean way to implement it.I would prefer to store the bare minimum cookies client side and keep most data in session variables server side.Unless there is a good reason to have another cookie or two, like if it somehow added additional security. SMF & Drupal makes use of the standard session_start(), and both also use database for session management.(more scalable) phpBB3 also uses the databse for session management, but does not use the standard "session_start()"it uses custom implementation using session_begin() , session_create() , session_kill() , session_gc() I like that Drupal only had the one session cookie, however it takes me much longer to follow the functions and understand what is happening with drupal code.In drupal a lot of things are generated like forms etc, using a single function, this is very clean as it reuses a lot of code, however I would rather learn from something easier to follow.I can always make the code more efficient afterwards. mybb seemed to set more cookies than the rest, and did not make use of the standard session_start(), I am unsure if it uses the db for session management. Right now I think I have it narrowed down to either SMF or PHPBB3, I am kinda leaning toward PHPBB because of a post I found: I read this post: https://www.phpbb.co...49840#p12949840 "Stealing a session id/key is not enough to get logged in. The IP must match to the extent defined in the ACP.Also, the browser user-agent must match (enabled by default). Additionally, you can have it check the x_forwarded_for value." I would think the extra checks like user-agent, IP, x_forwarded_for would help mitigate xss and sesion fixation.phpbb3 key function quotes:"Multiple keys may exist for each user representing different browsers or locations."I am curious if they limited the number of sessions per user, so that a malicious user cant intentionally create Tons of session keys on purpose. SMF may have the same checks, I am unsure. (I do not see IP or x_forwarded_for checks in the 'cookies and Sessions' admin section of smf, but they could be hardcoded.) Any insight or opinions on the subject are appreciated, or if you know of another opensource CMS or Forum that I should take a look at as a good example. at the moment I am leaning towards further studying the phpbb3 implementation and tryint to implement something similar.
  10. Hi,I tried to apply this example on my website and it didn't work.The problem is that the text is also included in the opacity and then you get a transparent text: My website: My code: shaltermain.htmlmystyle.css thanks!
×
×
  • Create New...