ajax1.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

78: ajax1 79: 80: 81:
82: Symbol: 83:

84: 85:
86: 87:

2/2

ajax2.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

78: ajax2 79: 80: 81:
82: Symbol: 83:
84: Price: to be determined 85:

86: 87:
88: 89:

2/2

ajax3.html

1/3

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

ajax3
Symbol:

ajax3.html

3/3

lectures/9/src/ajax/ 91:

92: 96:
97:

98: 99:
100: 101:

ajax4.html

1/2

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

69: ajax4 70: 71: 72:
73: Symbol: 74:

75: 76:
77: 78:

ajax5.html

1/3

lectures/9/src/ajax/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

ajax5


ajax5.html lectures/9/src/ajax/ 91: Symbol: 92:

93: Price: 94:
95: High: 96:
97: Low: 98:
99:

100: 101:
102: 103:

3/3

quote1.php

1/1

lectures/9/src/ajax/ 1:

/** * quote1.php * * Outputs price of given symbol as text/html. * * Computer Science 50 * David J. Malan */ // get quote $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?s={$_GET["symbol"]}&f=e1l1", "r"); if ($handle !== FALSE) { $data = fgetcsv($handle); if ($data !== FALSE && $data[0] == "N/A") print($data[1]); fclose($handle); }

quote2.php lectures/9/src/ajax/ 1:

/** * quote2.php * * Outputs price, low, and high of given symbol as text/html, after * inserting an artificial delay. * * Computer Science 50 * David J. Malan */ // pretend server is slow sleep(5); // try to get quote $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?s={$_GET["symbol"]}&f=e1l1hg", "r"); if ($handle !== FALSE) { $data = fgetcsv($handle); if ($data !== FALSE && $data[0] == "N/A") { print("Price: {$data[1]}"); print("
"); print("High: {$data[2]}"); print("
"); print("Low: {$data[3]}"); } fclose($handle); }

1/1

quote3.php

1/1

lectures/9/src/ajax/ 1:

/** * quote3.php * * Outputs price, low, and high of given symbol as JSON. * * Computer Science 50 * David J. Malan */ // try to get quote $quote = array(); $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?s={$_GET["symbol"]}&f=e1l1hg", "r"); if ($handle !== FALSE) { $data = fgetcsv($handle); if ($data !== FALSE && $data[0] == "N/A") { $quote["price"] = $data[1]; $quote["high"] = $data[2]; $quote["low"] = $data[3]; } fclose($handle); } header("Content-type: application/json"); print(json_encode($quote));

dump.php lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:

dump
  

1/1

form1.html

1/1

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:

form1
Email:
Password:
Password (again):
I agree to the terms and conditions:



form2.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form2.html

2/2

lectures/9/src/forms/ 46: form2 47: 48: 49:
50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59:
60: 61:

form3.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form3.html

2/2

lectures/9/src/forms/ 46: form3 47: 48: 49:
50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59:
60: 61:

form4.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

54: form4 55: 56: 57:
58: Email: 59:
60: Password: 61:
62: Password (again): 63:
64: I agree to the terms and conditions: 65:

66: 67:
68: 69:

form5.html

1/2

lectures/9/src/forms/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:



form5.html

2/2

lectures/9/src/forms/ 46: form5 47: 48: 49:
50: Email: 51:
52: Password: 53:
54: Password (again): 55:
56: I agree to the terms and conditions: 57:

58: 59:
60: 61:

dictionary.php

1/2

lectures/9/src/mispellings/ 1:
/*********************************************************************** * dictionary.php * * Computer Science 50 * David J. Malan * * Implements a dictionary. **********************************************************************/ // size of dictionary $size = 0; // dictionary $dictionary = array(); /* * bool * check($word) * * Returns TRUE if word is in dictionary else FALSE. */ function check($word) { global $dictionary; if ($dictionary[strtolower($word)]) return TRUE; else return FALSE; } /* * bool * load($dict) * * Loads dict into memory. */ function load($dict) {

Returns TRUE if successful else FALSE.

dictionary.php

2/2

lectures/9/src/mispellings/ 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: ?>

global $dictionary, $size; if (!file_exists($dict) && is_readable($dict)) return FALSE; foreach (file($dict) as $word) { $dictionary[chop($word)] = TRUE; $size++; } return TRUE; } /* * int * size() * * Returns number of words in dictionary if loaded else 0 if not yet loaded. */ function size() { global $size; return $size; } /* * int * unload() * * Unloads dictionary from memory. */

