Tuesday, April 25, 2017

How To Flashing maximus vjoy rainbow plus

  No comments


keyword : How To Flashing maximus vjoy rainbow plus for bootloop , How To Flashing maximus vjoy rainbow plus for softbrick , How To Flashing maximus vjoy rainbow plus for hardbrick , How To Flashing maximus vjoy rainbow plus Error Camera , How To Flashing maximus vjoy rainbow plus blank screen , How To Flashing maximus vjoy rainbow plus lost password , How To Flashing maximus vjoy rainbow plus stuck logo , How To Flashing maximus vjoy rainbow plus new 2017. How To Flashing maximus vjoy rainbow plus repair phone.




Download one of the above file:


Further to the next stage
1. Copy the file to Sd Card
2.boot into recovery mode, in the file already exists in the form of .pdf open a full tutorial and follow the instructions. anyone using flashing software.
3. When've followed all of the conditions please check the phone has been normal what is not.
4.Ciri EMMC feature of flashing not damaged in the road, still can wipe data cache. but install the update form sd card can not or will not runing.
5.booting first after install rom fair amount of time of approximately 15 minutes. Do not hurry to remove the battery. wait until the system finishes booting.

important: before doing anything on the phone to do the data backup beforehand. can pass CMW, recovery, twrp please find if you have not got.

How To Flashing maximus vjoy rainbow plus

>> david malan: all right, we are back. so for the excitingconclusion, our last section on web programming, which ithought we'd use as a general term to capture a few remaining topics. so at the end of theday, we'll actually do a little bit of hands-on web programmingwith a language called javascript. and i think we'll take a lookat something related to images and discovering somethingsecretly hidden in an image, and also take a look at the googlemaps api, application programming

interface, as somethingrepresentative of the type of software that's increasingly andfreely available today. >> but why don't we take a lookat an ingredient to this world that we've kind of beentaking for granted exists for some time, a database. for the past day anda half we've assumed that we have access to a database, butwhat problem does a database solve? what does it do for us? what is it?

>> audience: [inaudible] david malan: holds all the information,ok, and what kinds of information might you put in it? >> david malan: any informationyou put in it, you'll get back. that is true. and on a typical web-based site or webapplication, what kinds of information, specifically, might you put in? audience: [inaudible] david malan: users.

so what's a user? david malan: ok, registereduser of the site. and what does it mean tostore users' information? what composes a user? a user has what? david malan: yeah, personaldata, and i like that. let's be more precise. so a user typically has a name,what else might a user have? david malan: an addr-- ok,so first name, last name.

that's good. actually, let's fixthat, because it's going to open up an opportunity fordiscussion, still, further. first name, last name, gender. an id of some sort. what else? i heard something else before, too. an email, postal address. >> so let's pause there and now considernot what we're storing in the database,

but-- and not why, since it's perhapsobvious that once you register a user, you want to remember them for some time. you don't want it tojust be stored in ram and be forgotten-- solet's focus on the how. >> it turns out that inthe world of databases, there's at least two types these days. something called a sql database,structured query language, or, cutely named,nosql, which is not sql. and the latter is anexample of what might

be called an object-oriented,or an object store, a database that stores objects, and not, excuseme, as we will soon see, rows. >> so we'll focus for just a moment onthe first of these, namely, a sql database, if only because it'sso familiar already, to anyone who has used excel orgoogle sheets or apple numbers or any standardspreadsheet program, or, equivalently, ormore sophisticatedly, something like microsoftaccess or oracle or mysql or postgresql, all of whichare product names for implementations

of the following idea. >> a relational database is simplysomething that has rows and columns. and by rows and columns,i literally mean something like this, so where we might have thename of a field and its type over here. and actually, let menow start to map these. so actually, i don't knowwhy i drew a separate chart. let's keep this simple. >> we have right here thebeginnings of our table, where this is the name of the fieldand this is the data type,

and by type i mean the following. is it a number, is it a string,a short string like a word, is it a paragraph, is itbinary data, like an image? and let's just tease thisapart for just a moment. so first name, number,string, large chunk of text-- david malan: yes, so string. and in a database context, we'lltypically call this char field. i'll just say char for now but we'regoing to refine this in a moment. character field.

last name's probably the same. gender? >> male or female, so itcould be a char field. it could be either quote, unquote"male" or quote, unquote "female" or it could be m or f. if you want to be more inclusive,you might need a third value or some kind of other field altogether. and so you could use true false. the field could be called male, andthen you could say true or false.

but that doesn't necessarily captureall of the information you might want. >> so it turns out there's another typeof field that might be useful here in a typical database, called anenum, where it is a character field, but you, the designer, get toenumerate the possible values, like quote, unquote "male", quote,unquote "female" and so forth. so that whatever valueis in your database, is indeed character-based, butit has to be one of those values. we probably wouldn't want anenum for first name or last name. otherwise we would haveto enumerate, as the name

derives from, literally everypossible first name and last name. >> ok, so id what should an id be? yes, so maybe a number. so let's stick withthat for now, number. and by number, number'sa little too broad now. for the end of the secondday, i feel like we should be a little more precise. number could mean like, itcould be something like 1.236. and that's probably notwhat we mean by an id.

what do we probably mean by an id? david malan: oh, ok, somaybe it's not even a number. maybe it's actually a unique identifierthat's a string, like a user name. so absolutely, could be. i think someone probablymeant numeric, though. so let's stay with that. what kind of number? what's a more precise-- an integer. so a number like 0, 1, 2, 3,so we'll call this an integer.

and even then, i couldbe nitpicking, it's not really just ageneral integer you want. you probably don't want negative values,just because, it just feels weird. you probably want positive integers. so you can also expressthat in a database, but for now, we'll say integer. >> email? this is probably just-- a what? >> david malan: it's an email,but that's characters, right?

it just has a funky character likean "at" symbol or something else, but it's still a character field. and postal address? so that's a nice beginning, butlet's be a little more precise now. >> so it turns out that ina database, you often have a choice over more refinedversions of these things. in fact, in a typical sql database, sql,or more generally, relational database, databases with rowsand columns, you often get to specify not only the type of thefield-- let me make some room here--

but also the length. >> so how long is a first name? i think, d-a-v-i-d. ok, got it iprobably just offended like half of the people in the room, right,since your names are longer than five letters, so five seems a little selfishand naive, so what's a better value? 10, all right, and i thinkwe're ok in the room. 13? 30? why don't i take theapproach of earlier when we

were talking about arrays and memory? why don't i just say like 1,000? no one's name is goingto be longer than 1,000. push back. david malan: yeah, it'swasteful, right, especially if most names are only five or 10 or15 characters, that's very wasteful. so you know what? this is kind of a hard question. now, we can certainly analyze englishand any other language's names

and figure out, well, what is theaverage-- average doesn't really help us-- what's the max isprobably what we really want. but it turns out we even havesome choice over the type here. >> in a typical sql database, youhave something called a char field and also a varchar, v-a-r,for variable char field. and the difference is this. a char field, you the designer,have to specify in advance the exact length of the field. so maybe the first namelike 20 feels kind of safe.

might have to do some googling tosee if that's actually safe enough. there's probably a name with 21characters, but for now, suppose 20 is safe. >> a char field would implyin a database that you are using 20 and always 20 characters. now if it's just d-a-v-i-d, 15 of thoseare just going to be blank characters, but you're still using all 20 bytes. a varchar field, by contrast, means thestring should be up to 20 characters but if it's only five,you're only going to use

five, or maybe six for aspecial value at the end, like that 0 we discussed thatsignifies the end of a character sequence in memory. >> so when do you thinkyou might choose char versus varchar, given that trade-off? char uses that many characters, varcharuses no more than that many characters. david malan: ok, when you know thelength of the string pretty compelling to just use char, 'cause ifyou know it, just put it down. and maybe that's true for a zipcode, in the us, at least, 02138,

it's always going to be fivecharacters until you add the dash four. but you might have some values forwhich you always know the length. or maybe state symbols,like ny for new york, and ma for massachusetts in the us. maybe you do have some situationswhere that's totally reasonable, but by that logic, why arewe even overthinking this? why don't we just usevarchar and then we'll just always use two characters anyway, oralways use five characters anyway? why not just save varchar foreverything, by that logic?

