2016-12-12

Practice Final.

Post your practice final answers here!
(Edited: 2016-12-12)
Post your practice final answers here!

-- Practice Final
Manisha Yalavarthy Isabel Chan Anthony Trinh 3) a. git init name_of_git_repository // initializes the git repository b. git branch my_new_branch_name // creates a new branch c. git format-patch rev1 rev2 // applying a patch of your code to a branch. The patch could then be used by someone else to patch onto their code.
(Edited: 2016-12-12)
Manisha Yalavarthy Isabel Chan Anthony Trinh 3) a. git init name_of_git_repository // initializes the git repository b. git branch my_new_branch_name // creates a new branch c. git format-patch rev1 rev2 // applying a patch of your code to a branch. The patch could then be used by someone else to patch onto their code.

-- Practice Final
Yulong Chen, Thanh Quang
 
9. Define the following terms:
 
Internationalization: adding an application the ability to input, process, and output internatioal text from CSS to DTD. An example of CSS is supporting vertical text or non-Latin typographic features. In DTD, the markup must support bidirectional text.
 
Code point: A character set that is a mapping for some "abstract character" to numbers which are called code points. For example, code point for an "a" is 0x61 in ASCII. Then we have an encoding which maps these numbers into a binary representation that can be stored in the computer.
 
Grapheme: putting two or more unicode code points. Combining two or more letters to create a sound.
(Edited: 2016-12-12)
Yulong Chen, Thanh Quang 9. Define the following terms: Internationalization: adding an application the ability to input, process, and output internatioal text from CSS to DTD. An example of CSS is supporting vertical text or non-Latin typographic features. In DTD, the markup must support bidirectional text. Code point: A character set that is a mapping for some "abstract character" to numbers which are called code points. For example, code point for an "a" is 0x61 in ASCII. Then we have an encoding which maps these numbers into a binary representation that can be stored in the computer. Grapheme: putting two or more unicode code points. Combining two or more letters to create a sound.

-- Practice Final
Question 1 Andre Mak, Adrian Vargas
Comment: This is in Foo.php <?php namespace GooCom\Fud; abstract class Foo{
    public abstract function getFoo();
}

Comment: This is in RealFoo.php <?php namespace GooCom\Fud; class RealFoo extends Foo{
    public function getFoo(){
        return "foo";
    }
}
(Edited: 2016-12-12)
Question 1 Andre Mak, Adrian Vargas Comment: This is in Foo.php <?php namespace GooCom\Fud; abstract class Foo{ public abstract function getFoo(); } ---- Comment: This is in RealFoo.php <?php namespace GooCom\Fud; class RealFoo extends Foo{ public function getFoo(){ return "foo"; } }

-- Practice Final
Give HTML and Javascript necessary to output a form with a phone number field and a submit button. The form will only be submitted if the phone number is a valid phone number in the format (XXX) XXX-XXXX. <!DOCTYPE html> <html> <head>
    <meta charset="utf-8">
</head> <body> <form onsubmit="return validate()">
    <input type="text" id="usrinpt" title="Input"/>
    <input class="submit" type="submit" value="Send" onclick="validate()"/>