Returns TRUE if successful else FALSE.

function unload() { return TRUE; }

speller lectures/9/src/mispellings/ 1: #!/usr/bin/php 2:
1/4

speller

2/4

lectures/9/src/mispellings/ 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90:

{ print("Could not load $dict.\n"); return 2; } // calculate time to load dictionary $ti_load = $after - $before; // try to open file $file = ($argc == 3) ? $argv[2] : $argv[1]; $fp = fopen($file, "r"); if ($fp === FALSE) { print("Could not open $file.\n"); return 3; } // prepare to report misspellings printf("\nMISSPELLED WORDS\n\n"); // prepare to spell-check $word = ""; $index = 0; $misspellings = 0; $words = 0; // spell-check each word in file for ($c = fgetc($fp); $c !== FALSE; $c = fgetc($fp)) { // allow alphabetical characters and apostrophes (for possessives) if (preg_match("/[a-zA-Z]/", $c) || ($c == "’" && $index > 0)) { // append character to word $word .= $c; $index++; // ignore alphabetical strings too long to be words if ($index >= LENGTH) { // consume remainder of alphabetical string while (($c = fgetc($fp)) !== FALSE && preg_match("/[a-zA-Z]/", $c)); // prepare for new word $index = 0; $word = ""; } }

speller

3/4

lectures/9/src/mispellings/ 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135:

// ignore words with numbers (like MS Word) else if (ctype_digit($c)) { // consume remainder of alphabetical string while (($c = fgetc($fp)) !== FALSE && preg_match("/[a-zA-z0-9]/", $c)); // prepare for new word $index = 0; $word = ""; } // we must have found a whole word else if ($index > 0) { // update counter $words++; // check word’s spelling $before = microtime(TRUE); $misspelled = !check($word); $after = microtime(TRUE); // update benchmark $ti_check += $after - $before; // print word if misspelled if ($misspelled) { print("$word\n"); $misspellings++; } // prepare for next word $index = 0; $word = ""; } } // close file fclose($fp); // determine dictionary’s size $before = microtime(TRUE); $n = size(); $after = microtime(TRUE); // calculate time to determine dictionary’s size

speller

4/4

lectures/9/src/mispellings/ 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: ?>

$ti_size = $after - $before; // unload dictionary $before = microtime(TRUE); $unloaded = unload(); $after = microtime(TRUE); // abort if dictionary not unloaded if (!$unloaded) { print("Could not load $dict.\n"); return 5; } // calculate time to determine dictionary’s size $ti_unload = $after - $before; // report benchmarks printf("\nWORDS MISSPELLED: printf("WORDS IN DICTIONARY: printf("WORDS IN FILE: printf("TIME IN load: printf("TIME IN check: printf("TIME IN size: printf("TIME IN unload: printf("TOTAL TIME:

%d\n", $misspellings); %d\n", $n); %d\n", $words); %.2f\n", $ti_load); %.2f\n", $ti_check); %.2f\n", $ti_size); %.2f\n", $ti_unload); %.2f\n\n", $ti_load + $ti_check + $ti_size + $ti_unload);

ajax1.html 1/2 ajax1.html 2/2 - CS50 CDN

3: ajax1.html. 4: 5: Gets stock quote from quote1.php via Ajax, displaying result with alert(). 6: 7: Computer Science 50. 8: David J. Malan. 9: 10: -->. 11: 12:

66KB Sizes 2 Downloads 399 Views

Recommend Documents

52/cs50! - CS50 CDN
SSH. • Secure Shell. • Allows you to access another computer through command-‐line interface. • We use SSH to connect to the CS50 Cloud!

52/cs50! - CS50 CDN
A condi on may have two values: true or false. • May be expressed as a logical expression or a. 'bool' variable. • Can be thought of as a yes/no ques on, or a.

CS50 Walkthrough 1 - CS50 CDN
Free Candy. ▫ Time for Change. ▫ I Saw You ... Free Candy. ▫ Seriously, in the CS50 ... ask user for an integer printf("Give me an integer between 1 and 10: ");.