there must be a catch. david malan: couldwrite something wrong. so that is true. but even then, they can't usemore memory than i allocate. i still have the finalsay over the length, so they can't accidentally makethat mistake, but a good thought. it's more subtle, but it's very relatedto our discussion, actually, of arrays and linked lists earlier. >> it turns out that a database, ifit knows that all of the values are

of a fixed length, even ifsome of those values are blank, sort of aesthetically blank,d-a-v-i-d and then 15 blanks, it turns out that if everyfield is the same length, much like an array had all of its stuffback to back to back to back so that you could just plus 1 to get to the nextvalue, same idea in a database table. if all of your characterstrings are the same length, you have what's called random access. if all the strings are oflength 20, you don't just do plus 1 you just do plus20, plus 20, plus 20, plus 20,

and you can very rapidly scroll throughor search through all of your data. >> a variable char field, by contrast,doesn't always have 20 characters. it might have 20 and then15 and then 19 and then 10, and so if you want to searchthrough it, you can't just blindly add 20 bytes to get to the next one. you literally have to search throughbecause the edge of the data structure, if you will, is ragged. it kind of goes in and out basedon the actual length of the string. so when you know the length, askareem says, use a char field,

because you gain thatefficiency of being able to search through it fasterwhen you're looking for data, otherwise use a variable. >> unfortunately, i have no good answerto how long the name should be, but for something likea name, i would say a varchar is commonbecause it's not going to be a fixed length for everyone. 20, i don't know, 20feels a little tight. let's just say 50, 50.

it doesn't really cost you thatmuch more to say 50 instead of 40, but at some point, you needto make a judgment call. >> very common, frankly,for [? historical ?] reasons, even though it's excessive,is to say 255, because some time ago, in popular database systems, likemysql, a free open source tool that a lot of companieslike even facebook used, this was the maximum defaultso people just went with it. so not unreasonable, but we'lluse a little more intuition and say, sure 50, that'sprobably a little excessive.

>> gender, i do like enum,and so we can therefore enumerate male or female,or maybe more efficiently, m or f or some other symbology, butenum feels like a good choice there. to be clear, gendercould just be a varchar, and we could just allagree as nice people, to always put the same values there. male or female or whatnot. >> but the problem then, is that we couldmake a mistake, as [inaudible] proposed earlier in a different context.

if we make a mistake, we could getincorrect values in our database. so what's nice about databaseslike oracle and mysql and others, is that you have this lastlayer of defense where your dba, database administrator,whoever is designing this table like we are verbally, could putinto place an enum that protects against that by specifyingmale, female, and so no one else no programmer can accidentallyinsert any other value. so this would be a good thing. this is a feature.

>> so an id, assuming a numeric id, itprobably should be a positive integer. and we sometimes do haveopportunity to discuss length. you wouldn't typicallyspecify a number here, you would instead specifythis is a int, or a big int, as they're typically called. but typically, an integerwould be, let's say, 4 bytes. and if it's 4 bytes,that's how many bits? >> david malan: 32 bits. so how many users can we have inour database if they all have an id

and this id has to be unique? 32 bits means we have patternsof one, two, three, four, five-- so how many different patterns of zerosand ones can you have if there are 32? that's the same thing asasking what's two to the 32? it's a big number thati can't quite get right, but i know it's roughly 4 billion. so this means your database table canhave four billion users and that's it. >> so this is an interestingdesign implication. a decent number of companieshave decided, maybe not so much

for their users table, because having4 billion users is a rare problem. this is sort of a facebook-styleproblem, not a typical company problem. but maybe if you have transaction logsor some kind of data that constantly gets written into your databasethat absolutely could have billions and billions of rows, andyou use an integer for it, what's going to happen as soon asyou get to row number 4 billion and then you try to insert the4 billionth and 1, so to speak? i'm simplifying the numbers a bit. >> you can cut back, i mean youhave to handle it somehow.

and what a computer would typically do,think about it even from this morning, if you have a 4-bit valuelike 1, 1, 1, 1, which, just to tie the morningtogether to the afternoon, what does this number represent in binary? ok, we'll make it easier. what does this numberrepresent in binary? ok, we'll make it easier, whatdoes this represent in binary? audience: three. david malan: three, becausewe have the ones column--

[laughter] whew! we had the ones columnand the twos column. so suppose that, indeed, our[? infield ?] weren't 32 bits, but it were two bits, we cancount from user number 0, 1, 2, 3, and then we're kind ofback to user 00 again. so this is what typically happens. if you've ever heard the expression--probably haven't, but if you have-- integer overflow, where youkeep flipping all of your bits

to be the biggest possible values,and then you're out of bits, what would typically happen? why do i say 00? well, this is three. how do i represent 4? how do i represent thefor number 4 in binary? david malan: one-- yeah,don't say 100 per se, because it has the wrongconnotation, but 1-0-0. so that number 1-0-0 is indeedcorrect, but if you only have two bits,

what have you really done? you've rolled over to 00. and indeed, that's what would happen. actually, you can thinkabout this more familiarly. if you recall, what,16 years ago, the world was supposed to end whenthe y2k problem happened. why was that? well most computers, forreasonable decisions, were storing numbers like theyear 1975 or the year 1999

by just using two digitsin the computer's memory. so of course, what happenswhen you get to the year 2000, you go to this, or rather, yeah. so you go to the year 2000, but ifyou're only using two digits it looks like the year 00 andso you've rolled over. and this is why a lot of systemsneeded to be updated at the time. >> so with that said, companies likefacebook run up against this. so the only way to handle thesituation, frankly, is to anticipate it. or the cleanest way tohandle this situation

is to anticipate it so you don'thave to make changes later. so instead of 8 bytes, you know what? i'm going to be forward-thinkinghere, even though it's a little optimistic thatwe're going to have 4 billion and 1 users on our website. but let's just use 8 bytes, or64 bits, which would generally be called a big integer, very technical. and that just means you can haveeven more digits in your number. but this is an importantdesign decision,

because if you choose a number thathas too few bits of expressiveness you could actually createa bug in your software. >> all right, so let's wrap upwith email and postal address. so email, how long shouldan email address be? 50. i really have no idea, but it'sprobably something like that, because otherwise no one's going towrite you if it gets too long, so 50, let's go with it for now. postal address, how long should that be?

>> david malan: it's notjust a zip code, though. postal address, i heard. so this is like 1 brattle square,comma, cambridge mass., comma, 02138. and in fact, let me just pullup a little worksheet here. this feels like it'sa missed opportunity. if we have 1 brattle square,comma, cambridge ma 02138, i feel like we can do betterthan just postal address. why don't we explode this a little bit? what am i getting at?

what should we instead havefor our rows here, perhaps? >> david malan: yeah, so let'scall it street_number, and an underscore is just a commonway of having what looks like a space, but it's not, actually. street, and then city-- sorry? david malan: we could do that. line one, line two. why don't we will keepit simple for now, but that's absolutelyan acceptable decision.

and then state, and then let'sbe a little us-centric for now and just do zip code, just becauseit'll lead to an interesting mistake or problem here. so suppose that's now our address. it's a little more annoying thatwe have all these more fields, but now we can tagthings a little better. >> so now street number probablyshouldn't be a char, should it? what should it be? david malan: maybe, a numberlike an integer again?

a big integer? you probably don't liveat 4 billion main street or anything crazy like that. so integer is probablyfine, but has anyone ever lived at an address like1a brattle square, or 1 and 1/2? these things exist, unfortunately,even if you haven't lived there, there are these anomalieslike apartment 1a, 1b, 1c. so you know what, we probablyshouldn't go with integer, otherwise we're goingto lose some sales.

>> char field, maybe? i don't know how long. it's probably not going to bethat long, so 10 or something. no one's going to writea longer number, maybe. but again, we should probablygive more thought to that. maybe google, do some research,but we'll go with our guts for now. streets, char, 50, i don't know. at some point, no one's goingto write it on an envelope, too, so there's probablysome upper bounds there.

city, same, sure, so char 50. >> state, can be us-centric for now. so it could be a list, so kindof a judgment call, state. it could be like two characters. so actually, maybe, i kept saying char. i probably mean varchar,just for some efficiency, but we'll come back tothat decision in a moment. could be a char of length 2 for state. if in the us they have, like ma,massachusetts, ny, new york, nj, new

