Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native speaker attacks. #22

Merged
merged 1 commit into from
Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ We hope that we'll be able to make you love technology as much as we do!

When you'll finish the tutorial, you will have a simple, working web application: your own blog. We will show you how to put it online, so others will see your work!

It will (more or less) look like that:
It will (more or less) look like this:

![Figure 0.1](images/application.png)

Ok, let's begin with the very basic thing...
Ok, let's start at the beginning...
10 changes: 5 additions & 5 deletions django/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ You see, when you're building a website, you always need a similiar set of compo

Luckily for you other people long ago noticed that web developers face similar problems when building a new site, so they teamed up and created frameworks (Django is one of them) that give you ready components you can use.

Frameworks exist to save you from having to re-invent the wheel and help alleviate some of the overhead when you’re building a new site.
Frameworks exist to save you from having to reinvent the wheel and help alleviate some of the overhead when you’re building a new site.

## Why do you need a framework?

To understand what Django actually is for, we need a closer look at the servers. First thing is that the server needs to know that you want it to serve you a webpage.
To understand what Django actually is for, we need a closer look at the servers. The first thing is that the server needs to know that you want it to serve you a webpage.

Imagine a mailbox (port) which is monitored for incoming letters (requests). It is done by a web server. The web server also sends a response with a webpage. But when you want to send something, you need to have some content. And Django is something that helps you create the content.
Imagine a mailbox (port) which is monitored for incoming letters (requests). This is done by a web server. The web server reads the letter, and sends a response with a webpage. But when you want to send something, you need to have some content. And Django is something that helps you create the content.

## What happen when someone requests a website from your server?

When a request comes to a web server it's passed to Django which tries to figure out what actually is requested. It takes a webpage address first and tries to figure out what to do. This part is done by Django's urlresolver (Note that a website address is called URL - Uniform Resource Locator, so the name *urlresolver* makes sense). It is not very smart - it takes a list of patterns and tries to match the URL. Django checks patterns from top to the bottom and if something is matched then Django passes the request to the associated function (which is called *view*).
When a request comes to a web server it's passed to Django which tries to figure out what actually is requested. It takes a webpage address first and tries to figure out what to do. This part is done by Django's __urlresolver__ (Note that a website address is called a URL - Uniform Resource Locator, so the name *urlresolver* makes sense). It is not very smart - it takes a list of patterns and tries to match the URL. Django checks patterns from top to the bottom and if something is matched then Django passes the request to the associated function (which is called *view*).

Imagine a postman with a letter. She is walking down the street and checks each house number with the one on the letter. If it matches, they put the letter there. This is how the urlresolver works!

In the *view* function all interesting things are done: we can look at a database to look for some information. Maybe the user asked to change something in the data? Like a letter saying "Please change description of my job." - the *view* can check if you are allowed to do that, then update the job description for you and send back a message: "Done!". Then the *view* generates a response and Django can send it to the user's web browser.

Of course, the description above is a little bit simplified, but you don't need to know all the technical things yet. Knowing a general idea is enough.
Of course, the description above is a little bit simplified, but you don't need to know all the technical things yet. Having a general idea is enough.

So instead of diving too much into details, we will simply start creating something with Django and we will learn all the important parts along the way!

Expand Down
8 changes: 4 additions & 4 deletions how_internet_works/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# How the Internet works?
# How the Internet works