CS50 Walkthrough #3 - CS50 CDN
Go to middle if k < value at middle search for k between first and the one before the middle if k > value at middle search for k between one after the middle and last if k = value at middle return true. If you haven't found k after this loop, return

Merge Sort - CS50 CDN
Data stored in memory has both a value and a location. • Pointers contain the memory address of some piece of data. • * pointer contains address to a ...

pset4 - CS50 CDN
Oct 8, 2010 - Go ahead and execute the command below: hostname. Recall that cloud.cs50.net is actually a cluster of servers. That command tells you the name of the specific server in the cluster that you happen to be connected to at the moment. Take

Merge Sort - CS50 CDN
Data stored in memory has both a value and a location. • Pointers contain the memory address of some piece of data. • * pointer contains address to a ...

CS51 - CS50 CDN
We can still conceptualize & prototype using the right language abstractions. ▻ If we understand relationships between linguistic abstractions, we can realize ...

Untitled - CS50 CDN
http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Characteristics/Characteristics.html ... content="yes"> http://developer.apple.com/library/safari/documentation/appleapplications/reference/SafariHTMLRef/Article

Asymptotic Notation - CS50 CDN
Like searching through the phone book. • Identify ... as you go. If array[i + 1] < array[i], swap them! ... Grab the smallest and swap it with whatever is at the front of ...

Krzysztof Gajos - CS50 CDN
What you will learn in. CS 179. • Discover and understand people's latent needs. • Invent and construct prototypes. • Design for people different than yourself.

CS50 Walkthrough #3 - CS50 CDN
what type are these values? ▫ how do we initialize them? ▫ don't forget! ▫ swap tiles for even d ... Questions? Please email me feedback: [email protected].

cs50.c 1/5 cs50.c 2/5 - CS50 CDN
11: * Based on Eric Roberts' genlib.h and simpio.h. 12: *. 13: * The latest version of this file can be found at. 14: * http://www.cs50.net/pub/releases/cs50/cs50.h.

Quiz 0 - CS50 CDN
In the context of files, Linux uses \n to end lines, Mac OS uses \r, and Windows ... format string's expectation of a leading %f, and so neither f nor c get filled with a ...

Week 8 - CS50 CDN
PHP: PHP Hypertext Preprocessor. • When accessed, dynamically generates a webpage which it then outputs to browser. • PHP code enclosed in tag.

Untitled - CS50 CDN
void swap(int a, int b). { int tmp = a; a = b; b = tmp;. } Page 11. void swap(int *a, int *b). { int tmp = *a;. *a = *b;. *b = tmp;. } Page 12. main's parameters main's ...

Asymptotic Notation - CS50 CDN
break – tell the program to 'pause' at a certain point (either a function or a line number) step – 'step' to the next executed statement next – moves to the next ...

Krzysztof Gajos - CS50 CDN
What you will learn in. CS 179. • Discover and understand people's latent needs. • Invent and construct prototypes. • Design for people different than yourself.

Untitled - CS50 CDN
void swap(int a, int b). { int tmp = a; a = b; b = tmp;. } Page 11. void swap(int *a, int *b). { int tmp = *a;. *a = *b;. *b = tmp;. } Page 12. main's parameters.

Computer Science 124 - CS50 CDN
Computer Science 124 : Who Should Take It. • CS 124 is all about developing techniques for solving problems. • This is what CS is all about! – Take a problem.

Untitled - CS50 CDN
Mac OS 10.6. Windows 7. Mac OS 10.5. Windows Vista. Windows XP. Mac OS 10.4. Linux. 0. 50. 100. 150. 200. Page 19. Elective. Concentration. Unsure.

Untitled - CS50 CDN
50. 100. 150. 200. Page 19. Elective. Concentration. Unsure. Gen Ed. Core. 0. 50. 100. 150. 200. 250. 300. Page 20. arrays. Page 21. to be continued... Page 22.

Untitled - CS50 CDN
http://www.blogcdn.com/www.engadget.com/media/2008/05/iphone_line_1-1.jpg. Page 16. valgrind valgrind -‐v -‐-‐leak-‐check=full a.out. Invalid write of size 4.

CS121 Tease for CS50.pptx - CS50 CDN
Formal Systems and Computation. • Two ways to look at it. 1. Study of problems and computers with all their physicality abstracted away q0 q1 q2 q3 a a a a b b.