jersey, and so forth. so it could be fixed at that. dc for washington dc. >> but i think, olivier, youproposed another approach. david malan: yeah, so it's alittle annoying to type in, but an enum might make more sense,because this way, at least in the us, you could enumerate, if tediously, butyou do it just once in your database and never again have to think aboutit, all 50 two-character codes. so i like enum.

let's stick with that there, becauseit sort of enforces more rigor. and then zip code? i think andrew had a thought on that david malan: yeah, five or nine. let's just keep it simple. just do five for now. but maybe i could justdo an integer, right? i could, but you know what, i madethis mistake once, in some sense. years ago, i was migrating frommicrosoft outlook to gmail,

and outlook has a way of exportingall of your contacts as an excel file, a csv file, comma separated values file. and i made the mistake, ithink, of double clicking it, once i downloaded the export, tomake sure it looked as i expected. i must have hit save or letauto-save kick in or something. because when i then importedit into gmail, it all worked. but for years, to this day, andi did this five, 10 years ago, i'm still finding friends who haveaddresses that look like this. why?

>> david malan: it tookthe 0, well, rather, it took the whole zip code asa number, and therefore it's a leading 0 which meansit has no meaning. and so 2138 seems to be my zip code. and this is, frankly, an annoying excelfeature whereby i think by default, even if it's meant to justbe text, microsoft excel decides, let me be helpful,and oh, i see only numbers. let's treat these as numbers. and it truncates the leading zeros.

>> i swear to god, every coupleof months i find an address, and out of a sort of ocd, i go backin and add the 0, even though i never send people letters or anything. but i'm still finding remnants of this. so this is to say, is this a good idea? ok, no, because anyone inmassachusetts, in this area, is going to have a o leading them. so let's go with likechar, probably, five. >> and here, realize wecould use an enum and we

could enumerate 10,000possible zip codes, but that feels like it's probablycrossing a line of, like, benefits. if you have to input thatmuch data into your database to protect against something. so char realized you could typein h-e-l-l-o as your zip code, which is not, obviously, numeric. so there's no way, ina typical database, to specify only numeric andonly five characters long, so we're going to haveto do that in code.

we're going to do that in php orjava or whatever language we're using on the server to enforcethat kind of constraint. >> whoo! all right, so any questions just yet? let's make another design decision. it turns out that youalso get to choose, when designing a sql database, ortypical relational database-- where again, relational justmeans rows and columns, that's how you organize your data--and realize that what this means is,

i've been misleading inthat, i'm drawing-- this is what's called the schemafor a database table. this is like thespecifications for the table-- but when it comes timeto actually store data, and we'll do this just by example here. i'm going to open up excel, becauseexcel will give me rows and columns. and that's exactly what oracle andmysql and other tools will give me. so i'm just going to useit for discussion's sake. let me go ahead and open up arepresentative document here,

zoom in a bit. so for instance, our headers are nowfirst name, last name, gender, id, email, street number, street, whoops. street, city, state, justabout fits on the screen. >> so what this means is that when auser first registers for my website, it's going to be something likedavid, malan, m, let's say 1, malan@harvard.edu, street number willbe like 1 brattle square, cambridge, ma, 02138, and then so forth. so when i say that a relational databaseor sql database is rows and columns,

i mean this. that actual data is storedin rows and columns. this is just a coincidence,that we were talking, and i was just drawing itout in rows and columns. this is just the schema,the overarching definition. >> so of these fields here,or equivalently, there, which are the fields that you thinki'm likely to search on if i'm a user or if i'm the database administrator? like, what fields am iactually going to search on?

>> david malan: the name, yeah soi like the fact that-- yeah, email might be pretty common. sorry, you said name. so maybe-- and again, we'rekind of talking in the abstract. i don't know why you'dbe searching for a name, but that feels reasonable ifyou're searching for a user. maybe states, sure, id. >> and it's a slipperyslope, because i could contrive a scenario wheremaybe my boss has asked me,

how many men do we have on our site? how many women do we have on our site? and so at that point, you might wantto search on the gender field, too, and nothing else. so there's a trade-off here. again, there's noright answer, but there is a feature in most sql databasesknown as indexing, whereby you, the designer, thedatabase administrator, get to decide in advance whichfields the database should optimize

for searches on. >> you could very naively say, optimizethis, optimize that, optimize this, optimize that and this,and the database will do some magical thing underneath thehood, and do something in such a way that the next time you searchon any of these fields, it will, in fact, be faster. this is possible. it doesn't cancel itself out. but there must be a price paid.

>> if you naively, or over-enthusiasticallysay, index all of these fields, so to speak, make them allefficiently searchable, what price are you probably paying? david malan: performance. what do you mean? well performance, at least in thecontext i'm discussing, is better now. that's the definition of indexing. it will make searches faster. so time decreases, so to speak.

david malan: space. so again, these are a common trade. i can speed up your searches, but it'sgoing to cost you more bytes of space. well, by default, if we have none ofthese red stars, none of these indexes, as i'm saying, how do you searchfor a name in this database? so let's draw ourattention to this example. if we have david and scully and kareemand arwa and others in these rows, for instance. >> so let's do exactly that.

scully is in here, and thenwe have kareem, and arwa, and everyone else, if you don'thave an index defined, so to speak, the best you can do is linear search. if you search for arwa, we're notgoing to be able to jump right to her quickly. we're going to start top andgo all the way to the bottom, not unlike our originalmike smith example. >> if, however, i say, hey, database,index the first name field, then it's going to do somethingfancier and support something

like binary search. it's probably not binary search per se. databases tend to use anotherdata structure called b-trees, not to be confused with binary trees,that just make it faster to search something logarithmic in nature. but the price you pay to build up thatfeature, that data structure in memory, is more bytes. so it might take some megabytes,some gigabytes, who knows? it depends on the data.

>> so at some point, you have to decide,it's probably not a common case. so what are the actual commoncases, if you really had to choose, what might your favorite fields be? email. and i like email because email,in theory, should be unique. and so typically, when you knowin advance that one of your fields is or will be unique, thattends to be a good field to search on, because that way,when you search for something, you're going to get back one orzero responses and then you're done.

you don't have to keeplooking for yet others. >> and so in this case here, email,so long as you can't register twice with the same email, is a good one. id by definition, in thecomputer science world, if you're talking about anid, that had better be unique. that's sort of the connotationof id or identifier. and the rest of these might be,let's call them nice to haves, but not really required. >> and so in a database,you specify indexes,

but you can be even more precise. you can say, hey, database, make surethat every id in this table is unique. don't even let a programmeraccidentally put in a duplicate email or duplicate id number. so much like enumsprotect us similarly, you can have those lower-level defenses. and so database design, insome sense, is kind of fun, because you do it defensively. you sort of assume that you workwith horrible, horrible programmers

and you want to put in as many defensesas you can to protect your data, but simultaneously you wantto help them perform better by choosing whichfields to optimize for. but you can't necessarily do it ina vacuum like we kind of are here. you've got to know what arethose common cases being. if the developers areimplementing an address book, you might very well want to be ableto search on almost every field, just by nature of the application. so maybe you spendthat additional space.

>> right, any questions? yeah. >> david malan: no. >> david malan: ok. >> david malan: oh, so weare talking in a way now that's completely language agnostic. so we are talking now aboutrelational databases more generally, or sql databases more generally. >> david malan: a better word to useis, can be used by any language.

so i can write javascript code, ccode, c++ code, java code, ruby code, all of which talk to adatabase and execute queries. in fact, that's not a badsegue to an example query. and again, we're not going to go intojava or c++ or any of that anymore, but in sql, the language to which i keepreferring, structured query language, this itself is a programming language,but it's meant to be used for, no surprise, structured query queries. >> by that i mean this. the way you select datafrom a mysql database

is you literally type in your programsomething like select star from users. i am assuming that this table,henceforth is called users. i could call it anything we want,but that kind of makes sense. and so select is a verycommon verb, if you will, in sql, that literally does that. what do you think starmeans in this context? >> david malan: i'm sorry? >> david malan: not required, it'smore inclusive than that, actually. it's the wild card character.

star almost always means anything,so this means, in this case, select everything from the database. so when i say this, i meangive me back every column from my table called users. so give me a result set, as it's called. in other words, give me a copy of thespreadsheet, is what i'm getting at. >> but if i said select star from userswhere id equals 1, how big should my result set be then? or equivalently, how many rows shouldi be handed back from the database?

