{"captions":[{"content":"[Section 9] [More Comfortable]","startTime":0,"duration":2750,"startOfParagraph":false},{"content":"[Rob Bowden] [Harvard University]","startTime":2750,"duration":2000,"startOfParagraph":false},{"content":"[This is CS50.] [CS50.TV]","startTime":4750,"duration":2000,"startOfParagraph":false},{"content":"All right. Basically today it's all up to you guys to ask some questions.","startTime":6750,"duration":5380,"startOfParagraph":true},{"content":"I might be able to wander with some topics","startTime":12130,"duration":2940,"startOfParagraph":false},{"content":"for a bit if no one has any questions to ask.","startTime":15070,"duration":2500,"startOfParagraph":false},{"content":"Hopefully you do. Does anyone have any questions?","startTime":17570,"duration":3090,"startOfParagraph":false},{"content":"Maybe from past quizzes, things you're not comfortable with currently.","startTime":20660,"duration":4560,"startOfParagraph":false},{"content":"Yes. >>[Student] Can you go over buffer overflow attacks? >>[Rob] Sure.","startTime":34630,"duration":3220,"startOfParagraph":true},{"content":"The main example actually might be right here.","startTime":37850,"duration":7680,"startOfParagraph":false},{"content":"The main deal behind buffer overflow attacks are","startTime":45530,"duration":3190,"startOfParagraph":false},{"content":"we have some buffer, here.","startTime":48720,"duration":2820,"startOfParagraph":false},{"content":"Char c--which is only of size 12--","startTime":51540,"duration":2570,"startOfParagraph":false},{"content":"but then we are inserting something into that buffer","startTime":54110,"duration":3470,"startOfParagraph":false},{"content":"but not checking exactly how much we are inserting.","startTime":57580,"duration":2470,"startOfParagraph":false},{"content":"Here we are inserting strlen(bar) into C, but who knows how long bar is.","startTime":60050,"duration":6690,"startOfParagraph":false},{"content":"If it's longer than 12 characters then this is going to overflow this buffer.","startTime":66740,"duration":5230,"startOfParagraph":false},{"content":"Looking at this picture--","startTime":71970,"duration":3860,"startOfParagraph":false},{"content":"if you take 61 you'll get much more familiar with this sort of layout","startTime":75830,"duration":5010,"startOfParagraph":false},{"content":"and dealing with the saved frame pointer and return address and parent's routine stack","startTime":80840,"duration":4920,"startOfParagraph":false},{"content":"and all of these actual things.","startTime":85760,"duration":2000,"startOfParagraph":false},{"content":"But here you just need to know that we have","startTime":87760,"duration":3580,"startOfParagraph":false},{"content":"this little space for our buffer.","startTime":91340,"duration":4650,"startOfParagraph":false},{"content":"Here we have c(0) and then we have c, 1, 2, 3, 4, 5 and so on.","startTime":95990,"duration":3490,"startOfParagraph":false},{"content":"Under normal circumstances we would fill this buffer as per usual.","startTime":99480,"duration":5330,"startOfParagraph":false},{"content":"If we inserted 'hello' we'd have h-e-l-l-o/0,","startTime":104810,"duration":5670,"startOfParagraph":false},{"content":"and then just a bunch of empty space.","startTime":110480,"duration":2420,"startOfParagraph":false},{"content":"For a hacker--oh, I guess this is the example.","startTime":112900,"duration":5010,"startOfParagraph":false},{"content":"For a hacker we get something like this where","startTime":117910,"duration":4560,"startOfParagraph":false},{"content":"what they're specifically trying to do is","startTime":122470,"duration":2290,"startOfParagraph":false},{"content":"usually override the return address.","startTime":124760,"duration":3130,"startOfParagraph":false},{"content":"Whenever you call a function and your stack frame gets pushed onto the stack","startTime":127890,"duration":4620,"startOfParagraph":false},{"content":"that stack frame needs to know how--","startTime":132510,"duration":2180,"startOfParagraph":false},{"content":"well, the function that has been called needs to know how to return to the function that called it.","startTime":134690,"duration":6330,"startOfParagraph":false},{"content":"So, if main calls foo, foo needs to return to main,","startTime":141020,"duration":2760,"startOfParagraph":false},{"content":"and so that's what this return address does.","startTime":143780,"duration":2520,"startOfParagraph":false},{"content":"But what the hacker's going to do is","startTime":146300,"duration":2500,"startOfParagraph":false},{"content":"override it with a special return address","startTime":148800,"duration":2020,"startOfParagraph":false},{"content":"where again--Little Indian--it's not straightforward but each byte is backwards.","startTime":150820,"duration":9270,"startOfParagraph":false},{"content":"This return address as far as the computer is concerned","startTime":160090,"duration":7210,"startOfParagraph":false},{"content":"returning to this address is equivalent to returning to foo or main ","startTime":167300,"duration":4090,"startOfParagraph":false},{"content":"or whatever function called it.","startTime":171390,"duration":2460,"startOfParagraph":false},{"content":"So it's going to return to this address","startTime":173850,"duration":950,"startOfParagraph":false},{"content":"which just so happens to be this address","startTime":174800,"duration":3330,"startOfParagraph":false},{"content":"which either sometimes what they do here is use the return address ","startTime":178130,"duration":6610,"startOfParagraph":false},{"content":"of a specific function that they know is already there.","startTime":184740,"duration":4410,"startOfParagraph":false},{"content":"I can't remember what the function's called.","startTime":189150,"duration":3480,"startOfParagraph":false},{"content":"I'll look it up later.","startTime":192630,"duration":2000,"startOfParagraph":false},{"content":"Here what they're doing is passing the return address","startTime":194630,"duration":2940,"startOfParagraph":true},{"content":"to the stack itself, and this is somewhat strange where","startTime":197570,"duration":8740,"startOfParagraph":false},{"content":"there are examples of memory where--","startTime":206310,"duration":3220,"startOfParagraph":false},{"content":"memory can be split up into read-only, read-write, and executable memory","startTime":209530,"duration":4820,"startOfParagraph":false},{"content":"where we have seen read-only memory before where the--","startTime":214350,"duration":4360,"startOfParagraph":false},{"content":"if I say char*s = hello I can't modify hello.","startTime":218710,"duration":5250,"startOfParagraph":false},{"content":"That's read-only memory.","startTime":223960,"duration":2240,"startOfParagraph":false},{"content":"There's also this idea of executable memory","startTime":226200,"duration":3370,"startOfParagraph":false},{"content":"where the executable memory would be the text segment of your code.","startTime":229570,"duration":4300,"startOfParagraph":false},{"content":"Looking at your usual address space layout--","startTime":233870,"duration":3480,"startOfParagraph":false},{"content":"I believe that's going to be a good picture--","startTime":237350,"duration":5740,"startOfParagraph":false},{"content":"this works--where we have our stack up here. We have data memory.","startTime":248200,"duration":3970,"startOfParagraph":false},{"content":"Ignore this basically. This is our heap.","startTime":252170,"duration":4190,"startOfParagraph":false},{"content":"And then we have down here our main program code.","startTime":256360,"duration":2450,"startOfParagraph":false},{"content":"This is similar to the place where we put our strings like char* = hello","startTime":258810,"duration":8670,"startOfParagraph":false},{"content":"and that's read-only.","startTime":267480,"duration":2250,"startOfParagraph":false},{"content":"But you could also mark this main program code as executable.","startTime":269730,"duration":3860,"startOfParagraph":false},{"content":"And if you are doing that or your operating system does that correctly","startTime":273590,"duration":4360,"startOfParagraph":false},{"content":"then this should be the only place in memory","startTime":277950,"duration":2960,"startOfParagraph":false},{"content":"that code can actually execute","startTime":280910,"duration":3920,"startOfParagraph":false},{"content":"which means that this sort of buffer overflow attack we have over here","startTime":284830,"duration":3720,"startOfParagraph":false},{"content":"would be ineffective because this is trying to execute memory up here in our stack.","startTime":288550,"duration":5250,"startOfParagraph":false},{"content":"Notice the pictures are first.","startTime":293800,"duration":3430,"startOfParagraph":false},{"content":"We have our stack growing up.","startTime":297230,"duration":2040,"startOfParagraph":false},{"content":"Here the stack is growing down.","startTime":299270,"duration":2000,"startOfParagraph":false},{"content":"For CS50 purposes the stack grows up.","startTime":301270,"duration":2000,"startOfParagraph":false},{"content":"It is possible to circumvent this particular type of buffer overflow","startTime":303270,"duration":6250,"startOfParagraph":true},{"content":"by having these executable regions of memory in non-executable regions.","startTime":309520,"duration":5590,"startOfParagraph":false},{"content":"But it just so happens that rarely is executable memory marked as executable.","startTime":315110,"duration":6310,"startOfParagraph":false},{"content":"It just tends to be read-only and re-write are the only things that are used,","startTime":321420,"duration":5100,"startOfParagraph":false},{"content":"so this is still very effective.","startTime":326520,"duration":2470,"startOfParagraph":false},{"content":"And here we could put whatever we want.","startTime":328990,"duration":2960,"startOfParagraph":false},{"content":"It wasn't actually done as a Pset in 61 this year,","startTime":331950,"duration":3070,"startOfParagraph":false},{"content":"but if you look at last year's offering of it or any previous year","startTime":335020,"duration":3380,"startOfParagraph":false},{"content":"one Pset is you're specifically supposed to insert in here code that is supposed to","startTime":338400,"duration":5710,"startOfParagraph":false},{"content":"print some specific value or return a value that is different from ","startTime":344110,"duration":4850,"startOfParagraph":false},{"content":"the value that is supposed to be printed.","startTime":348960,"duration":2440,"startOfParagraph":false},{"content":"Or even more cleverly, it wants you to call or write--","startTime":351400,"duration":6370,"startOfParagraph":false},{"content":"so this will return up to here and then you'll execute some coding here,","startTime":357770,"duration":5550,"startOfParagraph":false},{"content":"and the cleverest of overflows will then return to what this return address used to be.","startTime":363320,"duration":6400,"startOfParagraph":false},{"content":"So even though we needed to override this","startTime":369720,"duration":2250,"startOfParagraph":false},{"content":"to come up here, we still remember that return address somewhere","startTime":371970,"duration":4750,"startOfParagraph":false},{"content":"so that we can return to main or whatever,","startTime":376720,"duration":2170,"startOfParagraph":false},{"content":"and it's like we never even noticed that things went wrong.","startTime":378890,"duration":4910,"startOfParagraph":false},{"content":"But things did so that's the case where maybe inside of here we gelbroke our iPhone.","startTime":383800,"duration":6300,"startOfParagraph":false},{"content":"Things go as normal--like we run some program and things end up returning to","startTime":390100,"duration":5570,"startOfParagraph":false},{"content":"whatever it's supposed to return to, but in the meantime","startTime":395670,"duration":2870,"startOfParagraph":false},{"content":"you managed to destroy the entire operating system.","startTime":398540,"duration":3280,"startOfParagraph":false},{"content":"You don't need to know code concerning buffer overflows or actually taking advantage of it.","startTime":401820,"duration":9130,"startOfParagraph":false},{"content":"You do need to know the basic ideas of this is the buffer that's being overflowed,","startTime":410950,"duration":7110,"startOfParagraph":false},{"content":"and this is the reason that it can be overflowed because we're not checking whether","startTime":418060,"duration":3950,"startOfParagraph":false},{"content":"we're actually within the bounds of it.","startTime":422010,"duration":4100,"startOfParagraph":false},{"content":"[Student] The solution for preventing it is just checking the bounds?","startTime":426110,"duration":3770,"startOfParagraph":true},{"content":"[Rob] Yes. In this case the solution would be","startTime":429880,"duration":3720,"startOfParagraph":false},{"content":"you could either say if strlen of bar is greater than 12-1--","startTime":433600,"duration":7250,"startOfParagraph":false},{"content":"because you need the /0 at the end--","startTime":440850,"duration":4120,"startOfParagraph":false},{"content":"or you could manually do a for loop that only copies the first 11 characters,","startTime":444970,"duration":9120,"startOfParagraph":false},{"content":"or just anything where you're actually checking to make sure you don't overflow that buffer.","startTime":454090,"duration":5620,"startOfParagraph":false},{"content":"Other questions? Yes?","startTime":465580,"duration":3470,"startOfParagraph":true},{"content":"[Student] Can you talk about tries and maybe something about programming (inaudible).","startTime":469050,"duration":3710,"startOfParagraph":false},{"content":"[Rob] Sure. ","startTime":472760,"duration":5960,"startOfParagraph":false},{"content":"The actual program--","startTime":478720,"duration":4780,"startOfParagraph":false},{"content":"we would never make you do an implementation of a trie on the exam","startTime":483500,"duration":4690,"startOfParagraph":false},{"content":"because it would be unfair to those who did hash tables.","startTime":488190,"duration":4650,"startOfParagraph":false},{"content":"And similarly we would never make you implement a hash table on the exam","startTime":492840,"duration":3190,"startOfParagraph":false},{"content":"because it would be unfair to those who did tries.","startTime":496030,"duration":2530,"startOfParagraph":false},{"content":"You should nevertheless know the struct of a trie or the struct of a hash table or whatever.","startTime":498560,"duration":6660,"startOfParagraph":false},{"content":"That's actually true of any sort of data structure we've seen.","startTime":505220,"duration":5010,"startOfParagraph":false},{"content":"Linked lists, stacked skews, binary trees--","startTime":510230,"duration":3329,"startOfParagraph":false},{"content":"you should be able to define those structs by heart.","startTime":513559,"duration":4631,"startOfParagraph":false},{"content":"A trie--that means the only thing you will need to do is maybe we'll give you ","startTime":518190,"duration":6620,"startOfParagraph":false},{"content":"some word or something and we'll say construct the trie that--","startTime":524810,"duration":5260,"startOfParagraph":false},{"content":"we'll give you maybe a set of words ","startTime":530070,"duration":2800,"startOfParagraph":false},{"content":"and we're like construct a trie that represents this dictionary.","startTime":532870,"duration":3410,"startOfParagraph":false},{"content":"Let's make our dictionary cat and dog.","startTime":536280,"duration":9700,"startOfParagraph":true},{"content":"The idea of the trie is we start out with this array--","startTime":545980,"duration":4810,"startOfParagraph":false},{"content":"26 slots--","startTime":550790,"duration":5720,"startOfParagraph":false},{"content":"and in each slot the actual index of the slot corresponds to the letter we're concerned with.","startTime":556510,"duration":7980,"startOfParagraph":false},{"content":"So here, if we're trying to insert cat into our trie","startTime":564490,"duration":4070,"startOfParagraph":false},{"content":"the first character is 'c' which is going to be 'if a is 0 then b is 1, c is 2.'","startTime":568560,"duration":6800,"startOfParagraph":false},{"content":"We're going to go into the second index,","startTime":575360,"duration":2730,"startOfParagraph":false},{"content":"and we're going to create a trie off of that.","startTime":578090,"duration":3010,"startOfParagraph":false},{"content":"We're going to have 26 slots.","startTime":581100,"duration":5980,"startOfParagraph":false},{"content":"And then we are going to index the second character of cat.","startTime":587080,"duration":4060,"startOfParagraph":false},{"content":"That's 'a' which is going to be the 0 spot.","startTime":591140,"duration":2200,"startOfParagraph":false},{"content":"And that's going to have 26 spots.","startTime":593340,"duration":3620,"startOfParagraph":false},{"content":"Then we go to 't' and we would also have that coming down which is actually kind of important","startTime":596960,"duration":8690,"startOfParagraph":false},{"content":"because--let's have it come up here. Here's our trie for 't'.","startTime":605650,"duration":8340,"startOfParagraph":false},{"content":"Let's say this is index 't' is 19.","startTime":613990,"duration":9380,"startOfParagraph":false},{"content":"The important thing to remember about tries is you can't just keep track of these pointers.","startTime":623370,"duration":7650,"startOfParagraph":false},{"content":"You also have to keep track of whether this is actually the end of a word.","startTime":631020,"duration":4450,"startOfParagraph":false},{"content":"So, inside of here we need some kind of flag that says ","startTime":635470,"duration":3100,"startOfParagraph":false},{"content":"okay, this is actually the end of a word.","startTime":638570,"duration":2950,"startOfParagraph":false},{"content":"The reason being if we later try to insert catastrophic into our dictionary","startTime":641520,"duration":5310,"startOfParagraph":false},{"content":"which has the same starting 3 characters","startTime":646830,"duration":3100,"startOfParagraph":false},{"content":"but goes on further we need to recognize that this is the end of a word.","startTime":649930,"duration":7320,"startOfParagraph":false},{"content":"Or alternatively if we try to look up 'ca' which maybe isn't a word","startTime":657250,"duration":4080,"startOfParagraph":false},{"content":"but we get down to here then we--","startTime":661330,"duration":4770,"startOfParagraph":false},{"content":"or would it be c and then we look at a--","startTime":666100,"duration":4170,"startOfParagraph":false},{"content":"we need to recognize that even though there's a pointer coming out of this node","startTime":670270,"duration":3670,"startOfParagraph":false},{"content":"it doesn't represent the end of the word.","startTime":673940,"duration":2000,"startOfParagraph":false},{"content":"So, what does that mean--what were you going to say?","startTime":675940,"duration":3490,"startOfParagraph":true},{"content":"What does that mean our struct looks like?","startTime":679430,"duration":3330,"startOfParagraph":false},{"content":"[Student] It's an array of pointers that is 26 long and then a bool were or not were.","startTime":682760,"duration":3000,"startOfParagraph":false},{"content":"[Rob] Yeah. So, we'll have a struct trie* pointers--here we'll say [26] on ","startTime":685760,"duration":21670,"startOfParagraph":false},{"content":"and then the semicolon over here.","startTime":707430,"duration":2160,"startOfParagraph":false},{"content":"But on the Pset, we also need to account for apostrophes,","startTime":709590,"duration":3620,"startOfParagraph":false},{"content":"which meant you needed to hard-code that apostrophe with index 27 or something.","startTime":713210,"duration":4960,"startOfParagraph":false},{"content":"But here we only care about 26.","startTime":718170,"duration":2270,"startOfParagraph":false},{"content":"And then we need maybe a char in or bool--let's call it is word.","startTime":720440,"duration":11390,"startOfParagraph":false},{"content":"That's 2 of the 3 things I think you would ever need to know about tries--","startTime":731830,"duration":6290,"startOfParagraph":false},{"content":"building them, the struct of them, and the last thing is the run-time of them.","startTime":738120,"duration":6250,"startOfParagraph":false},{"content":"What is the runtime of a trie--or the lookup in a trie?","startTime":744370,"duration":3880,"startOfParagraph":true},{"content":"This is where we say it's o(k) where k is the length of the word we happen to be looking up;","startTime":748250,"duration":19250,"startOfParagraph":false},{"content":"but at the same time we say--at least for Pset 5 speller's sake--we say","startTime":767500,"duration":6350,"startOfParagraph":false},{"content":"the longest word in the dictionary is 45 characters, so this is basically","startTime":773850,"duration":5620,"startOfParagraph":false},{"content":"the O of 45 which is constant time.","startTime":779470,"duration":5430,"startOfParagraph":false},{"content":"So, if there is an upper bound on your longest word then--","startTime":784900,"duration":4760,"startOfParagraph":false},{"content":"or even like the English dictionary--there is an upper bound on your longest word.","startTime":789660,"duration":5470,"startOfParagraph":false},{"content":"Or any dictionary--there is a longest bound on your upper word.","startTime":795130,"duration":4840,"startOfParagraph":false},{"content":"No matter what you're doing is constant time,","startTime":799970,"duration":5510,"startOfParagraph":false},{"content":"but O of k is nice because there actually is a difference between running say","startTime":805480,"duration":8330,"startOfParagraph":false},{"content":"45-character word versus an alphabet which only has words up to 3 characters.","startTime":813810,"duration":6310,"startOfParagraph":false},{"content":"Another thing about that is that the--","startTime":820120,"duration":12750,"startOfParagraph":false},{"content":"oh, because just saying that 45 happens to be our longest word","startTime":832870,"duration":4650,"startOfParagraph":false},{"content":"is kind of silly because at the same time let's say an algorithm is O of N.","startTime":837520,"duration":4810,"startOfParagraph":false},{"content":"Well okay, because memory only supports up to 2^32 bytes, ","startTime":842330,"duration":4180,"startOfParagraph":false},{"content":"then N is at most 4 billion and that's constant time, which is why at some point","startTime":846510,"duration":5260,"startOfParagraph":false},{"content":"it's silly to say this sort of thing where there's an upper bound ","startTime":851770,"duration":3100,"startOfParagraph":false},{"content":"that we can just reduce to constant time because everything is constant time ","startTime":854870,"duration":4670,"startOfParagraph":false},{"content":"when you think of it in that way.","startTime":859540,"duration":2780,"startOfParagraph":false},{"content":"But we would probably accept both of these.","startTime":862320,"duration":3150,"startOfParagraph":false},{"content":"In any case explain either that O(1) means you have an upper-bounded length of word;","startTime":865470,"duration":6310,"startOfParagraph":false},{"content":"O(k) means your length of the word--","startTime":871780,"duration":2290,"startOfParagraph":false},{"content":"well, k means length of the word.","startTime":874070,"duration":6830,"startOfParagraph":false},{"content":"Yeah. >>[Student] Does the bool--because when you made your trie","startTime":884060,"duration":3220,"startOfParagraph":true},{"content":"it seemed like it was--you would go c-a-t and then you go to the next pointer","startTime":887280,"duration":5940,"startOfParagraph":false},{"content":"and then you tell if that equals true--would you put that true at like with the t?","startTime":893220,"duration":6640,"startOfParagraph":false},{"content":"[Rob] Let's think this is the case where a lot of examples you can just try and come up with","startTime":899860,"duration":6700,"startOfParagraph":false},{"content":"simple and/or extreme examples and what it should be, so let's think of the word 'a'.","startTime":906560,"duration":5750,"startOfParagraph":false},{"content":"In our original trie--","startTime":912310,"duration":9010,"startOfParagraph":false},{"content":"would we want to put a 1 here, or we'd want to put a 1 down here.","startTime":921320,"duration":14190,"startOfParagraph":false},{"content":"I would say that in the end it would probably be either/or.","startTime":935510,"duration":5840,"startOfParagraph":false},{"content":"I can't think of a reason--or really you wouldn't--","startTime":941350,"duration":4650,"startOfParagraph":false},{"content":"the reason I wouldn't put it down there is because you don't even need to go that far.","startTime":946000,"duration":5060,"startOfParagraph":false},{"content":"We never need to allocate this trie.","startTime":951060,"duration":4760,"startOfParagraph":false},{"content":"We just put the 1 up there.","startTime":955820,"duration":2130,"startOfParagraph":false},{"content":"This is still pointing to NULL.","startTime":957950,"duration":5360,"startOfParagraph":false},{"content":"If we're only going to have single characters","startTime":963310,"duration":6120,"startOfParagraph":false},{"content":"there's no reason to extend down to another trie just to mark that letter as used.","startTime":969430,"duration":7790,"startOfParagraph":false},{"content":"Similarly, if we had put the 'a' down there","startTime":977220,"duration":4040,"startOfParagraph":false},{"content":"then necessarily all of these would just be 0 at all times.","startTime":981260,"duration":6600,"startOfParagraph":false},{"content":"[Student] But don't we need a starting trie that will point to this 'a'?","startTime":987860,"duration":8200,"startOfParagraph":true},{"content":"[Rob] We have some global or something struct trie* t ","startTime":996060,"duration":7510,"startOfParagraph":false},{"content":"which points here, but that's just a pointer.","startTime":1003570,"duration":3700,"startOfParagraph":false},{"content":"It's not a full-blown trie that's pointing to it.","startTime":1007270,"duration":4230,"startOfParagraph":false},{"content":"[Student] Okay. How would we assign the letter 'i'--with the word I?","startTime":1011500,"duration":10500,"startOfParagraph":false},{"content":"[Rob] His question might be answering that. Hold on.","startTime":1022000,"duration":4380,"startOfParagraph":false},{"content":"That is an issue where a trie in and of itself--","startTime":1026380,"duration":8680,"startOfParagraph":false},{"content":"I don't know the way the Pset would have written it.","startTime":1035060,"duration":2820,"startOfParagraph":false},{"content":"The previous struct was bad.","startTime":1037880,"duration":2000,"startOfParagraph":false},{"content":"But we could also do struct node is a bool--and a pointer--","startTime":1039880,"duration":21810,"startOfParagraph":false},{"content":"there's actually multiple ways you could write it.","startTime":1061690,"duration":4810,"startOfParagraph":false},{"content":"Alternatively a trie doesn't need to be a struct.","startTime":1066500,"duration":15300,"startOfParagraph":false},{"content":"It could even be trie--typedef node*-- ","startTime":1081800,"duration":19450,"startOfParagraph":false},{"content":"node [26] is a trie; and this is no longer struct.","startTime":1101250,"duration":13510,"startOfParagraph":false},{"content":"Now there's going to be--I'm trying to think of the way that Pset would have expected you to.","startTime":1114760,"duration":9510,"startOfParagraph":false},{"content":"[Student] I pulled up that review session and I think they just go--","startTime":1124270,"duration":3380,"startOfParagraph":false},{"content":"like if you have an a then you go to the next-- >>[Rob] That's how they do it?","startTime":1127650,"duration":3020,"startOfParagraph":false},{"content":"[Student] And then if there's a true there it doesn't work--","startTime":1130670,"duration":3080,"startOfParagraph":false},{"content":"[Rob] Yeah. That does work. It wastes the space of--","startTime":1133750,"duration":4960,"startOfParagraph":false},{"content":"you necessarily have a whole other level of trie that you wouldn't need in the first place.","startTime":1138710,"duration":5200,"startOfParagraph":false},{"content":"Here it's getting ugly with each--","startTime":1143910,"duration":4500,"startOfParagraph":false},{"content":"basically what I'm trying to do here is associate--","startTime":1148410,"duration":3120,"startOfParagraph":false},{"content":"instead of being 26 pointers to your tries,","startTime":1151530,"duration":3470,"startOfParagraph":false},{"content":"it's 26 bool pointer, bool pointer, bool pointer, and so on.","startTime":1155000,"duration":5810,"startOfParagraph":false},{"content":"[Student] You can't make that 2 arrays? An array of bools and an array of pointers?","startTime":1168940,"duration":5470,"startOfParagraph":true},{"content":"[Rob] You could but then you'd need to--","startTime":1174410,"duration":3650,"startOfParagraph":false},{"content":"2 arrays of booleans and pointers.","startTime":1178060,"duration":3440,"startOfParagraph":false},{"content":"You would need to then build your array of booleans--","startTime":1181500,"duration":5840,"startOfParagraph":false},{"content":"your array of booleans needs to be as big as the trie","startTime":1187340,"duration":3900,"startOfParagraph":false},{"content":"because you can't just have 26 booleans.","startTime":1191240,"duration":1960,"startOfParagraph":false},{"content":"It has to grow with each possible--","startTime":1193200,"duration":3810,"startOfParagraph":false},{"content":"like your trie has more than 26 true or false possible words.","startTime":1197010,"duration":6230,"startOfParagraph":false},{"content":"At that point they may as well just be a single struct that your trie grows down with.","startTime":1203240,"duration":5000,"startOfParagraph":false},{"content":"This doesn't seem right because--what do I want here?","startTime":1208240,"duration":6970,"startOfParagraph":false},{"content":"So, trie* t--","startTime":1215210,"duration":8430,"startOfParagraph":false},{"content":"can you do typedef (node*)[26] trie;","startTime":1223640,"duration":6560,"startOfParagraph":false},{"content":"that might be the syntax I'm looking for.","startTime":1230200,"duration":2890,"startOfParagraph":false},{"content":"And this should just be a regular trie.","startTime":1236740,"duration":4710,"startOfParagraph":false},{"content":"I'm not sure.","startTime":1244900,"duration":2540,"startOfParagraph":false},{"content":"But that is the way we did it in the review, so that works perfectly fine, too.","startTime":1247440,"duration":7410,"startOfParagraph":false},{"content":"In which case if it is just bool is word and then an array of 26","startTime":1254850,"duration":3000,"startOfParagraph":false},{"content":"then you do have to go to the next level.","startTime":1257850,"duration":3900,"startOfParagraph":false},{"content":"I'll think about the way I would do that.","startTime":1261750,"duration":3670,"startOfParagraph":false},{"content":"Other questions?","startTime":1267500,"duration":2050,"startOfParagraph":true},{"content":"[Student] Can I ask questions about something else? >>[Rob] Yes.","startTime":1269550,"duration":2990,"startOfParagraph":false},{"content":"[Student] Can you go over what the difference is and when you'd use jQuery versus Ajax?","startTime":1272540,"duration":6500,"startOfParagraph":false},{"content":"[Rob] They are in and of themselves completely different.","startTime":1279040,"duration":5510,"startOfParagraph":false},{"content":"JQuery does enable Ajax. It does give us some easier use of Ajax.","startTime":1284550,"duration":8170,"startOfParagraph":false},{"content":"But Ajax comes shipped with JavaScript. JavaScript has Ajax capabilities.","startTime":1292720,"duration":5760,"startOfParagraph":false},{"content":"All Ajax means is liken I'm already on a page and when I want to--","startTime":1298480,"duration":9010,"startOfParagraph":false},{"content":"when I click on something I don't need to reload the page to download that new information.","startTime":1307490,"duration":5330,"startOfParagraph":false},{"content":"I just request that new information.","startTime":1312820,"duration":2200,"startOfParagraph":false},{"content":"You can look at it in Facebook or something.","startTime":1315020,"duration":6200,"startOfParagraph":false},{"content":"Inspect network.","startTime":1321220,"duration":4360,"startOfParagraph":false},{"content":"Shrink this.","startTime":1325580,"duration":1880,"startOfParagraph":false},{"content":"Down here we see that we're getting all these requests.","startTime":1332070,"duration":2870,"startOfParagraph":false},{"content":"Now when I click on--well, it's doing Ajax before I even click on anything.","startTime":1334940,"duration":4050,"startOfParagraph":false},{"content":"But if I click on this, then it's going to make a bunch of requests down here","startTime":1338990,"duration":5150,"startOfParagraph":false},{"content":"which just making these requests--oh, now it's over here.","startTime":1344140,"duration":9390,"startOfParagraph":false},{"content":"Let's refresh.","startTime":1353530,"duration":3060,"startOfParagraph":false},{"content":"Do this again.","startTime":1356590,"duration":1990,"startOfParagraph":false},{"content":"We see that we get all these requests, but this could still be in the process of the page loading.","startTime":1358580,"duration":3510,"startOfParagraph":false},{"content":"Notice Facebook is making these constant requests even after the page has loaded.","startTime":1362090,"duration":5310,"startOfParagraph":false},{"content":"And if I click on here, it'll make some more requests for some data","startTime":1367400,"duration":4070,"startOfParagraph":false},{"content":"that is in response to the thing I just clicked on.","startTime":1371470,"duration":3520,"startOfParagraph":false},{"content":"That's just what Ajax is. It lets you pull for data that wasn't downloaded with the page originally.","startTime":1374990,"duration":9670,"startOfParagraph":false},{"content":"JQuery is separate. JQuery is just a JavaScript library that makes a lot of things easier.","startTime":1384660,"duration":7390,"startOfParagraph":true},{"content":"With jQuery it's a lot of the advantage is this just--","startTime":1392050,"duration":16610,"startOfParagraph":false},{"content":"dollar sign--dollar sign is a valid variable in JavaScript.","startTime":1408660,"duration":5370,"startOfParagraph":false},{"content":"So, jQuery--all it's doing is saying like var$= a whole bunch of stuff--","startTime":1414030,"duration":9430,"startOfParagraph":false},{"content":"like some big function with all this stuff in it--","startTime":1423460,"duration":3230,"startOfParagraph":false},{"content":"and then you use that dollar sign in ways like","startTime":1426690,"duration":5960,"startOfParagraph":false},{"content":"$(\"#footer\").style (\"text-align\", \"center\").","startTime":1432650,"duration":31290,"startOfParagraph":false},{"content":"JQuery gives us this sort of syntax where a big advantage--","startTime":1463940,"duration":8390,"startOfParagraph":false},{"content":"it has other features but what we want you to focus on most","startTime":1472330,"duration":3320,"startOfParagraph":false},{"content":"is just being able to select elements like this.","startTime":1475650,"duration":3110,"startOfParagraph":false},{"content":"In regular, plain-old JavaScript you can do things like ","startTime":1478760,"duration":4020,"startOfParagraph":false},{"content":"document-dot-get element by ID footer-dot--I don't know what it is at that point--","startTime":1482780,"duration":7710,"startOfParagraph":false},{"content":"something about CSS or style or something--","startTime":1490490,"duration":2300,"startOfParagraph":false},{"content":"but then alternatively, let's say we wanted to select by class.","startTime":1492790,"duration":6140,"startOfParagraph":false},{"content":"Now we are styling everything with a class footer with this style.","startTime":1498930,"duration":7400,"startOfParagraph":false},{"content":"Even if we wanted to style any paragraphs.","startTime":1506330,"duration":9740,"startOfParagraph":false},{"content":"So, this selector--being able to select things in the dom like this is incredibly convenient","startTime":1516070,"duration":5930,"startOfParagraph":false},{"content":"since in plain old JavaScript you would have to do document-dot-get elements by class name","startTime":1522000,"duration":7420,"startOfParagraph":false},{"content":"or whatever it is; or if I wanted a tag I'd need to say get elements by tag name.","startTime":1529420,"duration":4840,"startOfParagraph":false},{"content":"So, I need to know the specific ways that I access all of these things.","startTime":1534260,"duration":3270,"startOfParagraph":false},{"content":"The functions are going to be different depending on whether I'm using a class or an ID","startTime":1537530,"duration":3280,"startOfParagraph":false},{"content":"or a tag or what, whereas jQuery just does that for me.","startTime":1540810,"duration":5610,"startOfParagraph":false},{"content":"[Student] Is jQuery going to be used when you're doing initial styling of the page?","startTime":1546420,"duration":6700,"startOfParagraph":true},{"content":"Or in order to change the styling after it's already-- >>[Rob] To change it. ","startTime":1553120,"duration":3450,"startOfParagraph":false},{"content":"[Student] After it's already loaded. >>[Rob] Yeah.","startTime":1556570,"duration":1870,"startOfParagraph":false},{"content":"Any initial styling--well, even the--","startTime":1558440,"duration":8580,"startOfParagraph":false},{"content":"generally you would use this sort of change.","startTime":1567020,"duration":2950,"startOfParagraph":false},{"content":"You wouldn't change--this would work perfectly fine.","startTime":1569970,"duration":4360,"startOfParagraph":false},{"content":"But usually you wouldn't change the style like this.","startTime":1574330,"duration":3390,"startOfParagraph":false},{"content":"Instead, you'd give it a new class or something","startTime":1577720,"duration":2890,"startOfParagraph":false},{"content":"whereas the CSS has already been defined for that class in a certain way.","startTime":1580610,"duration":4040,"startOfParagraph":false},{"content":"By giving these items I'm selecting a new class","startTime":1584650,"duration":4270,"startOfParagraph":false},{"content":"I'm applying the styles that have already been downloaded.","startTime":1588920,"duration":3280,"startOfParagraph":false},{"content":"[Student] So you select a couple of checkboxes and the things that you've selected","startTime":1592200,"duration":4520,"startOfParagraph":false},{"content":"change to a new style and start looking different. >>[Rob] Yeah.","startTime":1596720,"duration":5100,"startOfParagraph":false},{"content":"The other things to remember about--","startTime":1601820,"duration":3670,"startOfParagraph":false},{"content":"well, there are several functions you should remember about jQuery.","startTime":1605490,"duration":2860,"startOfParagraph":false},{"content":"Let's say that we are selecting something with ID P.","startTime":1608350,"duration":7220,"startOfParagraph":false},{"content":"[Student] Do you always have to use the pound?","startTime":1615570,"duration":4930,"startOfParagraph":true},{"content":"[Rob] This means ID. It's equivalent to CSS, so CSS selectors--it's inspired by that.","startTime":1620500,"duration":9100,"startOfParagraph":false},{"content":"Where in CSS if I wanted to style a footer--","startTime":1629600,"duration":2810,"startOfParagraph":false},{"content":"or something with ID footer--","startTime":1632410,"duration":4540,"startOfParagraph":false},{"content":"it would be like text-align: center;","startTime":1636950,"duration":6540,"startOfParagraph":false},{"content":"you won't need to write CSS on the exam, but you need to know the selectors.","startTime":1643490,"duration":5330,"startOfParagraph":false},{"content":"You need to know what--you need to know how to read it.","startTime":1648820,"duration":5460,"startOfParagraph":false},{"content":"But we would never--","startTime":1654280,"duration":1720,"startOfParagraph":false},{"content":"you don't need to memorize all of the different possible styling things. Or any of them.","startTime":1656000,"duration":6390,"startOfParagraph":false},{"content":"JQuery things you should remember--","startTime":1662390,"duration":7630,"startOfParagraph":true},{"content":"you should remember dot-HTML, and a common pattern in jQuery--let's re-write this.","startTime":1670020,"duration":8360,"startOfParagraph":false},{"content":"A common pattern is we have $(\"#f\").html","startTime":1678380,"duration":11260,"startOfParagraph":false},{"content":"If I put just plain parentheses that means get the HTML;","startTime":1689640,"duration":6010,"startOfParagraph":false},{"content":"whereas if I say HTML and put whatever I want in here--some link to something--","startTime":1695650,"duration":8220,"startOfParagraph":false},{"content":"putting something inside of the parentheses now sets the HTML.","startTime":1703870,"duration":6540,"startOfParagraph":false},{"content":"That's pretty common amongst a bunch of functions.","startTime":1710410,"duration":3350,"startOfParagraph":false},{"content":"There's the same deal with text.","startTime":1713760,"duration":4600,"startOfParagraph":false},{"content":"The difference between HTML and text is that text is going to insert this","startTime":1718360,"duration":3360,"startOfParagraph":false},{"content":"as literal less-than a, greater-than instead of as an anchor tag.","startTime":1721720,"duration":4630,"startOfParagraph":false},{"content":"And text is going to be the same if I just do this.","startTime":1726350,"duration":6650,"startOfParagraph":false},{"content":"It's going to retrieve the text of the document--not the HTML of the document","startTime":1733000,"duration":2760,"startOfParagraph":false},{"content":"but just the text within this element.","startTime":1735760,"duration":6050,"startOfParagraph":false},{"content":"Another one is if 'f' happens to be an ID for an input,","startTime":1741810,"duration":6620,"startOfParagraph":false},{"content":"then hash-f-dot-val--if I want to set the input to something like--","startTime":1748430,"duration":5820,"startOfParagraph":false},{"content":"let's say I hit a checkbox and I want to set a default value--","startTime":1754250,"duration":3650,"startOfParagraph":false},{"content":"dot-val--I don't even know--3--so that will automatically insert into the text box 3,","startTime":1757900,"duration":8170,"startOfParagraph":false},{"content":"but if I say 3-dot-val, that will retrieve whatever is currently in the text box for me.","startTime":1766070,"duration":9910,"startOfParagraph":false},{"content":"This is useful for form validation where","startTime":1775980,"duration":3710,"startOfParagraph":true},{"content":"if I just want to make sure that they actually filled out all of the things.","startTime":1779690,"duration":8340,"startOfParagraph":false},{"content":"One way of doing that is if after I hit submit it's inevitably sent to some page on the server--","startTime":1788030,"duration":6680,"startOfParagraph":false},{"content":"like for us it would be PHP--and that would try to process the data and it would say","startTime":1794710,"duration":5480,"startOfParagraph":false},{"content":"they didn't fill something out, so that now redirects them to another page that says","startTime":1800190,"duration":2840,"startOfParagraph":false},{"content":"you didn't fill everything out.","startTime":1803030,"duration":2020,"startOfParagraph":false},{"content":"Instead of having to do that, in JavaScript/jQuery you can just see if val is empty.","startTime":1805050,"duration":6600,"startOfParagraph":false},{"content":"Or is val--empty quotes.","startTime":1811650,"duration":5620,"startOfParagraph":false},{"content":"That's going to just--now we can alert them that you didn't fill out this field.","startTime":1817270,"duration":5850,"startOfParagraph":false},{"content":"Inevitably you do need to do the PHP server-side checking because","startTime":1823120,"duration":3870,"startOfParagraph":false},{"content":"you can just disable JavaScript in all the browsers.","startTime":1826990,"duration":4220,"startOfParagraph":false},{"content":"But JavaScript makes it convenient for those who do have it activated,","startTime":1831210,"duration":4970,"startOfParagraph":false},{"content":"and virtually ninety-nine-point-something percent of browsers have it on nowadays.","startTime":1836180,"duration":6760,"startOfParagraph":false},{"content":"Very few people turn JavaScript off.","startTime":1842940,"duration":3690,"startOfParagraph":false},{"content":"It is a user convenience. You need to do PHP validation.","startTime":1846630,"duration":6220,"startOfParagraph":false},{"content":"You should do JavaScript validation.","startTime":1852850,"duration":3140,"startOfParagraph":false},{"content":"[Student] What does #f refer to here?","startTime":1855990,"duration":1960,"startOfParagraph":true},{"content":"[Rob] What does #f refer to?","startTime":1857950,"duration":2070,"startOfParagraph":false},{"content":"There is some element in my document with ID 'f'.","startTime":1860020,"duration":4330,"startOfParagraph":false},{"content":"We'll look at--probably Facebook has plenty of examples where if I come to elements","startTime":1864350,"duration":5500,"startOfParagraph":false},{"content":"looking here under the elements tag I see this particular div that's being highlighted up here--","startTime":1869850,"duration":7970,"startOfParagraph":false},{"content":"or is it the whole page--yeah, it's up there. This has ID pagelet_bluebar.","startTime":1877820,"duration":4850,"startOfParagraph":false},{"content":"In console I assume they're using jQuery.","startTime":1882670,"duration":4060,"startOfParagraph":false},{"content":"So, I could select pagelet_bluebar so that selects that, and I did something wrong.","startTime":1886730,"duration":13300,"startOfParagraph":false},{"content":"Let's try--or maybe they aren't using jQuery and that character's mapped to something else.","startTime":1906470,"duration":5780,"startOfParagraph":false},{"content":"A better example in something I know is using jQuery--","startTime":1912250,"duration":12720,"startOfParagraph":false},{"content":"still looking at our elements here--we have here class equals navbar.","startTime":1924970,"duration":5630,"startOfParagraph":false},{"content":"This is something with class navbar, ","startTime":1930600,"duration":1730,"startOfParagraph":false},{"content":"so inside of our console we can look up the thing with class navbar.","startTime":1932330,"duration":6850,"startOfParagraph":false},{"content":"Here we can scroll over this and see that's what this is.","startTime":1939180,"duration":2590,"startOfParagraph":false},{"content":"If I wanted to do .text this is the text of that, so I see settings for report above log out","startTime":1941770,"duration":8080,"startOfParagraph":false},{"content":"which are all under here, but that's still text within that HTML tag.","startTime":1949850,"duration":5910,"startOfParagraph":false},{"content":"I could set the HTML to just some link,","startTime":1955760,"duration":16470,"startOfParagraph":false},{"content":"so I'll get rid of my bar. Now that got rid of the header entirely just so it's linked to YouTube.","startTime":1972230,"duration":4320,"startOfParagraph":false},{"content":"And is there any form example?","startTime":1976550,"duration":3080,"startOfParagraph":true},{"content":"Here's a form.","startTime":1979630,"duration":2310,"startOfParagraph":false},{"content":"I can right-click and inspect element to come to it right here.","startTime":1981940,"duration":3890,"startOfParagraph":false},{"content":"I see that its ID is text search,","startTime":1985830,"duration":2630,"startOfParagraph":false},{"content":"so down here if I do ID text search.","startTime":1988460,"duration":8450,"startOfParagraph":false},{"content":"I'll bring over it and I see that is the correct thing I was searching for.","startTime":1996910,"duration":6280,"startOfParagraph":false},{"content":"If I want to do .val it would give me what I had typed there.","startTime":2003190,"duration":4480,"startOfParagraph":false},{"content":"If I wanted to do hello it'll change it up here to hello--jQuery.","startTime":2007670,"duration":8340,"startOfParagraph":false},{"content":"Of course I could do ridiculous like document.get element by ID--text search--","startTime":2016010,"duration":9770,"startOfParagraph":false},{"content":"I don't even know what it is at this point--dot value--no, I forgot that guy.","startTime":2025780,"duration":8220,"startOfParagraph":false},{"content":"So, that's hello. I don't know how I'd set it equals something. ","startTime":2034000,"duration":5110,"startOfParagraph":false},{"content":"Yeah, so that changed that.","startTime":2039110,"duration":1820,"startOfParagraph":false},{"content":"But you don't need to use these and very many websites at this point use jQuery.","startTime":2040930,"duration":6580,"startOfParagraph":false},{"content":"Even like on a final project--if you're doing a web project--the first thing","startTime":2047510,"duration":5540,"startOfParagraph":false},{"content":"I recommend is just including jQuery so you can get the convenience of all these functions.","startTime":2053050,"duration":6980,"startOfParagraph":false},{"content":"[Student] I think I saw a different way to get to a element using dom.","startTime":2062580,"duration":5170,"startOfParagraph":true},{"content":"Do you have to use dot and then keep going down?","startTime":2067750,"duration":4770,"startOfParagraph":false},{"content":"[Rob] You can do that. I don't know if it would work very well.","startTime":2072520,"duration":4110,"startOfParagraph":false},{"content":"It's difficult to navigate that way.","startTime":2076630,"duration":2270,"startOfParagraph":false},{"content":"One example is--I don't even know if we have any forms--","startTime":2078900,"duration":4279,"startOfParagraph":false},{"content":"but document.forms is going to return the list of forms that's on this page,","startTime":2083179,"duration":5761,"startOfParagraph":false},{"content":"then I can do document.forms 0 is going to be the first form.","startTime":2088940,"duration":6130,"startOfParagraph":false},{"content":"Dot--I don't know what we've called that--so it doesn't even have a name,","startTime":2095070,"duration":8000,"startOfParagraph":false},{"content":"so maybe inputs will work. No.","startTime":2103070,"duration":4980,"startOfParagraph":false},{"content":"I don't even know how to get at this--get element-I-tag name input.","startTime":2108050,"duration":3000,"startOfParagraph":false},{"content":"Yeah, that gave me the input, and now I want the 0 to input","startTime":2111050,"duration":12580,"startOfParagraph":false},{"content":"and I want to select its value, so that's going to be text.","startTime":2123630,"duration":7690,"startOfParagraph":false},{"content":"I had to end up doing get elements by tag name anyway.","startTime":2131320,"duration":2570,"startOfParagraph":false},{"content":"There might be some way to select it directly","startTime":2133890,"duration":2320,"startOfParagraph":false},{"content":"through form 0, but the nice thing about this is still like I only had to get the tags called input","startTime":2136210,"duration":7270,"startOfParagraph":false},{"content":"that were a child of this form; otherwise if I just do that straight up front","startTime":2143480,"duration":6400,"startOfParagraph":false},{"content":"this would select all elements on the entire page, in the entire document ","startTime":2149880,"duration":6800,"startOfParagraph":false},{"content":"instead of just that form and it probably won't even be the one I want.","startTime":2156680,"duration":3900,"startOfParagraph":false},{"content":"I don't even know which one it is. I don't know.","startTime":2160580,"duration":5600,"startOfParagraph":false},{"content":"I guess the first input element on our page is this little checkbox.","startTime":2166180,"duration":7270,"startOfParagraph":false},{"content":"[Student] This is pretty unrelated","startTime":2173450,"duration":7000,"startOfParagraph":true},{"content":"and possibly kind of silly, but on the answer key it says that PHP--","startTime":2180450,"duration":6970,"startOfParagraph":false},{"content":"I don't know whether it's the answer key or notes but it says PHP is server-side","startTime":2187420,"duration":8240,"startOfParagraph":false},{"content":"and JavaScript is client-side. What is the difference between the 2?","startTime":2195660,"duration":3930,"startOfParagraph":false},{"content":"[Rob] The difference between JavaScript client-side and PHP server-side.","startTime":2199590,"duration":5960,"startOfParagraph":false},{"content":"If you have heard of slash/used node js before you would think that ","startTime":2205550,"duration":6340,"startOfParagraph":false},{"content":"JavaScript isn't just client-side but for CS50 purposes it is--","startTime":2211890,"duration":4390,"startOfParagraph":false},{"content":"or at least for this quiz's purposes it is.","startTime":2216280,"duration":3060,"startOfParagraph":false},{"content":"PHP being server-side. No JavaScript.","startTime":2219340,"duration":4460,"startOfParagraph":false},{"content":"When you write your webpage you will be writing PHP on the server.","startTime":2223800,"duration":4900,"startOfParagraph":false},{"content":"You will never be writing JavaScript on the server.","startTime":2228700,"duration":2970,"startOfParagraph":false},{"content":"JavaScript ends up getting sent to the browser where the JavaScript code executes.","startTime":2231670,"duration":5520,"startOfParagraph":false},{"content":"And the JavaScript code needs to live in the browser because otherwise when I want to","startTime":2237190,"duration":5060,"startOfParagraph":false},{"content":"just do any sort of JavaScript-y thing like clicking on this,","startTime":2242250,"duration":3580,"startOfParagraph":false},{"content":"I'm not reloading a page. This is just JavaScript re-formatting things for me.","startTime":2245830,"duration":5890,"startOfParagraph":false},{"content":"If JavaScript lived on the server, then I would need to inevitably request something","startTime":2251720,"duration":4770,"startOfParagraph":false},{"content":"of the server to know what to do.","startTime":2256490,"duration":3000,"startOfParagraph":false},{"content":"PHP--there is no such thing as PHP in the browser.","startTime":2259490,"duration":5890,"startOfParagraph":false},{"content":"When I request a page--so let's say here I requested this particular page.","startTime":2265380,"duration":6710,"startOfParagraph":false},{"content":"That means that this is going to request--","startTime":2272090,"duration":5180,"startOfParagraph":false},{"content":"refresh--it's going to refresh this page--","startTime":2277270,"duration":7000,"startOfParagraph":false},{"content":"so this request goes out to our server.","startTime":2284270,"duration":2940,"startOfParagraph":false},{"content":"It sees that it needs to return this particular thread with this particular ID,","startTime":2287210,"duration":5980,"startOfParagraph":false},{"content":"so now that's going to be some PHP that the PHP interpreter is going to interpret that page","startTime":2293190,"duration":10550,"startOfParagraph":false},{"content":"and transform it into just HTML, CSS, maybe JavaScript, whatever.","startTime":2303740,"duration":4940,"startOfParagraph":false},{"content":"It's PHP that processes this request and retrieves all of the text and stuff","startTime":2308680,"duration":8250,"startOfParagraph":false},{"content":"that I'm actually looking for from the database.","startTime":2316930,"duration":2240,"startOfParagraph":false},{"content":"But what leaves the server is just HTML/JS/CSS.","startTime":2319170,"duration":5580,"startOfParagraph":false},{"content":"There's no PHP which leaves the server because if it actually did","startTime":2324750,"duration":3880,"startOfParagraph":false},{"content":"then the browser would have no idea what to do with it because it doesn't know what PHP is.","startTime":2328630,"duration":5260,"startOfParagraph":false},{"content":"But in the same thought because JavaScript is client-side,","startTime":2333890,"duration":6360,"startOfParagraph":false},{"content":"you can never access MySQL from it.","startTime":2340250,"duration":2000,"startOfParagraph":false},{"content":"Because PHP is server-side you do access MySQL from it.","startTime":2342250,"duration":5180,"startOfParagraph":false},{"content":"[Student] Can you go over some of the security concerns with cookies in HTTP?","startTime":2347430,"duration":5450,"startOfParagraph":true},{"content":"[Rob] Those are not things we're going to need to know.","startTime":2352880,"duration":5510,"startOfParagraph":false},{"content":"Some of the security concerns with cookies in HTTP.","startTime":2358390,"duration":6110,"startOfParagraph":false},{"content":"The big question here is we see here that my cookie is PHP/ID.","startTime":2364500,"duration":4050,"startOfParagraph":false},{"content":"That's like the universal PHP your session.","startTime":2368550,"duration":5010,"startOfParagraph":false},{"content":"Your session is something that inside of PHP will never need to be validated","startTime":2373560,"duration":5990,"startOfParagraph":false},{"content":"because it's the server that has complete control over the session.","startTime":2379550,"duration":6140,"startOfParagraph":false},{"content":"You can't touch it at all.","startTime":2385690,"duration":2000,"startOfParagraph":false},{"content":"But it's this cookie--this one--","startTime":2387690,"duration":5430,"startOfParagraph":false},{"content":"and I guess you could log in as me right now if you wanted to use that--","startTime":2393120,"duration":4380,"startOfParagraph":false},{"content":"but it's that cookie that the--inevitably you make a single request to the server.","startTime":2397500,"duration":9110,"startOfParagraph":false},{"content":"The server returns the page. The request is done.","startTime":2406610,"duration":3280,"startOfParagraph":false},{"content":"It no longer has any idea who you are.","startTime":2409890,"duration":2690,"startOfParagraph":false},{"content":"So, the next request you make is going to include that cookie so that it knows","startTime":2412580,"duration":4650,"startOfParagraph":false},{"content":"this is the person who made this request before. ","startTime":2417230,"duration":2580,"startOfParagraph":false},{"content":"This is the session data that is associated with this user.","startTime":2419810,"duration":4020,"startOfParagraph":false},{"content":"That's why you don't have to log in for each and every page you use.","startTime":2423830,"duration":4380,"startOfParagraph":false},{"content":"The security issue here is that that cookie is sent out over the web.","startTime":2428210,"duration":5170,"startOfParagraph":false},{"content":"We're using HTTPS here, so in this case that means that we are encrypting this stuff.","startTime":2433380,"duration":8110,"startOfParagraph":false},{"content":"Someone can't come in and just steal my cookie and now the server will think they're me.","startTime":2441490,"duration":8380,"startOfParagraph":false},{"content":"But with straight HTTP they can. ","startTime":2449870,"duration":2190,"startOfParagraph":false},{"content":"Just like this WireShark/FireSheep stuff that you can just listen to all of the wi-fis in the air","startTime":2452060,"duration":5590,"startOfParagraph":false},{"content":"and intercept whatever you want, so yeah.","startTime":2457650,"duration":3730,"startOfParagraph":false},{"content":"[Student] A sort of similar security risk is storing user ID's in post ","startTime":2461380,"duration":11050,"startOfParagraph":true},{"content":"because that can be freely edited using consoles and things.","startTime":2472430,"duration":4430,"startOfParagraph":false},{"content":"[Rob] Yes. There's plenty of issues where like just anything that comes from the user","startTime":2476860,"duration":6550,"startOfParagraph":false},{"content":"you need to validate.","startTime":2483410,"duration":3530,"startOfParagraph":false},{"content":"There are plenty of cases where it would be useful for like I'm about to make a post.","startTime":2486940,"duration":10710,"startOfParagraph":false},{"content":"Blah, blah, blah, blah, blah. Then I hit reply.","startTime":2497650,"duration":2000,"startOfParagraph":false},{"content":"It would be very useful if the post request included my ID because","startTime":2499650,"duration":4890,"startOfParagraph":false},{"content":" I want to associate this post with me.","startTime":2504540,"duration":4070,"startOfParagraph":false},{"content":"But I can't do that because I am free to make a post request--just like manually","startTime":2508610,"duration":6210,"startOfParagraph":false},{"content":"come up with my own post request--","startTime":2514820,"duration":3000,"startOfParagraph":false},{"content":"that uses your user ID and now it will post as you.","startTime":2517820,"duration":3140,"startOfParagraph":false},{"content":"That's why server-side I can't rely on post requests containing the correct user ID.","startTime":2520960,"duration":6480,"startOfParagraph":false},{"content":"That's why it has to belong in my session.","startTime":2527440,"duration":2280,"startOfParagraph":false},{"content":"So I look up your user ID in my session array and I insert that into my database ","startTime":2529720,"duration":5420,"startOfParagraph":false},{"content":"as the user who actually made this post.","startTime":2535140,"duration":2440,"startOfParagraph":false},{"content":"[Student] And that's based on your cookie?","startTime":2537580,"duration":2000,"startOfParagraph":false},{"content":"[Rob] Yeah. It uses the cookie to match up you as the user who made that request.","startTime":2539580,"duration":5110,"startOfParagraph":false},{"content":"It pulls out the user ID from that session and that then inserts into the database","startTime":2544690,"duration":5880,"startOfParagraph":false},{"content":"using that user ID.","startTime":2550570,"duration":2390,"startOfParagraph":false},{"content":"This like button--what that's actually doing is--","startTime":2552960,"duration":7370,"startOfParagraph":false},{"content":"I'm not going to find it here. It's going to be an Ajax function","startTime":2560330,"duration":3480,"startOfParagraph":false},{"content":"What is Ajax function? ","startTime":2563810,"duration":2970,"startOfParagraph":false},{"content":"Let me find out what my JavaScript is.","startTime":2566780,"duration":8720,"startOfParagraph":false},{"content":"It was a CS50 project a while ago.","startTime":2575500,"duration":4210,"startOfParagraph":false},{"content":"I can't remember what it is.","startTime":2579710,"duration":3170,"startOfParagraph":false},{"content":"Ajax function--all Ajax function is doing is making an Ajax request to a page with this ID--","startTime":2582880,"duration":9650,"startOfParagraph":false},{"content":"with the ID 22453.","startTime":2592530,"duration":3280,"startOfParagraph":false},{"content":"It's not even a post request. It's a get request which makes it even easier.","startTime":2595810,"duration":4370,"startOfParagraph":false},{"content":"If I knew what the URL is--it's something like like this/ID=22453--","startTime":2600180,"duration":7680,"startOfParagraph":false},{"content":"or ?ID=22453--","startTime":2607860,"duration":5430,"startOfParagraph":false},{"content":"so visiting this URL will like that.","startTime":2613290,"duration":7000,"startOfParagraph":false},{"content":"Which wouldn't be as much of a problem but it's incredibly easy to write a loop","startTime":2620290,"duration":4310,"startOfParagraph":false},{"content":"which is just going to visit this URL over and over again, which is why you see ","startTime":2624600,"duration":3900,"startOfParagraph":false},{"content":"Isawyouharvard post with thousands of things. ","startTime":2628500,"duration":2680,"startOfParagraph":false},{"content":"And they tend to be CS50-based Isawyouharvard posts.","startTime":2631180,"duration":5780,"startOfParagraph":false},{"content":"How do I find the most-liked?","startTime":2636960,"duration":4240,"startOfParagraph":false},{"content":"They tend to get deleted pretty quickly, too.","startTime":2641200,"duration":2520,"startOfParagraph":false},{"content":"This is not the most-liked. There we go.","startTime":2643720,"duration":2770,"startOfParagraph":false},{"content":"Cheaters on the most liked page--that's pretty relevant to this right now.","startTime":2646490,"duration":6910,"startOfParagraph":false},{"content":"Oh wow. They've already deleted any of the ones from this year which have been ","startTime":2653400,"duration":7830,"startOfParagraph":false},{"content":"cheated on. Those have all been deleted.","startTime":2661230,"duration":4360,"startOfParagraph":false},{"content":"There will never be a post that gets this high.","startTime":2665590,"duration":3090,"startOfParagraph":false},{"content":"This one was obviously cheated on to get on to the most liked page.","startTime":2668680,"duration":4180,"startOfParagraph":false},{"content":"More questions?","startTime":2676570,"duration":2740,"startOfParagraph":true},{"content":"[Student] What should we know about XHTML?","startTime":2679310,"duration":6740,"startOfParagraph":false},{"content":"[Rob] Virtually nothing. Just what it is.","startTime":2686050,"duration":3660,"startOfParagraph":false},{"content":"The difference between it and HTML being that XML is very similar in appearance ","startTime":2689710,"duration":9510,"startOfParagraph":false},{"content":"to HTML except in HTML we just have to have a predefined set of tags.","startTime":2699220,"duration":9860,"startOfParagraph":false},{"content":"But with XML--XML is just like a general format where you can make an XML document","startTime":2709080,"duration":6300,"startOfParagraph":false},{"content":"for whatever purposes you want.","startTime":2715380,"duration":2200,"startOfParagraph":false},{"content":"So, for example, if I wanted I could construct an XML for the courses--","startTime":2717580,"duration":8370,"startOfParagraph":false},{"content":"and I actually think that CS50 has an API for this.","startTime":2725950,"duration":2910,"startOfParagraph":false},{"content":"My XML document could look something like--","startTime":2728860,"duration":2730,"startOfParagraph":false},{"content":"courses and of course I need some end courses.","startTime":2731590,"duration":7740,"startOfParagraph":false},{"content":"I could have a course and it could have name equals CS50.","startTime":2739330,"duration":9590,"startOfParagraph":false},{"content":"And then my end course and I could put inside of here students,","startTime":2748920,"duration":9160,"startOfParagraph":false},{"content":"and then inside of students I have a list of one student whose name is whatever.","startTime":2758080,"duration":8930,"startOfParagraph":false},{"content":"I end that student and so on.","startTime":2767010,"duration":3170,"startOfParagraph":false},{"content":"I just happen to have constructed some arbitrary XML document, but it is valid XML.","startTime":2770180,"duration":5890,"startOfParagraph":false},{"content":"XML--all it is is this sort of structure and the nice thing--the reason that we even call it XML","startTime":2776070,"duration":7630,"startOfParagraph":false},{"content":"is that this sort of thing is very easy to parse.","startTime":2783700,"duration":3120,"startOfParagraph":false},{"content":"It's very easy to take this document and make an array out of it.","startTime":2786820,"duration":5760,"startOfParagraph":false},{"content":"And so XHTML is an attempt to get HTML to be valid XML.","startTime":2792580,"duration":6790,"startOfParagraph":false},{"content":"Already this looks pretty similar to HTML.","startTime":2799370,"duration":3210,"startOfParagraph":false},{"content":"Some of the differences are HTML you are able to do things like input maybe type equals text","startTime":2802580,"duration":9580,"startOfParagraph":false},{"content":"which is the default so I don't need to say that.","startTime":2812160,"duration":3390,"startOfParagraph":false},{"content":"Disabled.","startTime":2815550,"duration":4460,"startOfParagraph":false},{"content":"There are 2 things in here that make this invalid XHTML.","startTime":2820010,"duration":5150,"startOfParagraph":true},{"content":"The first thing is that all XML tags need a closing tag.","startTime":2825160,"duration":3590,"startOfParagraph":false},{"content":"So in the case of input I need to do the--which direction of slash is it?","startTime":2828750,"duration":4290,"startOfParagraph":false},{"content":"This direction? That looks wrong.","startTime":2833040,"duration":2020,"startOfParagraph":false},{"content":"Other direction.","startTime":2835060,"duration":4320,"startOfParagraph":false},{"content":"Self-closing tag.","startTime":2839380,"duration":2580,"startOfParagraph":false},{"content":"The second thing is that with XML you need these sorts of like key value pairs.","startTime":2841960,"duration":7600,"startOfParagraph":false},{"content":"It needs a value associated with it.","startTime":2849560,"duration":2570,"startOfParagraph":false},{"content":"So, even though disabled in and of itself expresses what I want--","startTime":2852130,"duration":2920,"startOfParagraph":false},{"content":"this input should be disabled--","startTime":2855050,"duration":2060,"startOfParagraph":false},{"content":"that's invalid XHTML.","startTime":2857110,"duration":2000,"startOfParagraph":false},{"content":"What I actually need to write is disabled equals disabled.","startTime":2859110,"duration":8000,"startOfParagraph":false},{"content":"Now it's valid XHTML.","startTime":2867110,"duration":2510,"startOfParagraph":false},{"content":"And these are just these slight differences that transform HTML to an XML-based sort of thing.","startTime":2869620,"duration":5230,"startOfParagraph":false},{"content":"[Student] XML is about like pull through your own X altogether like why is it (inaudible) ","startTime":2874850,"duration":10030,"startOfParagraph":true},{"content":"[Rob] The thing of like a CSV--a CSV you have just values separated by--","startTime":2884880,"duration":14570,"startOfParagraph":false},{"content":"just think of a spreadsheet. A CSV is basically a spreadsheet.","startTime":2899450,"duration":4100,"startOfParagraph":false},{"content":"You have maybe columns and you have a bunch of rows that","startTime":2903550,"duration":3170,"startOfParagraph":false},{"content":"associate data with those columns but that's it.","startTime":2906720,"duration":2880,"startOfParagraph":false},{"content":"XML is much more versatile in that you can--you have an arbitrary hierarchy of data.","startTime":2909600,"duration":8710,"startOfParagraph":false},{"content":"I could have multiple courses that have multiple students within it","startTime":2918310,"duration":4890,"startOfParagraph":false},{"content":"where it would be difficult to think of a spreadsheet that--","startTime":2923200,"duration":2260,"startOfParagraph":false},{"content":"just that single spreadsheet--CSV especially is like just a single spreadsheet--","startTime":2925460,"duration":5550,"startOfParagraph":false},{"content":"so that single spreadsheet having all CS50, 51, and 61 and within those all of the","startTime":2931010,"duration":7750,"startOfParagraph":false},{"content":"students related to those times, maybe meeting times and all of that sort of thing.","startTime":2938760,"duration":4470,"startOfParagraph":false},{"content":"The other thing is that the tag names give a nice name to all of the elements","startTime":2943230,"duration":5910,"startOfParagraph":false},{"content":"so reading a CSV file can be difficult to try and parse what it's actually seeing.","startTime":2949140,"duration":4000,"startOfParagraph":false},{"content":"XML is much more human-readable so that's why like--come up to some person who doesn't","startTime":2953140,"duration":6990,"startOfParagraph":false},{"content":"really know what a CSV file is or like isn't a programmer or something--","startTime":2960130,"duration":6250,"startOfParagraph":false},{"content":"you can give them like a template XML file and they can follow the lines and--","startTime":2966380,"duration":4260,"startOfParagraph":false},{"content":"oh, I'm supposed to insert my name here.","startTime":2970640,"duration":2950,"startOfParagraph":false},{"content":"It's a much more usable format.","startTime":2973590,"duration":3850,"startOfParagraph":false},{"content":"CSV has plenty of uses but XML has different uses.","startTime":2977440,"duration":5000,"startOfParagraph":false},{"content":"More questions?","startTime":2986050,"duration":3630,"startOfParagraph":true},{"content":"Other questions?","startTime":2989680,"duration":2220,"startOfParagraph":false},{"content":"[Student] From the previous quiz--vertical scaling versus horizontal scaling.","startTime":2996410,"duration":4110,"startOfParagraph":false},{"content":"[Rob] You would not need to know that. I don't think we even discussed that.","startTime":3000520,"duration":4140,"startOfParagraph":false},{"content":"I'm guessing it was just a one-off comment.","startTime":3004660,"duration":2680,"startOfParagraph":false},{"content":"Oh. Horizontal versus vertical scaling is not something you'll need to know.","startTime":3007340,"duration":5320,"startOfParagraph":false},{"content":"I think the difference is just like--oh well, the answer key will say the difference.","startTime":3012660,"duration":5910,"startOfParagraph":false},{"content":"Vertical scaling is just like oh, my computer's doing poorly. I'll get a better one.","startTime":3018570,"duration":7460,"startOfParagraph":false},{"content":"Whereas horizontal scaling is oh, my computer is doing poorly--","startTime":3026030,"duration":3120,"startOfParagraph":false},{"content":"let me get 20 of them to all work on the same task.","startTime":3029150,"duration":4210,"startOfParagraph":false},{"content":"[Student] Can we go over the linked list way of making queues. >>[Rob] Sure.","startTime":3040300,"duration":5220,"startOfParagraph":true},{"content":"That's easier than the array way.","startTime":3045520,"duration":4480,"startOfParagraph":false},{"content":"The linked list way of making queues.","startTime":3050000,"duration":3140,"startOfParagraph":false},{"content":"First, what does our struct for a linked list look like?","startTime":3053140,"duration":5210,"startOfParagraph":false},{"content":"[Student] Are we doing it for-- >>[Rob] Let's do its--yeah.","startTime":3058350,"duration":18710,"startOfParagraph":false},{"content":"Int val; then struct node* next;","startTime":3077060,"duration":12940,"startOfParagraph":false},{"content":"so that's what we'll use for the example here.","startTime":3090000,"duration":4560,"startOfParagraph":false},{"content":"Let's actually type up this stuff.","startTime":3094560,"duration":3100,"startOfParagraph":false},{"content":"Let's do linked_list.","startTime":3100030,"duration":9570,"startOfParagraph":false},{"content":"Our struct--","startTime":3111750,"duration":2000,"startOfParagraph":false},{"content":"Okay. Now looking at our queue we have the--","startTime":3125360,"duration":7700,"startOfParagraph":false},{"content":"let's just make a global queue.","startTime":3133060,"duration":3030,"startOfParagraph":false},{"content":"It'll be node* queue; and we have a dequeue function.","startTime":3136090,"duration":7040,"startOfParagraph":false},{"content":"I guess these things could also overturn true or false--let's do that.","startTime":3143130,"duration":5200,"startOfParagraph":false},{"content":"Bool dequeue--and we're dequeueing--oh. Hmm.","startTime":3148330,"duration":10360,"startOfParagraph":false},{"content":"Int dequeue--what did we do with this before?","startTime":3158690,"duration":6510,"startOfParagraph":false},{"content":"Int dequeue and we have bool enqueue and we need to enqueue some means true.","startTime":3165200,"duration":9140,"startOfParagraph":false},{"content":"Let's do enqueue first.","startTime":3174340,"duration":7020,"startOfParagraph":false},{"content":"We have our queue. We want to insert something into the queue.","startTime":3181360,"duration":5160,"startOfParagraph":false},{"content":"What is the best way to do that?","startTime":3186520,"duration":6200,"startOfParagraph":false},{"content":"Over here our queue currently looks like we have some global pointer to start.","startTime":3192720,"duration":7550,"startOfParagraph":false},{"content":"There's our queue.","startTime":3200270,"duration":4640,"startOfParagraph":false},{"content":"Assuming that we dequeue by taking the first element,","startTime":3204910,"duration":5440,"startOfParagraph":false},{"content":"where are we going to want to insert our node so that queues work as they should?","startTime":3210350,"duration":6220,"startOfParagraph":false},{"content":"[Student] At the very end. >>[Rob] Yeah. Queues are supposed to be first in, first out.","startTime":3216570,"duration":6870,"startOfParagraph":false},{"content":"Which means that the new element should be inserted over here. Okay.","startTime":3223440,"duration":4590,"startOfParagraph":false},{"content":"Coming back to code,","startTime":3228030,"duration":5190,"startOfParagraph":true},{"content":"that means that we will want to loop over our queue.","startTime":3233220,"duration":6540,"startOfParagraph":false},{"content":"Let's do node* current = queue; while current does not equal NULL.","startTime":3239760,"duration":10450,"startOfParagraph":false},{"content":"I would do--all right, let's do it separately.","startTime":3250210,"duration":6750,"startOfParagraph":false},{"content":"First, current = queue.","startTime":3256960,"duration":3500,"startOfParagraph":false},{"content":"What do we do if current starts off as NULL?","startTime":3260460,"duration":4200,"startOfParagraph":false},{"content":"We'll do this 2 ways. First this way.","startTime":3264660,"duration":3750,"startOfParagraph":false},{"content":"What do we do if current is NULL?","startTime":3268410,"duration":3040,"startOfParagraph":false},{"content":"Is this equivalent to if queue is NULL?","startTime":3271450,"duration":3400,"startOfParagraph":false},{"content":"[Student] It's going to return false. >>[Rob] Should we return false?","startTime":3278550,"duration":5410,"startOfParagraph":false},{"content":"What's wrong with inserting something into an empty list?","startTime":3283960,"duration":3160,"startOfParagraph":false},{"content":"[Student] Nothing is wrong with that. Sorry.","startTime":3287120,"duration":1960,"startOfParagraph":false},{"content":"[Rob] Yeah. So here the only difference is my global queue is being sent to my new node.","startTime":3289080,"duration":6900,"startOfParagraph":false},{"content":"And then I have to do my checks of if queue is NULL.","startTime":3297840,"duration":5040,"startOfParagraph":false},{"content":"Return false.","startTime":3302880,"duration":3080,"startOfParagraph":false},{"content":"And then queue val equals i; queue next equals NULL; return true.","startTime":3305960,"duration":14950,"startOfParagraph":false},{"content":"Okay. I'm going to jump the gun right here.","startTime":3320910,"duration":4980,"startOfParagraph":false},{"content":"Remember what we did that last time","startTime":3325890,"duration":3680,"startOfParagraph":false},{"content":"where we said it was much easier to work with node** with this sort of thing.","startTime":3329570,"duration":6090,"startOfParagraph":false},{"content":"So now current is going to be &queue, and coming down to here--","startTime":3335660,"duration":8220,"startOfParagraph":false},{"content":"while current--while *current does not equal NULL--","startTime":3343880,"duration":9130,"startOfParagraph":false},{"content":"so let me just do current--we'll talk about this in a second.","startTime":3353010,"duration":5220,"startOfParagraph":false},{"content":"Current next. Okay.","startTime":3358230,"duration":2630,"startOfParagraph":false},{"content":"Looking at it in this way, this is iterating over all of my pointers until I reach a null pointer.","startTime":3360860,"duration":12050,"startOfParagraph":false},{"content":"The null pointer is going to be the pointer I want to replace with my new node.","startTime":3372910,"duration":4800,"startOfParagraph":false},{"content":"Looking at iPad version--","startTime":3377710,"duration":4200,"startOfParagraph":false},{"content":"if my original pointer and the linked list is empty then current is going to point here.","startTime":3381910,"duration":5890,"startOfParagraph":false},{"content":"This is going to point to null, ","startTime":3387800,"duration":1830,"startOfParagraph":false},{"content":"so this is the pointer I end up moving to point to some other new node.","startTime":3389630,"duration":4810,"startOfParagraph":false},{"content":"Whereas if the example is this case up here","startTime":3394440,"duration":3710,"startOfParagraph":false},{"content":"then current is going to traverse from here--I messed up slightly.","startTime":3398150,"duration":4570,"startOfParagraph":false},{"content":"Where current is supposed to be the address of current next.","startTime":3402720,"duration":7980,"startOfParagraph":false},{"content":"Is that what I want? Current so *current gives me a node.","startTime":3410700,"duration":9500,"startOfParagraph":false},{"content":"Next traverses to the next one.","startTime":3420200,"duration":4240,"startOfParagraph":false},{"content":"I'm currently pointing here. ","startTime":3424440,"duration":6260,"startOfParagraph":false},{"content":"Let's do red--so I'm currently pointing here.","startTime":3430700,"duration":3020,"startOfParagraph":false},{"content":"Then *current is going to reference this node.","startTime":3433720,"duration":5990,"startOfParagraph":false},{"content":"And *current next references this node, but that's not what I want.","startTime":3439710,"duration":5370,"startOfParagraph":false},{"content":"I want this pointer to that node.","startTime":3445080,"duration":2620,"startOfParagraph":false},{"content":"So, that pointer to this node is ampersand (*current) next.","startTime":3447700,"duration":12830,"startOfParagraph":false},{"content":"At this point in time I've officially reached the node that I want to replace.","startTime":3467660,"duration":6700,"startOfParagraph":true},{"content":"Let's replace all of these queues current--and now we're done.","startTime":3474360,"duration":19410,"startOfParagraph":false},{"content":"There may be typos, but the idea is that with insert in this sort of way","startTime":3493770,"duration":7990,"startOfParagraph":false},{"content":"it is easier to work with the pointers that we want to change ","startTime":3501760,"duration":6370,"startOfParagraph":false},{"content":"instead of needing to keep track of--okay, is my start NULL?","startTime":3508130,"duration":4650,"startOfParagraph":false},{"content":"Oh it is? Then I need to create the start node to be something specific","startTime":3512780,"duration":3650,"startOfParagraph":false},{"content":"else I'll want to iterate until the next thing I point to is NULL,","startTime":3516430,"duration":3880,"startOfParagraph":false},{"content":"and then I'll replace that--what the next thing is--to my malloc node.","startTime":3520310,"duration":6430,"startOfParagraph":false},{"content":"Instead of needing to separate those cases, here I only deal with the case of ","startTime":3526740,"duration":4000,"startOfParagraph":false},{"content":"what is the pointer that is NULL that I no longer want to be NULL,","startTime":3530740,"duration":4250,"startOfParagraph":false},{"content":"and that makes life easier except these should all be *current now because--","startTime":3534990,"duration":6830,"startOfParagraph":false},{"content":"[Student] Are they still the size of a node?","startTime":3541820,"duration":3640,"startOfParagraph":false},{"content":"[Rob] Yes. I'm still mallocing a node.","startTime":3545460,"duration":5020,"startOfParagraph":false},{"content":"[Student] Is it going to be the size of a node*?","startTime":3550480,"duration":2500,"startOfParagraph":false},{"content":"[Rob] Coming back to here, think of the case if this is our linked list.","startTime":3552980,"duration":8010,"startOfParagraph":false},{"content":"This guy points off to NULL.","startTime":3568330,"duration":4860,"startOfParagraph":false},{"content":"After that why loop, current points to here","startTime":3573190,"duration":3760,"startOfParagraph":false},{"content":"because this is the pointer that is NULL.","startTime":3576950,"duration":4560,"startOfParagraph":false},{"content":"Now I want to change this pointer to point to a new node.","startTime":3581510,"duration":8870,"startOfParagraph":false},{"content":"First I malloc that new node--so malloc size of node.","startTime":3590380,"duration":8010,"startOfParagraph":false},{"content":"And that returns a node* and now changing this pointer is building to *current equals ","startTime":3598390,"duration":12680,"startOfParagraph":false},{"content":"this new node that I allocated.","startTime":3611070,"duration":4710,"startOfParagraph":false},{"content":"So, if current is a node**, then *current is going to be a node*,","startTime":3615780,"duration":10710,"startOfParagraph":false},{"content":"and if I'm mallocing something the size of node then this is returning a pointer to a node","startTime":3626490,"duration":6050,"startOfParagraph":false},{"content":"so this is a node*--so both sides correctly have the same type.","startTime":3632540,"duration":7090,"startOfParagraph":false},{"content":"And so if what I just allocated was NULL, return false; ","startTime":3639630,"duration":6980,"startOfParagraph":false},{"content":"else finish setting them to what I want them to be--except these need parentheses ","startTime":3646610,"duration":8140,"startOfParagraph":false},{"content":"because that's not how the order of things work.","startTime":3654750,"duration":2980,"startOfParagraph":false},{"content":"Without the parentheses that was being interpreted as ","startTime":3657730,"duration":1960,"startOfParagraph":false},{"content":"current-arrow-val dereference that.","startTime":3659690,"duration":3320,"startOfParagraph":false},{"content":"Instead I want to dereference current which brings me to a node.","startTime":3663010,"duration":4000,"startOfParagraph":false},{"content":"Then I want to get the value associated with that node.","startTime":3667010,"duration":3610,"startOfParagraph":false},{"content":"[Student] I thought arrows allowed you to bypass that and go straight to the value.","startTime":3670620,"duration":7050,"startOfParagraph":true},{"content":"[Rob] They do. That's if I have--let's say queue is an example.","startTime":3677670,"duration":4970,"startOfParagraph":false},{"content":"I'm allowed to do queue-arrow-val equals i because queue is a node*.","startTime":3682640,"duration":5760,"startOfParagraph":false},{"content":"If there were some nice syntax of like current-longer arrow-val or something","startTime":3688400,"duration":10760,"startOfParagraph":false},{"content":"which did 2 dereferences, then this would work well.","startTime":3699160,"duration":3380,"startOfParagraph":false},{"content":"[Student] So the arrow is only for 1 dereference. >>[Rob] Yeah.","startTime":3702540,"duration":2250,"startOfParagraph":false},{"content":"Alternatively I could write this as (**current.val).","startTime":3704790,"duration":8800,"startOfParagraph":false},{"content":"Just like I could also write queue as (*queue).val.","startTime":3713590,"duration":8900,"startOfParagraph":false},{"content":"So let's insert. Well, that's in queue I guess.","startTime":3724430,"duration":4820,"startOfParagraph":false},{"content":"Dequeue is going to be significantly shorter.","startTime":3729250,"duration":2780,"startOfParagraph":false},{"content":"Let's put void in here for cleanliness.","startTime":3732030,"duration":6250,"startOfParagraph":false},{"content":"So, dequeue. What element am I dequeueing?","startTime":3738280,"duration":4540,"startOfParagraph":false},{"content":"[Student] The first one? >>[Rob] Yeah.","startTime":3742820,"duration":2000,"startOfParagraph":false},{"content":"If my first one is NULL--return--I don't know what we want to return--INT_MAX;","startTime":3744820,"duration":8060,"startOfParagraph":false},{"content":"and then you should do a check to see if INT_MAX was returned.","startTime":3752880,"duration":4700,"startOfParagraph":false},{"content":"That's the sort of thing that get inc does else we want to--","startTime":3757580,"duration":6510,"startOfParagraph":false},{"content":"can we just return queue val? Is that what we want to do?","startTime":3764090,"duration":10520,"startOfParagraph":false},{"content":"Dequeue also implicitly removes the item from the queue,","startTime":3774610,"duration":3400,"startOfParagraph":false},{"content":"so let's first say--let's get a tmp to point to the first node of our queue.","startTime":3778010,"duration":12830,"startOfParagraph":false},{"content":"Now we want to advance our queue to point to the next thing in the queue.","startTime":3790840,"duration":4670,"startOfParagraph":false},{"content":"Now we have tmp left. Tmp val is the thing we want to return.","startTime":3795510,"duration":5940,"startOfParagraph":false},{"content":"So, val = tmp->val;","startTime":3801450,"duration":2730,"startOfParagraph":false},{"content":"but before we return it we should free tmp and return val.","startTime":3804180,"duration":7010,"startOfParagraph":false},{"content":"The order of operations here is important in that we need to grab a tmp ","startTime":3811190,"duration":5160,"startOfParagraph":false},{"content":"before we move queue to the next element.","startTime":3816350,"duration":4170,"startOfParagraph":false},{"content":"We need to get the value before we free tmp,","startTime":3820520,"duration":4340,"startOfParagraph":false},{"content":"and then we can return the val.","startTime":3824860,"duration":3850,"startOfParagraph":false},{"content":"[Student] Should we set the queue to queue next?","startTime":3828710,"duration":1970,"startOfParagraph":true},{"content":"[Rob] Yes. That was creating a bad loop/it wouldn't work after freeing it anyway.","startTime":3830680,"duration":7120,"startOfParagraph":false},{"content":"Queue = queue->next.","startTime":3837800,"duration":2100,"startOfParagraph":false},{"content":"We want to advance the queue into the next element not advance the next element","startTime":3839900,"duration":3330,"startOfParagraph":false},{"content":"to what the element currently is.","startTime":3843230,"duration":4940,"startOfParagraph":false},{"content":"Stacks would be significantly--like even easier in that dequeue is exactly the same","startTime":3848170,"duration":9490,"startOfParagraph":false},{"content":"because we're pulling off the front of the stack.","startTime":3857660,"duration":2530,"startOfParagraph":false},{"content":"End queue would be very similar where we just want to allocate a node","startTime":3860190,"duration":3840,"startOfParagraph":false},{"content":"and insert into the front of the stack, so we don't even need to loop over anything.","startTime":3864030,"duration":3640,"startOfParagraph":false},{"content":"We just insert directly at the front.","startTime":3867670,"duration":3750,"startOfParagraph":false},{"content":"Is everyone good on that?","startTime":3882500,"duration":2140,"startOfParagraph":false},{"content":"Okay. More questions?","startTime":3884640,"duration":5120,"startOfParagraph":true},{"content":"[Student] What major things should I keep in mind from the most recent lecture?","startTime":3889760,"duration":6810,"startOfParagraph":false},{"content":"[Rob] The most recent lecture.","startTime":3896570,"duration":2160,"startOfParagraph":false},{"content":"You do not need to know any code.","startTime":3898730,"duration":2890,"startOfParagraph":false},{"content":"You should know the overarching ideas.","startTime":3901620,"duration":5970,"startOfParagraph":false},{"content":"Nate's half didn't have any code and so those slides are online.","startTime":3907590,"duration":4060,"startOfParagraph":false},{"content":"They're just like look at them and they have the major ideas.","startTime":3911650,"duration":3570,"startOfParagraph":false},{"content":"My half--knowing the overall idea of first you can't trust anything.","startTime":3915220,"duration":13410,"startOfParagraph":false},{"content":"The fact that like maybe the process of the compiler can be bad,","startTime":3928630,"duration":9440,"startOfParagraph":false},{"content":"but it doesn't even matter that the source code looks fine.","startTime":3938070,"duration":2800,"startOfParagraph":false},{"content":"Because the compiler might be specifically altered to change the source code","startTime":3940870,"duration":5520,"startOfParagraph":false},{"content":" in the process of compiling.","startTime":3946390,"duration":4470,"startOfParagraph":false},{"content":"At the same time just like--I think those are like the major ideas of it.","startTime":3950860,"duration":7280,"startOfParagraph":false},{"content":"[Student] Did you mention that we don't need to know anything related to Firesheep--","startTime":3959560,"duration":9470,"startOfParagraph":true},{"content":"or do we need to know that?","startTime":3969030,"duration":4080,"startOfParagraph":false},{"content":"[Rob] With Nate's half of things, anything that Nate touched on--","startTime":3973110,"duration":5250,"startOfParagraph":false},{"content":"like FireSheep, WireShark--I don't even think he did Firesheep in detail.","startTime":3978360,"duration":4400,"startOfParagraph":false},{"content":"You also did something with that--was it Firesheep--last week?","startTime":3982760,"duration":5860,"startOfParagraph":false},{"content":"Did you touch on that?","startTime":3988620,"duration":2490,"startOfParagraph":false},{"content":"[Student] Yeah, I think we might have-- >>[Rob] Yeah.","startTime":3991110,"duration":2950,"startOfParagraph":false},{"content":"We're not going to give you Firesheep output and say interpret this.","startTime":3994060,"duration":6820,"startOfParagraph":false},{"content":"It's just going to be--it would be a question like what is Firesheep?","startTime":4000880,"duration":4080,"startOfParagraph":false},{"content":"What is it used for?","startTime":4004960,"duration":2330,"startOfParagraph":false},{"content":"[Student] I think it only works on version 4 of Firefox or something.","startTime":4007290,"duration":4830,"startOfParagraph":false},{"content":"[Rob] It might be broken by now. ","startTime":4012120,"duration":3200,"startOfParagraph":false},{"content":"I have no idea.","startTime":4031430,"duration":2640,"startOfParagraph":false},{"content":"They don't seem to have disabled it manually,","startTime":4034070,"duration":4260,"startOfParagraph":false},{"content":"but maybe it doesn't work with the most recent Firefox.","startTime":4038330,"duration":2880,"startOfParagraph":false},{"content":"[Student] I actually tried installing it because it said it would be compatible.","startTime":4041210,"duration":3580,"startOfParagraph":false},{"content":"[Rob] So, I guess it doesn't work with the most recent Firefox.","startTime":4044790,"duration":4090,"startOfParagraph":false},{"content":"But the idea still stands of what it was meant to show.","startTime":4048880,"duration":3480,"startOfParagraph":false},{"content":"It was absurd how much of the world was not living in HTTPS at the time.","startTime":4052360,"duration":7070,"startOfParagraph":false},{"content":"Even in the last 2 years or whatever, it's still--there's dramatic improvement in the","startTime":4059430,"duration":4390,"startOfParagraph":false},{"content":"number of websites which use HTTPS.","startTime":4063820,"duration":3390,"startOfParagraph":false},{"content":"[Student] Do we need to go over HTTP?","startTime":4069920,"duration":2660,"startOfParagraph":true},{"content":"[Rob] The protocol of it? >>[Student] Some of the things that we should know.","startTime":4072580,"duration":5470,"startOfParagraph":false},{"content":"[Rob] All right. Basic things are everything you can see in your network tab.","startTime":4078050,"duration":8170,"startOfParagraph":false},{"content":"When I request a page--coming back up to the top for the main things.","startTime":4086220,"duration":5940,"startOfParagraph":false},{"content":"You can see here the request that I make.","startTime":4092160,"duration":3930,"startOfParagraph":false},{"content":"Chrome happens to format it all nicely for us","startTime":4096090,"duration":3130,"startOfParagraph":false},{"content":"where the request URL was this, the request method was GET, ","startTime":4099220,"duration":2750,"startOfParagraph":false},{"content":"and the status code was 200 OK.","startTime":4101970,"duration":2830,"startOfParagraph":false},{"content":"If I hit view source, I see more directly that--","startTime":4104800,"duration":3479,"startOfParagraph":false},{"content":"and this is--we could show you either of these, but it isn't too difficult to interpret between them.","startTime":4108279,"duration":7401,"startOfParagraph":false},{"content":"Here is the direct request I made, so this means that I went to ","startTime":4115680,"duration":6049,"startOfParagraph":false},{"content":"apps.cs50.net/discuss/threads/inbox/all/HTTP/1.1.","startTime":4121729,"duration":6431,"startOfParagraph":false},{"content":"And the protocol it used was HTTP/1.1 which is virtually--it's always going to be that.","startTime":4128160,"duration":9409,"startOfParagraph":false},{"content":"Over here we used GET, so this might also be POST.","startTime":4137569,"duration":3921,"startOfParagraph":false},{"content":"And then coming down--all the way down to response headers--if we view that source,","startTime":4141490,"duration":3170,"startOfParagraph":false},{"content":"it's where we see the 200 OK.","startTime":4144660,"duration":3080,"startOfParagraph":false},{"content":"Know the possible different status codes of these.","startTime":4147740,"duration":3329,"startOfParagraph":false},{"content":"I think in the review we do say a couple of these,","startTime":4151069,"duration":4451,"startOfParagraph":false},{"content":"so 403, 404--those kind of common ones.","startTime":4155520,"duration":5120,"startOfParagraph":false},{"content":"That's the major idea of it.","startTime":4160640,"duration":6170,"startOfParagraph":false},{"content":"The difference just between HTTP and HTTPS is this encryption.","startTime":4169990,"duration":5130,"startOfParagraph":false},{"content":"[Student] Are you done? >>[Rob] I think so. Well, yep.","startTime":4175120,"duration":7199,"startOfParagraph":true},{"content":"[Student] Will you talk very generally about how encryption works?","startTime":4182319,"duration":4151,"startOfParagraph":false},{"content":"Because we talked for example when compressing Huffman files,","startTime":4186470,"duration":3450,"startOfParagraph":false},{"content":"you know how to decompress them because you actually sent the hashtable within the file","startTime":4189920,"duration":4970,"startOfParagraph":false},{"content":"so how does encryption work? ","startTime":4194890,"duration":2060,"startOfParagraph":false},{"content":"How do you know how to encrypt information if you haven't actually sent the client","startTime":4196950,"duration":3880,"startOfParagraph":false},{"content":"the key to the--and you can actually grab that key from--?","startTime":4200830,"duration":4910,"startOfParagraph":false},{"content":"How does the general process work?","startTime":4205740,"duration":2000,"startOfParagraph":false},{"content":"[Rob] The general process of encryption--","startTime":4207740,"duration":2130,"startOfParagraph":false},{"content":"that is an incredibly detailed question I will answer.","startTime":4209870,"duration":5720,"startOfParagraph":false},{"content":"There is a short--well, Tommy and I made the short.","startTime":4215590,"duration":5900,"startOfParagraph":false},{"content":"Unfortunately it is like 26 minutes, so it is not a short. It is a long.","startTime":4221490,"duration":4570,"startOfParagraph":false},{"content":"But our short was on RSA which is just one example of these,","startTime":4226060,"duration":5470,"startOfParagraph":false},{"content":"and this RSA is part of the overall HTTPS protocol.","startTime":4231530,"duration":8890,"startOfParagraph":false},{"content":"The idea--RSA is an example of public key cryptography,","startTime":4240420,"duration":5640,"startOfParagraph":false},{"content":"which means you have 2 separate keys.","startTime":4246060,"duration":3630,"startOfParagraph":false},{"content":"You use 1 key to actually encrypt things,","startTime":4249690,"duration":2000,"startOfParagraph":false},{"content":"and you use another key to decrypt things.","startTime":4251690,"duration":2720,"startOfParagraph":false},{"content":"This key that you use to encrypt things is the one that's public.","startTime":4254410,"duration":3950,"startOfParagraph":false},{"content":"The website can send you this encryption key.","startTime":4258360,"duration":5140,"startOfParagraph":false},{"content":"They do send you that encryption key, and when you want to send something back to them","startTime":4263500,"duration":4780,"startOfParagraph":false},{"content":"you use that encryption key to encrypt all of your data and send it to them.","startTime":4268280,"duration":5270,"startOfParagraph":false},{"content":"So, they are the only ones with the private key.","startTime":4273550,"duration":2560,"startOfParagraph":false},{"content":"If that private key became known then anyone would be able to decrypt your data.","startTime":4276110,"duration":6520,"startOfParagraph":false},{"content":"But that private key--which is mathematically related to the public key but you cannot","startTime":4282630,"duration":5350,"startOfParagraph":false},{"content":"figure one out from the other--so that private key can be used to decrypt the data.","startTime":4287980,"duration":5660,"startOfParagraph":false},{"content":"Since they are the only ones with the private key, ","startTime":4293640,"duration":2990,"startOfParagraph":false},{"content":"they're the only ones who can read the data.","startTime":4296630,"duration":2290,"startOfParagraph":false},{"content":"So even though the public key is public,","startTime":4298920,"duration":5250,"startOfParagraph":false},{"content":"I use the same--when I go to Google.com or whatever,","startTime":4304170,"duration":3490,"startOfParagraph":false},{"content":"they might have multiple, I don't know--but if I go to Google.com, ","startTime":4307660,"duration":2350,"startOfParagraph":false},{"content":"he goes to Google.com, she goes to Google.com--","startTime":4310010,"duration":4760,"startOfParagraph":false},{"content":"we all can use the same public key to encrypt our own information however we want.","startTime":4314770,"duration":4480,"startOfParagraph":false},{"content":"But none of us are going to be able to figure out--are going to be able to decrypt","startTime":4319250,"duration":4760,"startOfParagraph":false},{"content":"to their information because the public key isn't able to decrypt.","startTime":4324010,"duration":5930,"startOfParagraph":false},{"content":"It can only encrypt.","startTime":4329940,"duration":3110,"startOfParagraph":false},{"content":"And it's fun/detailed math of--like a bunch of module operators and exponentials and stuff,","startTime":4333050,"duration":10200,"startOfParagraph":false},{"content":"that it just works out that the private key is the only thing that can","startTime":4343250,"duration":5640,"startOfParagraph":false},{"content":"decrypt the public key's encryption stuff.","startTime":4348890,"duration":4730,"startOfParagraph":false},{"content":"Yeah. See the RSA short for more details.","startTime":4353620,"duration":4400,"startOfParagraph":false},{"content":"[Student] Is that on the website?","startTime":4358020,"duration":3860,"startOfParagraph":false},{"content":"[Rob] Yeah, I think it is at this point. Or at least a YouTube link to it was posted.","startTime":4361880,"duration":4330,"startOfParagraph":false},{"content":"Let's see. Shorts. I think it would have been week 2-related. Yeah. RSA.","startTime":4371330,"duration":5860,"startOfParagraph":false},{"content":"And it is--we're not going to play this--24 minutes.","startTime":4377190,"duration":6590,"startOfParagraph":false},{"content":"It's a long one.","startTime":4383780,"duration":2000,"startOfParagraph":false},{"content":"More questions?","startTime":4387740,"duration":2000,"startOfParagraph":true},{"content":"[Student] Could you talk briefly about the bitmasks? >>[Rob] Sure.","startTime":4389740,"duration":5030,"startOfParagraph":false},{"content":"Briefly, the idea is just that like-- >>[Student] What is it, Rob?","startTime":4394770,"duration":8320,"startOfParagraph":false},{"content":"[Rob] Bitmasks. The idea is--let's just say we have some--we're using some integer--","startTime":4403090,"duration":9670,"startOfParagraph":false},{"content":"int x--so, we start it off at 0.","startTime":4412760,"duration":8730,"startOfParagraph":false},{"content":"Now, this integer is 32 bits, so any single 1 of those bits can be used to represent","startTime":4421490,"duration":6410,"startOfParagraph":false},{"content":"a specific FLAC. ","startTime":4427900,"duration":2700,"startOfParagraph":false},{"content":"This is where if you look at operating system codes, they use this all over the place","startTime":4430600,"duration":5610,"startOfParagraph":false},{"content":"where maybe up top somewhere they hash-define--","startTime":4436210,"duration":7690,"startOfParagraph":false},{"content":"Let's see some examples.","startTime":4443900,"duration":5120,"startOfParagraph":false},{"content":"Man-2-open--the open-system call we can see here that one of its arguments is int flags--","startTime":4449020,"duration":13700,"startOfParagraph":false},{"content":"what it expects as that argument are some of these flags.","startTime":4462720,"duration":6400,"startOfParagraph":false},{"content":"We see O_append, O_ASYNC, O_CLOEXEC,","startTime":4469120,"duration":3910,"startOfParagraph":false},{"content":"O_CREAT, and so on.","startTime":4473030,"duration":4100,"startOfParagraph":false},{"content":"O_DIRECT. These sorts of flags are hash-defined somewhere.","startTime":4477130,"duration":8130,"startOfParagraph":false},{"content":"And all of them are exactly 1 bit.","startTime":4485260,"duration":2000,"startOfParagraph":false},{"content":"So, O_CREAT might be hash-defined as 1, left-shift, 4 (1<<4).","startTime":4487260,"duration":10340,"startOfParagraph":false},{"content":"That's going to be the--whenever I use O_CREAT that's just going to be--","startTime":4497600,"duration":4680,"startOfParagraph":false},{"content":"in binary 1, 0, 0, 0, and 30-ish zeros before it.","startTime":4502280,"duration":7070,"startOfParagraph":false},{"content":"It's only a single bit a set, and that bit represents this flag.","startTime":4509350,"duration":4580,"startOfParagraph":false},{"content":"And so no other flag is going to be left-shifted by 4.","startTime":4513930,"duration":4230,"startOfParagraph":false},{"content":"I'm able to represent up to 32 flags in a single integer by doing--","startTime":4518160,"duration":12230,"startOfParagraph":false},{"content":"x = O_CREAT bit wise or O_DIRECT.","startTime":4530390,"duration":10460,"startOfParagraph":false},{"content":"You're just picking any 2 of those flags.","startTime":4540850,"duration":2790,"startOfParagraph":false},{"content":"Now x is going to have 2 bits set which correspond to the 2 bits ","startTime":4543640,"duration":4960,"startOfParagraph":false},{"content":"of O_CREAT and O_DIRECT.","startTime":4548600,"duration":4890,"startOfParagraph":false},{"content":"The way that then--so then we passed x into the open function,","startTime":4553490,"duration":5250,"startOfParagraph":false},{"content":"and open needs to see what flags were actually set.","startTime":4558740,"duration":4210,"startOfParagraph":false},{"content":"So, that's where it's going to do things like ","startTime":4562950,"duration":3530,"startOfParagraph":false},{"content":"if (x & O_CREAT) do something,","startTime":4566480,"duration":12860,"startOfParagraph":false},{"content":"or if ( x & O_DIRECT) do something else,","startTime":4579340,"duration":7770,"startOfParagraph":false},{"content":"and then there may be some flag that we didn't have set--","startTime":4587110,"duration":3190,"startOfParagraph":false},{"content":"if (x & O_--I don't know what the other flags were--","startTime":4590300,"duration":5430,"startOfParagraph":false},{"content":"(x & O_RDONLY)--that particular condition is not going to be executed.","startTime":4595730,"duration":6410,"startOfParagraph":false},{"content":"Or that block of code is not going to be executed,","startTime":4602140,"duration":1890,"startOfParagraph":false},{"content":"but these 2 are because those 2 flags were set.","startTime":4604030,"duration":4000,"startOfParagraph":false},{"content":"And notice that in C, any value that is not 0 is true.","startTime":4608030,"duration":9370,"startOfParagraph":false},{"content":"So, (x & O_CREAT) will be either 0 or O_CREAT","startTime":4617400,"duration":7620,"startOfParagraph":false},{"content":"because O_CREAT only has a single bit set.","startTime":4625020,"duration":2970,"startOfParagraph":false},{"content":"If that bit is set next, then this is going to return O_CREAT--","startTime":4627990,"duration":4810,"startOfParagraph":false},{"content":"the binary where just that bit is set.","startTime":4632800,"duration":3840,"startOfParagraph":false},{"content":"If that bit next is not set, then it's going to return 0, in which case we know the flag was not set.","startTime":4636640,"duration":6760,"startOfParagraph":false},{"content":"That's how you use bitmasks. ","startTime":4643400,"duration":2000,"startOfParagraph":false},{"content":"I think on a previous exam or maybe in class or something--","startTime":4645400,"duration":3650,"startOfParagraph":false},{"content":"you can also use bitmasks to print out the binary of a variable.","startTime":4649050,"duration":6100,"startOfParagraph":false},{"content":"So I can use--looping over--1, left-shift, 0--and then print if x & that--","startTime":4655150,"duration":11100,"startOfParagraph":false},{"content":"if x & 1, left shift, 0--then print a 0 or 1. Or print a 1 else print a 0.","startTime":4666250,"duration":6320,"startOfParagraph":false},{"content":"And then I go over once more--if x & 1, left-shift, 2--then that means that the second bit","startTime":4672570,"duration":8050,"startOfParagraph":false},{"content":"of the variable is set, so I print a 1 else I print a 0.","startTime":4680620,"duration":3830,"startOfParagraph":false},{"content":"And I think we might actually want to do that in the reverse order because","startTime":4684450,"duration":2410,"startOfParagraph":false},{"content":"usually you want the left side to be the highest-order bits","startTime":4686860,"duration":3260,"startOfParagraph":false},{"content":"and the right side to be the lowest-order bits, so it would probably loop 4 int i = 31 until I hit 0,","startTime":4690120,"duration":14390,"startOfParagraph":false},{"content":"then do that exact condition--if x & 1, left-shift, i; print 1 else 0.","startTime":4704510,"duration":7810,"startOfParagraph":false},{"content":"[Student] Thank you.","startTime":4712320,"duration":2000,"startOfParagraph":false},{"content":"[Rob] I think we're out of time.","startTime":4716280,"duration":2270,"startOfParagraph":true},{"content":"Any more questions in the last couple of out-of-time seconds?","startTime":4718550,"duration":4290,"startOfParagraph":false},{"content":"All right. Good luck tomorrow.","startTime":4722840,"duration":4870,"startOfParagraph":false},{"content":"This was the last section where next week's going to be optional.","startTime":4727710,"duration":7070,"startOfParagraph":false},{"content":"I'll give back quizzes and we can go over them and maybe go over other things that","startTime":4734780,"duration":8990,"startOfParagraph":false},{"content":"you were interested in, or final project things, or future CS classes things or--I don't know.","startTime":4743770,"duration":5460,"startOfParagraph":false},{"content":"But this is the last material-filled section.","startTime":4749230,"duration":2840,"startOfParagraph":false},{"content":"Bye!","startTime":4752070,"duration":3000,"startOfParagraph":false},{"content":"(applause)","startTime":4755070,"duration":5900,"startOfParagraph":false},{"content":"[CS50.TV] ","startTime":4762250,"duration":2170,"startOfParagraph":true}]}