</form> <p id="message"></p>
</body> <script> function validate(){
	var string = document.getElementById(usrinpt).value;
    console.log(string);
	if(string.match(/[(]\d{3}[)]\s\d{3}-\d{4}/) && string.length==14){
		document.getElementById('message').innerHTML = "Valid";
	}else{
		document.getElementById('message').innerHTML = "Invalid";
        return false; //doesn't submit form
	}
} </script> </html>
Group names: Bhargava Ramisetty (Sec 3), Nnamdi Eneh (Sec 2), Kito Mam (Sec 3), Anthony Vo (Sec 2)
Give HTML and Javascript necessary to output a form with a phone number field and a submit button. The form will only be submitted if the phone number is a valid phone number in the format (XXX) XXX-XXXX. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <form onsubmit="return validate()"> <input type="text" id="usrinpt" title="Input"/> <input class="submit" type="submit" value="Send" onclick="validate()"/> </form> <p id="message"></p> </body> <script> function validate(){ var string = document.getElementById(usrinpt).value; console.log(string); if(string.match(/[(]\d{3}[)]\s\d{3}-\d{4}/) && string.length==14){ document.getElementById('message').innerHTML = "Valid"; }else{ document.getElementById('message').innerHTML = "Invalid"; return false; //doesn't submit form } } </script> </html> Group names: Bhargava Ramisetty (Sec 3), Nnamdi Eneh (Sec 2), Kito Mam (Sec 3), Anthony Vo (Sec 2)

-- Practice Final
Question 2: Bao Pham, Cassidy Tarng, Kareem Darkazanli
When posting, rather than choose the view and display it, we output a 301 redirect for a location header to some safe page. When the browser goes to that location, it will use GET to request the page. This is used in case of using a back button or refresh button on a POST page. This way, if you refresh or go back, the browser will not resubmit the POST form data back to the server again.
Example: <!DOCTYPE html> <html>
        <head><title> Question 2 </title></head>
        <body>
              <form method = "post">
              <input type = "text" name = "foo"/>
              <input type = "submit" name = "submit"/>
              </form>
       <body>
</html> <?php
   if(isset($_POST['foo']) and !empty($_POST['foo'])){
            //Below is sudo codes
            if(form == valid){
                     success = true;
             }else{
                     success = false;
             }
             if(success){
                    header("location:http://cs174.com/safepage");
                    exit();
             }else{
                    header("location:http://cs174.com/errorpage");
                    exit();
              }
   }
(Edited: 2016-12-12)
Question 2: Bao Pham, Cassidy Tarng, Kareem Darkazanli When posting, rather than choose the view and display it, we output a 301 redirect for a location header to some safe page. When the browser goes to that location, it will use GET to request the page. This is used in case of using a back button or refresh button on a POST page. This way, if you refresh or go back, the browser will not resubmit the POST form data back to the server again. Example: <!DOCTYPE html> <html> <head><title> Question 2 </title></head> <body> <form method = "post"> <input type = "text" name = "foo"/> <input type = "submit" name = "submit"/> </form> <body> </html> <?php if(isset($_POST['foo']) and !empty($_POST['foo'])){ //Below is sudo codes if(form == valid){ success = true; }else{ success = false; } if(success){ header("location:http://cs174.com/safepage"); exit(); }else{ header("location:http://cs174.com/errorpage"); exit(); } }

-- Practice Final
Practice Final Problem 6.
Justin Tu, Benjamin Liu, Zhining Qi
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT BusinessCard (FullName, Position, Business, Address) >
<!ATTLIST BusinessCard VIP (VIP) #FIXED "VIP" >
<!ELEMENT FullName (#PCDATA) >
<!ELEMENT Position (#PCDATA) >
<!ELEMENT Business (#PCDATA) >
<!ELEMENT Address (#PCDATA) >
(Edited: 2016-12-12)
Practice Final Problem 6. Justin Tu, Benjamin Liu, Zhining Qi <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT BusinessCard (FullName, Position, Business, Address) > <!ATTLIST BusinessCard VIP (VIP) #FIXED "VIP" > <!ELEMENT FullName (#PCDATA) > <!ELEMENT Position (#PCDATA) > <!ELEMENT Business (#PCDATA) > <!ELEMENT Address (#PCDATA) >

-- Practice Final
 Nikitha Adira, Shweta Sugnani, Amrit Sandhu, Nanthana Thanonklin, Mirat Panchal
 8. Briefly explain the following two website attacks and explain how to avoid them (a) SQL Injection, (b) target blank attack.
 a. SQL injection attacks are a type of injection attack, in which SQL commands are injected into web-page input in order to effect the execution of predefined SQL commands (to gain access to resources or make changes to data). Can be avoided by: (i) using PHP commands like mysqli_escape_string() or add slashes around posted var to prevent this problem. (ii) Or better yet, use prepared statements rather than ad hoc queries- they are both faster and safer. 
 b. "When a website uses target="_blank" on their links in order to open a new tab or window, that website gives the new page access to the existing window through the window.opener API, allowing it a few permissions. Some of these permissions are automatically negated by cross-domain restrictions, but window.location is fair game."
 
 Some older websites that implement the target="_blank" attribute on links or older browsers that have target="_blank"  are leaving visitors open to data theft and phishing attacks.
 How to fix
 To prevent the attack, should set as rel="noopener noreferrer". I.e.,
 <a href="http://somewhere.com/" target="_blank" rel="noopener noreferrer">Go Somewhere</a>
 
(Edited: 2016-12-12)
Nikitha Adira, Shweta Sugnani, Amrit Sandhu, Nanthana Thanonklin, Mirat Panchal 8. Briefly explain the following two website attacks and explain how to avoid them (a) SQL Injection, (b) target blank attack. a. SQL injection attacks are a type of injection attack, in which SQL commands are injected into web-page input in order to effect the execution of predefined SQL commands (to gain access to resources or make changes to data). Can be avoided by: (i) using PHP commands like mysqli_escape_string() or add slashes around posted var to prevent this problem. (ii) Or better yet, use prepared statements rather than ad hoc queries- they are both faster and safer. b. "When a website uses target="_blank" on their links in order to open a new tab or window, that website gives the new page access to the existing window through the window.opener API, allowing it a few permissions. Some of these permissions are automatically negated by cross-domain restrictions, but window.location is fair game." Some older websites that implement the target="_blank" attribute on links or older browsers that have target="_blank" are leaving visitors open to data theft and phishing attacks. How to fix To prevent the attack, should set as rel="noopener noreferrer". I.e., <a href="http://somewhere.com/" target="_blank" rel="noopener noreferrer">Go Somewhere</a>

-- Practice Final
 Daniel Tam, Anthony Vo(008191248), zixuan huang
 10. Briefly explain with code how to detect screen orientation in Javascript.
 <!DOCTYPE html>
 <html>
     <head>
         <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
         <script>
             $(function(){
                 $('body').bind('orientationchange', function(event){
                     changeOrientation(event.orientation)
                 })
                 function changeOrientation(ori) {
                     $("#orientation").removeClass('portrait landscape');
                     $("#orientation").addClass(ori);
                 }
                 $("body").trigger("orientationchange");
             })
         </script>
         <style>
             div.portrait {
                 <!--CSS for portrait mode-->
             }
             div.landscape {
                 <!--CSS for landscape mode-->
             }
         </style>
     </head>
     <body> 
         <div data-role="content">
         <div id="orientation" class="portrait" >
             <!--Content here-->
         </div>
     </body>
 </html>
Daniel Tam, Anthony Vo(008191248), zixuan huang 10. Briefly explain with code how to detect screen orientation in Javascript. <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> <script> $(function(){ $('body').bind('orientationchange', function(event){ changeOrientation(event.orientation) }) function changeOrientation(ori) { $("#orientation").removeClass('portrait landscape'); $("#orientation").addClass(ori); } $("body").trigger("orientationchange"); }) </script> <style> div.portrait { <!--CSS for portrait mode--> } div.landscape { <!--CSS for landscape mode--> } </style> </head> <body> <div data-role="content"> <div id="orientation" class="portrait" > <!--Content here--> </div> </body> </html>

-- Practice Final
Khoa Vo, Ben Sieben
7.Give an application code example of each of the following in Javascript: (a) timer, (b) XHR request, (c) Promise.
<script>
    function myfunction() {
        alert('Hello World');   
    }
    function test() {
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
            if(this.readyState == 4)
                document.getElementById("test").innerHTML = this.responseText;
        };
        xhttp.open("GET", "test.txt", true);
        xhttp.send();
    }
  var promise = new Promise(function(resolve, reject) {
  var test = 3;
  if (test == 3) {
    resolve("Resolve");
  }
  else {
    reject(Error("Broken"));
  }
}); </script>
<button onclick="setTimeout(myfunction, 3000)">click this</button> <button onclick="test()">change </button> <p id="test"></p>
Khoa Vo, Ben Sieben 7.Give an application code example of each of the following in Javascript: (a) timer, (b) XHR request, (c) Promise. <script> function myfunction() { alert('Hello World'); } function test() { var request = new XMLHttpRequest(); request.onreadystatechange = function() { if(this.readyState == 4) document.getElementById("test").innerHTML = this.responseText; }; xhttp.open("GET", "test.txt", true); xhttp.send(); } var promise = new Promise(function(resolve, reject) { var test = 3; if (test == 3) { resolve("Resolve"); } else { reject(Error("Broken")); } }); </script> <button onclick="setTimeout(myfunction, 3000)">click this</button> <button onclick="test()">change </button> <p id="test"></p>
[ Next ]
X