probably just one, if i have indeedtreated id as a unique identifier, and if david has that unique id, ishould get back one and only one row containing all of david's information. if i said this where idequals 99, i should get back, in this context, zero rows,at least at the moment. >> however, if i don't really careabout all that information, i could just say, where does david live? select zip code fromusers where id is 1. this will select to me only david's zipcode and not the entirety of that row.

why might i do this instead ofthe star query, the wild card? >> david malan: yeah, i might only need it. so performance is again the answer here. why ask for moreinformation than you need, because even if it's all right together,you still have to copy that data, it would seem, from the databaseinto your program somehow, and that's just silly if youonly need five of those digits, not the entirety of the row. >> so how do i insert a user?

suppose a user has justregistered for the first time. the syntax would usually look like this. insert into users, andthen we would say values, and then we would say valueslike, let's say, lauren scully, our videographer right here. and the next field is gender. so we'll say quote, unquote"f", then we have an id and i'm going to say-- let'spretend she's not actually here, so we'll rewind in the story.

so 2 will be her id. and then the next fieldhere is her email. so it's going to be likelauren scully and so forth, and we'll just dot dotdot it away from here on. now it will get a littletedious, but the insert query would ultimately look like that. >> if i want to get rid ofscully, uh-oh, let's deregister her, she deletes her account,delete from users where id equals 2, will get rid of scully.

or i can say update users set,let's say, what could we change? suppose she moves. set zip equals 021-- nope,that's her current zip. 90210. the only other zip codei know in the world. so that would changeher zip code-- actually, that would not change her zip code. >> what did i just do? even though the syntax is probably new.

david malan: yeah, i moved everyoneto beverly hills, california. so i should actuallysay where id equals 2. and so forth. so sql is all about thesekinds of instructions. select, insert, delete, update,with these predicates at the end these where clauses, so to speak. and there's a lot more you cando, but it really just boils down to simply, if arcanely, expressingwhat you want the database to do. >> and then the databasewill figure out, when

you insert lauren scully into thedatabase, where to put her in memory so that we can very quickly gether based on her email address or based on her id number or the like. yeah, dan. david malan: really good question. will these scripts change frommicrosoft access to oracle to mysql to postgresql? the short answer is it depends. in theory, there is a verysignificant common subset of sql

that's shared across allof these implementations. however, various manufacturershave added features to their databases to do certain thingsbeyond the scope of these features, that might, in fact, break. >> so the way developershedge against this, is that rather than writing rawsql code like i'm writing here, they instead use a library,a common library that itself is sort of higher-level and abstractsaway which product you're using. and it gives youfunctions and procedures

to call so that you neveractually write raw sql. >> in theory, then, you can changeproducts from oracle to microsoft or vice versa or anythingelse, and you literally change nothing about your code. the reality, though, is, you sometimesgive up features as a result. you might have chosen a product becauseit's got these value-added features, and you're just now notusing them consciously. >> and anecdotally, most companies tendnever to move away from their database. so while this is a nice tohave feature, the reality

is, if you're overhaulingyour database, you're probably making bunches of other changesanyway, that you don't necessarily need to anticipate that. so it's arguablyover-engineering the problem, but it really depends on the context. but in theory, sql is sharedacross these various products. really good questions. >> david malan: yeah, soyou can think a database is just a server, at the end ofthe day, and inside of that server

is a whole bunch oftables, rows and columns. and when you send a query like thisfrom your program, your website, written in java, ruby, python, whatever,the server is receiving this command and interpreting it inliterally the same way we discussed earlier withinterpreted languages, and then performing some action on zeroor more rows in zero or more tables. >> david malan: exactly, exactly. so the pseudocode for somethinglike that might be this. in your php file or yourpython file or your java file,

you would have pseudocode code, orscratch-like blocks as, if user visits acme.com/register for first time,then insert into users and so forth. and we would translate this tomore concrete code in the end. but really, we have allthe building blocks here, even though we're skipping someof the implementation steps. >> so let me find fault with what wewonderfully did just a moment ago. you have created a prettycomplete table for users. admittedly, we could implementit in a few different ways, but you have actually led usdown the path-- and i say you,

but it's probably my fault-- of a fairlyinefficient database implementation. it's not normalized. >> and by normalized i meanthere is going to be, over time, a significant redundancy,and therefore inefficiency, that is waste of space. based on only what you see here, canyou envision where this waste of space is going to come from, over time,as more and more users register for your website? what data might become redundant?

>> david malan: why do you mean that? david malan: yeah. and let's assume for the purposesof today that that is true. turns out, and we've learned thisthe hard way, that is not true. somehow multiple cities have,somehow, the same zip code, which breaks this wonderful intuition. but let's suppose that's true,because it's almost always true. so suppose that a zip code isalways associated with the same city and state, which is kindof reasonable assumption,

but incorrect, it turns out. but a reasonable assumptionfor today's purposes. >> then suppose that i live in cambridge,ma, according to this user's table, and suppose that laurenscully lives in cambridge, ma, and suppose that kareemlives in cambridge, ma, and arwa lives in cambridge,ma, all of us in 02138. why are we remembering cambridge,ma, 02138 for all four of us? what should suffice to remember? david malan: just the zip code.

just that 02138 exists, becauseyou know what we could do? we could get a little fancy hereand over here, define another table where this is going to be thename, this is going to be the type, this is going to be thelength, and henceforth, i'm going to call this my cities table. this was called, ofcourse, my users table. and so what should i put over herefor my cities table, do you think? >> david malan: yeah. so zip and state and city.

and so the type here, we'll saythis is going to be a char 5 again, subject to the debate of earlier. this will be an enum, perhaps likebefore, and city will be a varchar 50. and so now what do i getto erase from this table to eliminate that inefficiency? david malan: nice. state and city go away, so i've noweliminated the potential inefficiency for redundantly remembering, cambridge,ma, cambridge, ma, cambridge, ma, cambridge, ma, which, hopefullyis never going to change.

and even if it does, it'sminorly annoying, now that i have to changeit in multiple rows, whereas here, i could justchange it in one place. >> now what's the trade-off, perhaps? this was super convenient. had all my data nicely together. but what's clearly the case now? david malan: exactly, and i'mglad you used the word join, because that's actually the keyword,in the world of relational databases

in sql, it's an actual word youmight type or at least convey. and in fact, what we now have to doto select david's full information is something like select star fromusers, join cities, on-- and now i'm going to just move to a second lineso that this fits-- users.zip equals cities.zip, where users.id equals 1. >> so what's going on? it's ugly looking, but you can kind ofread it left to right, top to bottom. select star from usersis the same as before, but it's not from users, per se.

it's from users join cities. what am i joining those two tables on? well, apparently, theusers tables zip field, and this period is just specialsyntax to express that idea, and this is the cities tables zip field. i want those two to be equal,but i want to ultimately select only those rows whereid in the users table equals 1, which happened to be mine. >> and just to be clear, aprogrammer, typically when

hardcode something like the number1, because otherwise the website only supports david or thevery first user, you would instead dosomething like id, where this represents avariable, something that can change over time, similarin spirit to what i said earlier with these kinds of placeholders. but for now we'll just hardcode it as 1. and so what does this mean? well, a nice way to visualize this isthat if this hand is the users table,

and this hand is the zipstable, we're sort of finding-- and the tips of my fingers are zipover here, and the tips of my fingers here are zip, you'rekind of interlocking it so that you get back the resultingoriginal table, by truly joining the two tables on the common field. and it doesn't have to be zip. it could be most anything else, butzip is nice, because one, it's short, two, it's always thesame length, so there's a real efficiency to whatolivier proposed here

with factoring out the zip, and[inaudible] proposing that we get rid of city and states. >> so this is the processknown as normalization. any questions on that? well let me point outthis is the kind of stuff, even though it's fairly low-level,this discussion, that you would think you're sort of gettinglost in the weeds, this is a manifestation of ampleopportunity for developers to be bad. and in fact, even when we, incourses i've taught, when we've had,

for instance, inexperiencedundergraduate programmers build websites, at first glance,the websites might look terrific. and they have all of thefunctionality we requested, the developers did a good job. >> but they didn't necessarily knowenough about database design or they didn't think hardenough about the types of data and the types of users thewebsite was going to have, and we find, then, six months later,after they've graduated or moved on, that damn it, our websiteis really, genuinely slow.