*This chapter is inspired by a talk "How the Internet works" by Jessica McKellar (http://web.mit.edu/jesstess/www/).*

Expand All @@ -15,11 +15,11 @@ a screen, mouse or a keyboard, because their main purpose is to store data and s

Ok, but you want to know how the Internet looks like, right?

We made a picture for you! It looks like this:
We drew you a picture! It looks like this:

![Figure 1.1](images/internet_1.png)

Looks like a mess, right? But in fact it is a network of connected machines (*servers*). Hundreds of thousands of machines! Many, many kilometers of cables around the world! You can visit a Submarine Cable Map website (http://submarinecablemap.com/) to see how complicated the net is. Here is a screenshot from the website:
Looks like a mess, right? In fact it is a network of connected machines (*servers*). Hundreds of thousands of machines! Many, many kilometers of cables around the world! You can visit a Submarine Cable Map website (http://submarinecablemap.com/) to see how complicated the net is. Here is a screenshot from the website:

![Figure 1.2](images/internet_3.png)

Expand All @@ -41,7 +41,7 @@ Instead of address with street name, city, zipcode and country, we use IP addres

When you send a letter it needs to have certain features to be delivered correctly: address, postmark etc.. You also use language that the receiver understands, right? The same is with *data packets* you send in order to see a website: you use a protocol called HTTP (HyperText TransferProtocol).

So basically, when you have a website you need to have a *server* (machine) on which it is. The *server* is waiting for any incoming *requests* (letters that ask you to send your website) and it sends back your website (in another letter).
So basically, when you have a website you need to have a *server* (machine) where it lives. The *server* is waiting for any incoming *requests* (letters that ask you to send your website) and it sends back your website (in another letter).

Since it is a Django tutorial, you will ask what Django does? When you send a response you don't always want to send the same thing to everybody. It is so much better if your letters are personalized especially for the person that has just written to you, right? Django helps you with creating these personalized, interesting letters :).

Expand Down
55 changes: 28 additions & 27 deletions python_introduction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ After running the python command, the prompt changed to `>>>`. For us it means t

## Your first Python command!

Let's start with something really simple. For example, try typing some math, like `2+3` and hit Enter.
Let's start with something really simple. For example, try typing some math, like `2 + 3` and hit Enter.

>>> 2 + 3
5
Expand Down Expand Up @@ -57,24 +57,24 @@ Nice, huh? To see your name in uppercase, simply type:
>>> "Ola".upper()
'OLA'

You just used the `upper` __method__ on your string! A method (`upper`) is a set of instructions that Python has to perform on a given object (`"Ola"`) once you call it.
You just used the `upper` __function__ on your string! A function (`upper`) is a set of instructions that Python has to perform on a given object (`"Ola"`) once you call it.

If you want to get the number of letters in your name, there is a method for that too!
If you want to get the number of letters in your name, there is a function for that too!

>>> len("Ola")
3

Wonder why sometimes you call methods by adding `.` at the end of the string (like `"Ola".upper()`) and sometimes you first call a method and place the string in parentheses? Well, in some cases, methods belong to objects, like `upper` that can only be performed on Strings. But sometimes, methods don't belong to anything specific and can be used on different types of objects, just like `len`. That's why we're giving `"Ola"` as a parameter to `len` method.
Wonder why sometimes you call functions by adding `.` at the end of the string (like `"Ola".upper()`) and sometimes you first call a function and place the string in parentheses? Well, in some cases, functions belong to objects, like `upper` that can only be performed on Strings. In this case, we call the function a __method__. Other times, functions don't belong to anything specific and can be used on different types of objects, just like `len`. That's why we're giving `"Ola"` as a parameter to `len` function.

### Summary

Ok, enough of strings. So far you've learned about:

- __the prompt__ - typing commands (code) into prompt give you Python answers
- __numbers and strings__ - in Python it's math and text objects
- __methods__ - are actions in Python. You've used both English-language methods (upper, len) and symbolic ones (+, *).
- __functions__ - are actions in Python. You've used both English-language functions (upper, len) and symbolic ones (+, *).

That's the basic of every programming language you learn. Ready for something harder? We bet you are!
That's the basics of every programming language you learn. Ready for something harder? We bet you are!

## Errors

Expand All @@ -90,16 +90,16 @@ We got our first error! It says that objects of type "int" (integers, whole numb
>>> len(str(304023))
6

It worked! We used `str` method inside of `len` method. `str` is converting everything to strings.
It worked! We used `str` function inside of `len` function. `str` is converting everything to strings.

- `str` method convert things into __strings__
- `int` method convert things into __integers__
- The `str` function converts things into __strings__
- The `int` function converts things into __integers__

> Important: we can convert numbers into text, but we can't convert text into numbers.
> Important: we can convert numbers into text, but we can't necessarily convert text into numbers - what would `int('hello')` be anyway?

## Variables

There is a concept in programming called variables. A variable is nothing more than a name for something so you can use it easier. Programmers use these variables to store data, make their code more readable and to not forget what something is.
An important concept in programming is variables. A variable is nothing more than a name for something so you can use it later. Programmers use these variables to store data, make their code more readable and to not help them remember what things are.

Let's say we want to create a new variable called `name`:

Expand All @@ -112,13 +112,13 @@ As you've noticed, your program didn't return anything like it did before. How d
>>> name
'Ola'

Yikes! Your first variable :)! You can always change what it is:
Yippee! Your first variable :)! You can always change what it is:

>>> name = "Sonja"
>>> name
'Sonja'

You can use it in methods too:
You can use it in functions too:

>>> len(name)
5
Expand All @@ -134,7 +134,7 @@ Play with this for a while and see what you can do!

## Lists

Beside strings and integers, Python has all sorts of different types of objects. Now we're going to introduce one called __list__. List is the exact thing you think about now: object that is a list of objects :)
Beside strings and integers, Python has all sorts of different types of objects. Now we're going to introduce one called __list__. Lists are exactly what you think they are: they are objects which are lists of other objects :)

Go ahead and create a list:

Expand All @@ -145,7 +145,7 @@ Yes, it's empty. Not very useful, right? Let's create a list of lottery numbers.

>>> lottery = [3, 42, 12, 19, 30, 59]

All right, we have a list! What can we do with it? Let's see how many lottery numbers there are in a list. Do you have an idea which method you should use for that? You know this already!
All right, we have a list! What can we do with it? Let's see how many lottery numbers there are in a list. Do you have an idea which function you should use for that? You know this already!

>>> len(lottery)
6
Expand All @@ -154,7 +154,7 @@ Yes! `len` can give you a number of objects in a list. Handy, right? Maybe we wi

>>> lottery.sort()

This doesn't return anything... because we didn't print it! Try this:
This doesn't return anything, it just changed the list in place. Let's print it out again and see what happened:

>>> print(lottery)
[3, 12, 19, 30, 42, 59]
Expand All @@ -173,14 +173,14 @@ Easy, right? If you want to add something to the list, you can do this by typing
>>> print(lottery)
[59, 42, 30, 19, 12, 3, 199]

If you want to read only the first number, you can do this by using index. The first object of the list is an object number 0, next one is 1, and so on. Try this:
If you want to read only the first number, you can do this by using __indexes__. Computer people like to start counting at 0, so the first object of the list is at number 0, next one is 1, and so on. Try this:

>>> print(lottery[0])
59
>>> print(lottery[1])
42

As you can see, you can access different objects in your list by using its name and index number inside of brackets.
As you can see, you can access different objects in your list by using its name and index number inside of square brackets.

You can find a list of all available list methods here in Python documentation: https://docs.python.org/3/tutorial/datastructures.html

Expand Down Expand Up @@ -241,9 +241,9 @@ You can give Python as many numbers to compare as you want, and it will give you

## Boolean

Accidently, you just learned about a new type of object in Python. It's __boolean__ -- probably the easiest type there is.
Accidently, you just learned about a new type of object in Python. It's called a __boolean__ -- probably the easiest type there is.

Boolean can be only two things:
There are only two boolean objects::
- True
- False

Expand Down Expand Up @@ -336,21 +336,21 @@ See what happened there?
In the last three exercises you learned about:

- __comparing things__ - in Python you can compare things together using `>`, `>=`, `==`, `<=`, `<` and `and`, `or` operators
- __boolean__ - type of object that can only held two values: `True` and `False`
- __if...elif...else__ - statements that are helpful to execute only code that meet given conditions.
- __boolean__ - a type of object that can only have two values: `True` and `False`
- __if...elif...else__ - statements that allow you to execute code only when certain conditions are met.

Time for the last part of this chapter!

## Methods (functions)
## Your own functions!

Remember about methods like `len` that you can execute in Python? Well, good news, you will learn how to write your own functions now!
Remember functions like `len` that you can execute in Python? Well, good news, you will learn how to write your own functions now!

A function is a set of instructions that Python should execute. Each function in Python starts with the keyword `def`, has a name and can have some parameters. Let's start with an easy one:

>>> def hi():
...

As you can see, there are the dots again! This means that nothing has really happenned yet... and yes, we need to do a `TAB` before giving our instructions:
As you can see, there are the dots again! This means that nothing has really happened yet... and yes, we need to do a `TAB` before giving our instructions:

>>> def hi():
... print('Hi there!')
Expand Down Expand Up @@ -403,7 +403,7 @@ Let's call the function now:
>>> hi("Rachel")
Hi Rachel!

Congratulations! You just learned how to write functions :)!
Congratulations! You just learned how to write functions :)!

## Loops

Expand Down Expand Up @@ -435,6 +435,7 @@ Dots again! Remember what goes after dots? Yes, tab :)
Hi Ola!
Next girl
Hi You!
Next girl

As you can see, everything you will put inside `for` statement with `tab` will be repeated for every element of the list `girls`.

Expand All @@ -449,7 +450,7 @@ You can also do `for` on numbers using `range` method:
4
5

`range` is a method that creates a list of numbers from one number to another (numbers are given by you as parameters).
`range` is a function that creates a list of numbers from one number to another (numbers are given by you as parameters).

## Summary

Expand Down