and i'm not even talking about havingmillions or thousands of users. i mean a few hundred users on campus,all of whom like to, for instance, shop for courses atthe same time, they're using that course catalogapplication i mentioned and the thing is getting reallyslow because there were no indexes. there were no red stars, so tospeak, or we hadn't necessarily factored out common data toget some savings of space. >> and so when vetting a developeror database person or the like, the kinds of questions to think throughis even, when reviewing someone's code,

to say, not necessarily lookthrough all of their code, but say, let's look through the database tables. what are you storing? and then to say, well, wait aminute, why are you using an integer? what if we have 4 billionand 1 of these rows? and these kinds ofquestions is an opportunity to kind of push back andget a sense of, where if you're not comfortable doingit, having someone more technical ask these questions, of whether or notthe person really knows their stuff.

and this is the kind ofstuff, too, that people on the internet whoare self-taught, maybe learn less frequently, because youdon't necessarily come across it as much, because you can getthe database up and running, but unless you've readup on tutorials or been told about database normalizationand indexing and performance, these are the kinds of thingsthat are going to hurt you. and you might think, or a bad engineermight say, oh, well, we better pay for a bigger databaseor a faster database

or just throw money at this,vertically scale, not necessarily so. if you go in-- and you can go inafter the fact-- and add indexes, and it might take a few hours for thedatabase to build up that new data structure that i alluded to earlier,you can still fix this after the fact, that this is where youstart to distinguish good designers from baddesigners, not just aesthetically, but performance-wise as well. any questions? no?

so for nosql, which was the other typeof database to which i alluded earlier, you don't have rows and columns. instead, you would have somethingthat looks a little more like this. i'm going to use common syntax. curly braces happen tobe used here quite a lot. you might have somethinglike first name is david, you might have lastname is malan, quotes, you might have id is--excuse me, whoops-- id is 1, email is malan@harvard.edu, and i won'tbother typing out the rest, and then

some other things. >> in other words, this isa textual representation of what we would generally callan object in a computer program. and an object is generally justa collection of key value pairs. so again, this recurring theme. we saw key value pairs in html,we saw key value pairs now in the context of databases, and wesaw key value pairs in the context of, i think, a language earlier today. keeps coming up.

and indeed, that's reallywhat data boils down to, data and metadata, or valuesand keys, respectively. >> so a non-relationaldatabase, something based on objects, where you just clumpeverything together and put it into memory, would generally bepictured as, or thought of, as this. and i'll leave that now as asort of alternative approach. and one isn't necessarilybetter than the other. in fact, very much in voguethese days are database systems like mongodb and redis and a fewother such tools, freely available,

but they are increasingly en vogue. partly because they offer additionalfeatures over these tabular approaches, but also because they'rea little easier to use, because you don't have to think as hardabout a lot of these design decisions. so pluses and minuses. so realize there are optionsbeyond what we just spent time on. >> so let's do this. let's transition a littleback now to web programming, so that we kind of concludetoday with something

that's a little hands-on, fillingin some gaps from yesterday. let me go to this first. so recall that yesterdaywe had some canonical html pages that had initially, onlyhtml, and then secondarily had css, cascading style sheets. this is a new tag that we didn'tsee yesterday, or dwell on, so-called script tag. >> turns out you can actually embed alanguage called javascript in your web page and make your webpages do something.

so what do i mean by that? well, let me go ahead and justborrow this code for a moment. i'm going to go into cloud9, no needto go there yourselves just yet, and i'm going to call this alert.html. i'm going to paste in my file here. and just to clarify what i've done, letme go to this address and go to alert, and you see the hello world. >> but this is kind of underwhelming. i want to do somethinga little different.

so i'm going to actually do this. i'm going to go in here e,and in between my script tags, say alert('hello,world'); so noticeit's a little sloppy, but i've got html, inside of which is alanguage called javascript, and this is what's called afunction call or procedure call. this is a verb, literally, in this case,and i am invoking code functionality that someone else wrote. >> so that functionality is analert, so let's go to this page now and click reload, and now yousee a little bit of interactivity.

it's kind of old school and ugly. this kind of reminds you of thepop-ups, perhaps, of yesteryear but it did do something alittle more programmatic. >> so more than that, let's dosomething more interesting. let me go in here and get rid of this. and i'm going to go ahead andcreate a form like we did yesterday. actually, you know what? i'm going to go intogoogle.html, which we started on yesterday, which looked likethis, via which we searched for cat

but notice there's kind of abug in the current version. it works for cats, but suppose thati don't cooperate and i type nothing, and i simply click submit. that's kind of weird behavior. took me to the real google,didn't give me an error message. i'd like to tell the useryou need to give us a value. >> so how might we do this? well let me go back into cloud9 andlet me go into the top of my page and add a script tag like this, wherei'm going to type some javascript code.

and i'm going to do the following. if(document.getelementbyid-- and recallthat we talked about that earlier, that function. what id do i want to get? i want to get q, and i'm going tosay equals nothing, like this-- actually let me use double quotesjust for consistency-- equals nothing, then alert("please type a query") here. >> so i have what appears to besomething like a condition. we've seen this general idea in scratch.

it's like one of those puzzlepieces that looked like this. and what am i saying? well, down here, notice i'mgoing to do the following. i'm going to give this formfield not only a name of q, which is what gets passed to google, but i'mgoing to give it a local identifier, also called q. but i could call this anything iwant, i'm just going to keep it simple and also call it q, just for simplicity. >> and now i'm going to dosomething a little more.

on the form fields here, i'm going toadd what's called an event handler. on submit, i want to calla function called validate. this does not exist yet, thisword, or this verb validate, because what i'm going to doup here now is add some code. >> i'm going to say function validate. i'm going to indent this and add anothercurly brace here and another one here. consider what this is now doing. i have now-- think of this as created myown puzzle piece that didn't previously exist, and i've called this puzzlepiece the validate puzzle piece.

its purpose in life is to executethe four lines of code inside of it. >> if document.getelementbyidso conceptually, that is going to go into the element,the html element whose unique idea is just q, and then even thoughthe syntax looks a little weird, that equal equals just means equals. so that means if the element with theunique identifier of q, when gotten, has no value, it just equalsquote unquote, nothing in there, then what do i want to do? i want to yell at the user.

>> and we won't go great detail here. i'm going to return false. that is an error. else, i'm going to return true. so either it worked or it didn't. false or true. and now if i didn't make any mistakes,let me save this and reload this. and let me just double check thati didn't, in fact, make any typos, so i don't embarrass myself.

let's see if this works. >> so now i'm going to type cats. it still works, or half works, at least. now let me reload it, and now letme try submitting without typing anything-- damn it, it broke. one moment. let me open the console,[inaudible] log, reload the page. let me try this again. oh, damn it.

i forgot. i made a typo. i remember what it is. .value. i meant to say if the valueof the element whose id is q equals that, then yell at the user. >> so now let me hold my breath again. here we go. there we go.

please type a query. so it's not letting me through. i can be kind of playful with this,and instead of checking for no value, i can say something like,no more searching for cats, and now we can just more playfully letthe user search for dogs if he or she wants, or if i go in here andsearch for cats, now i can't. >> so what's the takeaway here? so one, we've introduced intoour world of html and css, programming functionality.

i can actually nowmake decisions in code. previously, all i could do is mark uptextual content or graphical content and tell it what to looklike and where to display. now i can actually askquestions of the web page and make decisions basedon it, and prompt the user if i need to yell at him or her. >> so let's try somethingon our own with this. go ahead, let me open up the next slidehere, and just point out one thing. just like with css, we can factor outour javascript code to a separate file,

you can do the same thingwith javascript as with css. and you use that using a sourceattribute of the script tag. but we won't complicate things for now. instead, if you couldgo to not this page, but-- let me move this around in order--go to, if you could, this page here. this url here. it's in today's slides. you might have to reload becausei've added a couple of thing. >> but go there where some puzzles await.

and this will give us a chance,in a slightly more fun context, to dabble with some javascript. and when you get there,i'll explain what awaits. get green. set blue. sets green, sets red. oops. sorry. >> this is the extent of ourdocumentation for this challenge.

and this is going to work as follows. so what you have on thispage is a whole bunch of image puzzles by a buddyat stanford university. so what you're seeing here is almostkind of one of those magic eye puzzles, but if you just stare at it,nothing's going to pop out at you. rather, something ishidden in this image. and it's hidden in the following way. images, as you may know, can becomposed of just three colors. some red, some blue, and some green.

and we can make all thecolors in the rainbow by mixing those three colors somehow. >> so this looks mostly green andblue, but as nick says here, this iron puzzle image is a puzzle. it contains an image ofsomething famous, however, the image has been distorted. the famous object is in the red values. however, the red valueshave all been divided by 10. so they are too small by a factor of 10.

so in other words, nicktook an original image, and he desaturated allof the red from it, lowering the amount of redink, if you will, in it. >> the blue and green valuesare all just meaningless, random values, aka noise designedto obscure the real image. so what nick did was hetoned down the red and then he just threw randomamounts of blue and green at the image to kind of obscurewhat's actually still there. you must undo these distortionsto reveal the image.

first, set all the blue and green valuesto zero to get them out of the way, and look at the result. thenmultiply each red value by 10, scaling back up toapproximately its final value. what is the famous object? >> so all of you have this rectanglein your browser right now. and notice that there is somestarter code, so to speak. this is javascript code thatnick has written for you. and notice that there'sa line in the middle that starts with a slash slash, that'swhat's generally called a comment.

it means it's a phrase to the programmerthat has no functional meaning. it's just a visual cue to the human. >> so you can go ahead anddelete just that line, and be super careful not todelete or change anything else. and let me just walk you throughwhat this code does and i'll leave it to you to figure out the secret image. this first line here that i've justhighlighted gives you the following. on the left hand side,you have what's called a variable that nick has arbitrarily,but reasonably called im for image.

on the right hand sideof that equal sign, he's saying give me a newquote, unquote "simple image". >> simple image, in this contextis what's called a class, well, it's kind of like a class--technically a prototype-- but really, this is giving me a new object,the contents of which are the file, iron-puzzle.png. in other words, nick has createdthis notion of a simple image so that we can, for pedagogicalpurposes, play with the image and change its red,green, and blue values.

>> and how are we doing that? this somewhat cryptic syntax hereis kind of like the repeat block that some of you saw in scratch earliertoday, where you can repeat 10 times. in this case, nick has nothardcoded a number like 10. instead he is saying, initializea variable called x to 0, check if x is less thanthe width of the image. >> and so to be more proper, image is thevariable, dot means go inside of it and get its width, andthen open paren, closed paren is just a programmer's wayof saying this is a function.

this is a procedure. this is functionalitysomeone else wrote. use it and give me back an answer. and then x++ is a fancy way ofsaying, after you've done this once, increment x by 1. in other words, thisis a programmer's way of inducing a loop that'sgoing to iterate over all of the columns in an image. >> an image is just a grid ofdots, rows and columns of dots.

this is a way of iteratingover all of those columns. and on the inside,meanwhile, we're iterating over the heights, hereand here and here. so this is just a way of traipsing,almost like an old school typewriter, to just go over thewhole image iteratively. even that's not quite whollyclear, just take on faith for now, that those three linesof code together are going to allow you to iteratively lookat every pixel, every dot in the image. >> what's a pixel?

well, to be clear, if we lookat the original and zoom in, if you really put your eyesto the computer screen, that's just a whole bunch of dots, severalthousand dots packed together there. and so what are you about to do? each one of those dots,a final definition, is the result of what's generallycalled rgb, red, green, blue, which again, can be combined togive you any number of colors. >> in fact, if you rememberfrom many, many years ago, projector screens like these thingsused to have not one lens but three.

one of them spit out red light, one ofthem spit out green light, one of them spit out blue light. and if you were in a middle schoollike i was where they were never properly aligned, you werealways watching history movies that were slightly distorted,because the three colors were not combining properly. >> but it turns out that each ofthese values red, green, and blue, can have a number associated with them. for instance, 0 for red means nored, 0 for green means no green,

and 0 for blue means no blue. so if you have no red, no green,and no blue, what color do you have? david malan: you wouldhope so, it's white. unfortunately, this operates-- sorry? david malan: so you actuallyhave black, in this case. so if you have none of thesecolors turned on, you have black. however, if you have, let's say a lotof them, like a lot of red, 255 of it, a lot of green, and a lotof blue, that is white. so these are the two extremes.

so by this logic, if i have a lotof red and no green and no blue, what color is that? david malan: right, obviously. and then no red, lot ofgreen, no blue, and then if you have-- well, we'll just finishit, just because, but this, of course, now, is blue. and now you can combine these colors. now as an aside, if any of you haveever done some actual website design, you might actuallysee symbols like this.

fff-- and actually, it'sprobably not even that. it's ffffff. >> anyone ever seen f's and e'sand a through-- so it turns out, we talked yesterday about decimal,and today, kind of about decimal. today we talked about binary. turns out, hexadecimal is a verycommon base system to use in computing. binary is two, decimal is 10, hex is 16. and it turns out, how doyou count in hexadecimal? zero, one, two, three, four,five, six, seven, eight,

nine, what do you use after nine? what's the next number? we already used zero. i need 16 of these. zero, one, two, three, four,five, six, seven, eight, nine, you need some arbitrary convention. >> and what mankind decided some timeago that after nine comes the letter a and then b and then c. so theway you count in hexadecimal is zero, one, two, three, four,five, six, seven, eight, nine,

a, b, c, d, e, f, and that will countyou all the way, it turns out, to 15. so zero to 15 is zero throughf. now why is that significant? well, when you have two f's,that's how you express 255. >> so long story short, inthe world of photoshop, that graphic design software,in the world of web development, where you have lots of colors,of course, to play with, often programmers willexpress those in hexadecimal, just because it tendsto be a little simpler. even though at first glanceit's much more complex.

>> so in any case, this is importantbecause nick at stanford has given us six pieces of functionalitythat you, the budding programmers, will now have the ability to use. built into this webpage is six functions, six procedures that nick wrote. three of them will get you a number,a red, a green, or a blue value. three of them will set that value. and these underscoresare just placeholders, so you need to know what those are.

>> so with these three functions,the first of these things is going to be an x-coordinate,and the second of these things is going to be a y-coordinate. in other words, which dot, whichpixel do you want to get the green of, get the blue of, get the red of. and then here, this is going to bex, this is going to be a y value, and this is going to be a number. so let's do the firstline of this together and then i'll leave it to youto try to deduce the rest.

so per the instructionson this page, we need to increase the red by a factor of10, and we need to remove the green and remove the blue. let's start with the latter scenarios. so if i want to, and i'm goingto indent by using some spaces, if i want to set the red,the green, or the blue value, i'm going to do the following. >> image, im.setblue, and thenbased on my instructions here, what three things should itype inside of parentheses now?

i need the x value, they value, and what number should i put here if i want to get ridof the blue, based on this story here? just zero. if i want no blue, i'm justgoing to change it to zero. >> now let's just recap what this is doing. i have here on these topsecond and third lines, i claimed two loops,nested loops, if you will, that are going to have the effectof progressing from left to right, top to bottom over all of the xvalues and all of the y values.

because again, a picture isjust a grid of rows and columns. so this is going to getrid of all the blue. let me leave in the next line to you. how do i get rid of all the green? >> david malan: nice. and i'm going to zoom out, and just takecare of that you've not done any typos. and if you're comfortablewith what you've done, go ahead and click the buttonrun/save and see what you get. and again, we've madejust three changes.

we deleted that firstcomment and replaced it with these two lines of code. and it's ok if you need to hitthe run/save button a couple times to fix something. >> and let me also zoom in on mycode so you can transcribe. good. so i see andrew has whatseems to be a mistake. he's just got a big blackrectangle on his screen. does anyone else havea big black rectangle?

>> audience: yes. >> david malan: big black rectangle? ok, so let's thinkabout what this means. we said that zero, zero, zero,so no green, no red, no blue, is going to give you black. and it turns out thatmost of our laptops just don't have enough fidelity. you can't quite tell thereis actually something there. and if you kind of maybe leanyour screen forward and back,

maybe do you see alittle something there? maybe, kind of, sort of? it's not perfectly black. >> david malan: spoiler! there is some red there, butremember from the specifications of the problem, nick toned it down. he desaturated it somewhat,but not all the way to zero. so if we want to magnify the amountof red, let me propose this trick. let me zoom in on my screen.

and let me go ahead and sayamount equals im.getred(x, y). >> this line of code is giving mesomething called a variable. i have arbitrarily, but, arguably,reasonably called my variable what, apparently? amount. just amount. i could've called itanything i want, but i'm using this other functionthat i described earlier to get the amount of red at x comma y.

why did i do that? what do you want to do here? you need to add-- david malan: yes, maybemultiply it by 10. and if you don't know this, i'mgoing to go ahead and do this. i'm going to go ahead andsay, i want the amount of red i want to be whateveris at the red, times 10, and the star, the asterisk on yourkeyboard is the-- don't use x. use the star.

that's how you multiply thingsin most programming languages. >> so according to kareem's intuition,stored in this variable called amount, is how much red i want at location xy. how, now, do i make thatpixel have that number? you've already done this before. you set the green and theblue to no value, to zero. david malan: yes, wellyou don't want it to 10. you already did the math here. so we are getting the value of red,which is a low number, presumably.

we're multiplying up by 10. what you want to do withthe variable amount now? so im.set-- what? >> audience: setred. >> david malan: setred, at location xy. and just amount. in other words, a variableis a temporary placeholder that you can put anything you want in. we happen to be putting anumber in it, at the moment.

we've multiplied it by10 to make it bigger. and now i'm substituting that variableas that third argument, or input to set red. and so that once youfinish that, and take note of the semi-colons and the parentheses. >> go ahead and clickrun/save again, and you should see, magically, what was actuallythere. [? arwa, ?] what's there? the eiffel tower in full-fledgedred, not quite dark. it should be more obvious now, yes?

ok. and andrew, no more black box? david malan: all right. so i'll keep this on the screen. if you want to play with thislater, i'll recreate this for you. but this code here did exactly that. why don't we do one other. let me scroll down slightly. >> so in this case, the projectordoesn't really do it justice.

but on your screens, you probablyhave a very red and very black box. this, too, is a puzzle thatshows something famous. however, the image has been distorted. the true image, this time, isin the blue and green values. however, they've all been dividedby 20 so the values are very small. the red values are justrandom numbers, noise. undo these distortionsto reveal the true image. >> so nick then tells you what to do. set the red values to zero, andthen don't spoil what it is.

then multiply the blueand green values by 20. so it's almost thesame program as before, but you're reversing the process. and i will put my code frombefore on the screen in case you want to refer back to itor play further with that one. let me zoom in on that. but solve copper imagepuzzle, number two. >> david malan: ok, so this one i'mnot going to give as many hints. so i would-- oh, let'ssee, you have a typo here.

so remember, this hereactually needs to go there. so what i would propose, if you want tofocus on this one, there's the answer. if you want to transcribe that, thatshould get the first one working. and then you can use that asinspiration for the second one. nice. >> and for the curious,this is a simple example of a science or an artcalled steganography, the art of hiding information in images. typically, images might bewatermarked very blatantly

with a logo in the bottomcorner, but clearly, you can be much more sophisticatedabout it and actually hide other images in the imagessomehow with this technique. >> take another 30 seconds, and then we'llat least announce what you should see. and i'll leave the thirdone as an at-home exercise, if you'd like more of achallenge this weekend. and i think andrew mighthave gotten it first. what is the second image, andrew? >> audience: statue of liberty.

>> david malan: statue of libertywill be the answer this time. so again, just some simpleexamples, the goal of which is to give you a sense of howwe've translated pictorial scratch blocks to more annoying and morecomplicated code, but all of the ideas are still exactly the same,albeit with the introduction now of the notion of a variable, beingable to store something temporarily. >> let's do one more hands-on,just to now connect the dots to something a little more real-world. when you're ready, if you couldgo to this url on the screen.

that's also in your copy of theslides, developers.google.com/maps. let's actually do somethingreal, so to speak, on the web using the google maps api, orapplication programming interface, in the following way. >> google, like many companies,provides a lot of free functionality that you can use to build yourown interesting applications. in fact, if you've ever useduber to get a cab or a car, you probably know that uber hasa map and it shows cars on it. that is, as best as i cantell, google maps api.

they are actually using google's maps,but uber is not a mapping company, nor would that be aparticularly interesting problem to solve on top of theircar service problem. and so they're standing,again, on the shoulders of others, google in this case. so they use google's maps but their owncar services and other such features. >> so we're going to take advantageof this to do the following. and if i've gone too fast,just call me over in a moment. happy to recap some of the image stuff.

you should see yourselfat a page like this. so google's nice, andthey're among the best of providing not only apis,but free apis that you can play with or use commercially. they do start charging you if your usageis high, but i went ahead in advance and signed us up for a free accountthat, hopefully, 10 computers won't disqualify us for suddenly. so hopefully thisdemonstration will work. >> and notice that they have apis forandroid, ios, web, and web services,

whatever that is. let's focus on web. so click the pink box, web, and thatwill lead you, hopefully, to a page here. and they've got a whole bunch of apis. and it can be a littleoverwhelming at first, but i'll steer us through what we want. >> at the top left is the google mapsjavascript api, the javascript api. so go ahead and click that one.

and that will lead you now to thefollowing page, demos and sample code. let me zoom out here. and let me get us to-- scroll downto where it says quick start steps. your screen should look like mine. >> and there's two steps, geta key and start developing. i already did step one forus, getting a so-called key. and this is a common idea. an api key is generally justa big random number or string that you are supposedto paste into your code,

so that google knows who you are whenyou're using their service, their api. doesn't mean we'rebeing charged anything. and now, click, instead ofone, click start developing. if you could just wave meover if not sure where we are. >> so we'll just scratch thesurface, here but what i thought would be compellingis to actually have all of us, using cloud9 in one window andthis tutorial in another window, lets actually get our ownapplication up and running that embeds a custom googlemap in our own webpage,

and then adds one or two features. but we'll just scratch thesurface of what we can do. >> so just a quick sanity check. is everyone at this page,google maps javascript api? should say getting started. we're not going to go throughthe whole thing by any means. ok, in another tab, if you don'thave it open, do go into cloud9 and get yourself to justa new tab, ultimately. so again, c9.io from yesterday,c9.io, and just create a new file.

and go ahead and callit whatever you'd like. i called mine map.html. call it anything ending in .html. and you should be roughlywhere i am in this process with just a blinking prompt in an emptytab called something like map.html. or file, new file this time. >> and now, over on thegoogle maps javascript api, we'll skip readingthrough all of this text. but notice that hello world isindeed everywhere, you see it now.

hello world has this big colorfulexample of a whole bunch of html. go ahead and copy and paste only thathtml, so from the doc type at the top all the way to the close html tag, goahead and copy all of that-- again, that's under the hello world example--and paste that into your cloud9 tab, so that now your screenshould look roughly like mine. >> and you can save it, butdon't load it just yet. let's first look atthe code and see if we can't infer or learnfrom what it is google has had us blindly copy and paste.

they just want to help,literally, get us started, but there's not that muchcomplexity actually there. any questions just yet? we're safe to forge ahead? >> so quickly, let's just dosome quick sanity checks. line one of what isee, and hopefully, you see, what does that mean, doctype html? kareem, recall? david malan: yes.

here comes html 5. meanwhile, line two on thescreen here means hey browser, here comes the actual html. line three is hey browser,here comes the head. line four is, of course, heybrowser, here comes the title. what does line five do? actually, this doesn'treally do anything for us. in this case, it just resizesthe page to a default. line six, we have not talked about, but itspecifies the character encoding.

there's different ways to encode files,especially for foreign languages. utf-8 just tends to be the default. >> so now we'll see in lineseven through 16, some css. and even though we've not seenall of these things before, we can kind of infer. so line eight means, hey browser, applyall of the following to which two tags, the html and body text. so the comma is the new thing there. and that's just a way ofspecifying multiple tags at once.

>> then we've got the curly braces. so apparently, this tells the browser,make the height of the page 100%. so even if there's very littlecontent, make the whole page, make the thing fill the page. make the map ultimately fill the page. margin, what does that mean? that's usually like arbitrarywhite space around the edges that some browser designer justdecided should be there, because it kind of makes things look cleaner.

but we don't want that. we want the map goingall the way to the edges. padding, similar in spirit to margins. margins mean outside, padding meansinside, but it's the same kind of deal. it's a little bit of a bufferbetween you and the edges. >> and then line 13 is a goodchance for a quick review. what does sharp sign mapmean, or hashtag map mean? what does that refer to, in principle? david malan: exactly.

this property, this css propertyapplies to just one thing, the html tag that has an id of quote, unquote "map". and now let's fast forward, scrolldown to the bottom of the file, which isn't too far away, and notice on line19, if you paste it exactly like i did, line 19 has just a div, which is adivision of the page, which yesterday i called a rectangular region. it's got nothing in it. it's an open tag, close tag. but it does have a unique id.

>> so what seems to behappening here is google is readying our web page tohave a complete 100% height, and no padding, no margins, becausewhat we're going to put inside of this div, whose unique id ismap, is an actual embedded map. and we want it to fillthe page and not just be some small rectangle in the middle. so line 14 similarly emphasizes, themap itself should have a height of 100%. >> so now notice between lines 20and 28, this is javascript code. and this is, even though it'ssyntactically a little strange,

there's not all that much going on here. in line 21, this is declaringsomething called a variable. instead of calling itamounts, like we did before, we're more precisely sayingvar, which just means variable. we could have used that innick's code, but he didn't, so i didn't bother doing it either. it's a variable calledmap, and then there's a function that'sapparently called initmap. >> so this is like our own custompuzzle piece in scratch.

we've created a piece offunctionality called initmap, and you can kind of inferwhat's going on here. on the left hand side,we've got a variable, so we're going to put the followingthing inside that variable, from right to left. the right hand side says, heybrowser, give me a new google map. and google.maps.map is just a funky wayof specifying that this functionality belongs to google maps. >> after the parentheses, we've seenthis before, hey browser, get

me the elements in the page, thetag in the page whose unique id is-- >> david malan: --map. and what is going on, well,this line together, line 23, is essentially saying,hey browser, go get me that empty div on the pagewhose unique id is map, because i want to insertinto it-- inject into it, if you will-- a whole bunch of contentthat happens to be coming from the web, subsequently. and google's doing all of that for us.

>> so again, at the very end of the day,we have this example of abstraction. i have no idea what a map isor how to implement a map api. we don't need to. we just need to tell the mapwhere to put itself, and leave those underlying implementationdetails to google. now there is apparentlytwo pieces of data that this example isproviding to google's api. apparently the center of the map,and the zoom level, so to speak. >> and does anyone recognize thesecoordinates, latitude and longitude?

probably not, but we can go backto the tutorial, literally see. but we'll see it in just a moment. zoom level is a value between, i don'tknow, one in 13 or something like that. it just has to do with how far you'rezoomed in or out, and that's it. and now at the very end ofthe page, notice line 29-- it's a little ugly becauseit wraps-- this line of code is what downloads to thebrowser google's actual api. all of the code that google'sengineers have written that implement this whole feature of embeddable maps.

>> now let's not change anything. if you're following along, go ahead andjust save that file, if you indeed have what i have. go to its url. you can click the run buttonup top and that will tell you the url of your web server again. and it will lead you to a new tab. if you click open formap.html, and odds are you're going to get an alert,an error message, yes?

error message, error message? >> so unfortunately, the errormessage is not that enlightening unless you actually open theconsole, that special tab we kept opening yesterday anda little bit earlier today. but i stumbled acrossthis earlier, so i already figured out what the solution is. in today's slides, orrather, in cloud9, notice that we didn't dosomething deliberately. notice that this script tag inline 29, if you read through it,

it's like maps.googleapis.com/something, something, something, then notice someone,one of the developers, wrote in all capitalletters, your api key. >> we need to paste something in there. and this was the stepi did for us before, and again they might blacklistus if suddenly, 12 or more of us start using the same key,but let's see what happens. so if you go into today'sslides, one slide later, there's this very funky-looking string of text.

go ahead and just copy that andpaste it where it says your api key. that's the one i signed up for. >> and definitely don't trytyping it out manually, because it feels fraughtwith typos, potentially. so just copy and paste that. and it's going to make the linelonger, but now, just to be clear, it should look a little morelike this, where key equals not capitalized yelling at you. save your page, go backto the other tab, reload,

and hope to see a map of where? >> audience: australia. >> david malan: australia. so apparently those are thegps coordinates of australia. and let me walk around for just a momentand help anyone who's not quite there, but let me propose, via google, findthe gps coordinates of your own hometown or your own home country. and probably google can turn thisup, or wikipedia can tell you. but choose two different valuesfor latitude and longitude,

go back in and paste them, andthen reload the page after saving and see if you can have amap for your own hometown. >> and when you're done withthat, the follow-up challenge-- and i'll give a little less direction,deliberately, so that you deliberately have to struggle for a coupleminutes with the documentation, change the map to be not thiscartoonish default, but a satellite map. so you actually see satelliteimagery instead of the pretty colors. >> and the hint i'll give youis change the map's type. go back to that gettingstarted page for inspiration.

as you may have gleaned,if you're looking, there are so many morethings you can do. some of you have alreadychanged the map type. but you can do-- for instance, let mego to something we did for the course i teach-- maps.cs50.net. one of our undergrads did this. we center our map over harvard yard andoverlay all of these building names, and we had him add this. so if i want to search for,for instance, matthews hall,

we have a little drop-down menu. and i think he's using bootstrap, thelibrary we discussed earlier for this. and if you click on matthewshall, it immediately jumps the map to a certainlocation, and it shows you a picture in this little pop-up. >> but even this littlepop-up, we didn't implement. if i scroll down on our gettingstarted page and look for info windows, you'll see that some of thefunctionality you yourself can add, albeit witha bit more complexity,

is something called an info window. and if i click an examplehere, and this is what's fun, you can do things like this,clicking on a marker and then voila, information pops up. >> so we haven't quite introducedenough features of javascript to paint a picture of exactly how youcould wire all of this stuff together, but we've kind of scratched the surface. in fact, what i just did wheni clicked on that marker, was triggering an event, aso-called on click event.

and we actually saw anevent earlier today, the so-called submit event,when we were preventing the user from searching for cats. so we've kind of picked and choosedfrom among all these various features, to give you a sense, hopefully,of what you can actually do with a bit morecomfort in programming, and completely free resources. >> any questions? this is your final chance,at least today, on a friday,

to get anything off your chestso that you walk out of here feeling confident and comfortable. yes. >> audience: why don'tyou add one more thing? >> david malan: oh my goodness. i need to rest this weekend, i think. other questions? >> david malan: you can-- ininternet explorer, rest in peace, you used to be able to put vbscript, virtual basic script,

but that really never caught on. so the short answer is just javascript. all right, well, let me do this. let me grab our colleagues outside. they have some evaluationforms that they want everyone to spend a few minutes filling out. they want to collect that form and anywaivers that you might have outside. they'll also have certificates. i'm guessing there'sstill some snacks outside.

let me pass these out, and if youhave any questions in the meantime, i'll walk around more individuallyand we can get you started. yes, of course. david malan: that'susually true these days. certainly with websoftware, you are leaning on others you're eitheraesthetically using things like bootstrap, so you don'thave to implement the low level details of menus andbuttons and all that. you're leaning on someonelike google so that you

don't have to build an uberbusiness and a mapping business, and any number of similarapplications as well. >> in fact, logins are popular, too. if you've used spotify orany number of websites, you'll log in to somewebsites using facebook. so what's nice, thereare apis for logins nowadays, so that you don't haveto have your own users table and all of your own databasenecessarily to the same extent. you can let facebook do allof that complexity for you.

so it's an exciting time,honestly, in programming, because there are so many third partyservices that you can build on top of. >> and again, the price you pay iseither financial or downtime. if google goes down,so does uber, arguably, but perhaps that's areasonable trade-off. and again, that was one of the themes,hopefully, for the past couple of days, is these trade-offs. and rarely is there goingto be a right answer. it really is the betterof two or more answers.

>> pass these around. >> and these cloud9 accounts will continueto work, in theory, in perpetuity. you might find if you wait a few daysor a week or more to log back into them, it might take like one orfive minutes to open back up, but that's just because they putit to sleep to save on resources.

No comments :

Post a Comment