1/162
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
URI
URI is an abbreviation for Uniform Resource Identifier. It is a string of characters that identifies a web resource by name, location, or both. A URI can be broken down to a URL or a URN.
URL
Uniform Resource Locator. This specifies the particular method of retrieving a given resource on the Internet. HTTPS, FTPS, etc.
URN
URN means Uniform Resource Name. This is a persistent and location-independent way of identifying a resource. The name stays the same even if the resource moves to another location.
Static Website
The web server relays the requests from the client to other parts of the server, where resources are located. The web server packages the response back to the client. The client then visualizes the response in their browser.
Dynamic Website
All that you can do with a simple static website is retrieve its content. However, with a dynamic website the website content is created dynamically, by inserting bits of data into the webpage into placeholders. This is classically called server-side programming nowadays. The server also includes databases, or other storage locations for storing resources. It also has a web application, which assembles data and resources necessary for the client’s web browser. The web application retrieves files and data from the Database to dynamically render the web page.
GET Request
GET is used when you want to retrieve information from the server. Often uses a list of parameter names and values to retrieve information. The response from a GET request can often be stored in the cache.
POST Request
Used when a user posts information to the server. Sending a POST request multiple times creates the very same resource multiple times! Beware
PUT Request
In contrast with POST, The PUT request is used to update an existing resource on the server. If the resource does not yet exist, then PUT will create the resource (in this way it will act like POST). Example: updating posts on social media. Note: sending a PUT request multiple times produces the same result each time (it is idempotent).
DELETE Request
This is used to delete a resource on the server. The structure is similar to GET, no data is posted in the body of the DELETE request.
XML
XML stands for eXtensible Markup Language
JSON
JSON stands for JavaScript Object Notation. JSON can use arrays, whereas XML can’t.
XML Format
<play>
<title>Hamlet</title>
<author>William Shakespeare</author>
<length>45</length>
</play>
JSON Format
{
“title”:”Hamlet”,
“author”:”William Shakespeare”,
“length”:45
}
XML List
<server>
<users>
<user>tommy</user>
<user>sammy</user>
<user>timmy</user>
</users>
</server>
JSON Array
{
“name”: ”Concordia University Irvine”,
“num_students”: 4900,
“departments”: [
“Engineering”,
“Math”,
“Computer science”
],
“president”: “Michael Thomas”
}
What is a cron job?
We can set up automated jobs on the server (usually a Linux server).
These jobs are executed at regular time intervals.
In Windows, these scripts correspond to background services.
Examples of cron jobs
Populating a database based on data scraped from the Internet at a regular interval.
Backing up files
System maintenance
Disk space monitoring, i.e. garbage collection
Limitations of cron jobs
A particular job can only be repeated after one minute, no less.
59 seconds is not possible.
Can only be run on one computer, cannot be distributed.
The job cannot be run if it crashes.
How to Write a Cron Job
A typical cron job descriptor has 6 fields:
Minute: the minute of the hour the job should run: 0-59
Hour: the hour the job should run (24 hour system): 0-23
Day: the day of the month the job should run: 1-31
Month: the months that the job should run: 1-12
Day of the week: 0-6, where 0 represents Sunday
The command/script/program itself
No fields should be left blank.
Cron Job Asterisk (*)
this signifies all possible values for a given field.
In the hour field it goes from 12 am to 11 pm, 00 to 23.
Cron Job Comma (,)
with this you can list multiple values in a field.
i.e. 2,4,5 means every Tuesday, Thursday, and Friday in the “day of the week” field
Cron Job Hyphen (-)
determines a range of values
11-20 in the Day field means from the 11th to the 20th of every month
CJ Separator (/)
This divides a value.
i.e. */6 in the day field means every six days.
CJ Last (L)
can be used in the day of week and day of month fields
i.e. 4L in the day of week field means the last Thursday of the month
CJ Weekday (W)
This denotes the first weekday from a given time point.
i.e. 15W means the weekday closest to the 15th of the month.
If the 15th is a Sunday, then the cron job will run on the 16th of the month.
CJ Hash (#)
this determines the day of the week
i.e. 5#3 means the third Friday of the month, 2#2 means the second Tuesday of the month.
What is n-tier architecture?
An n-tier application is a program that is distributed among multiple separated computers in a distributed network.
N-Teir 3 Layers
The interface layer on the user’s computer (presentation layer)
A server computer that manages a database (database layer)
A centralized middle-layer computer that handles the business logic between the user and the server (application/business layer)
Tier vs Layer
A layer is a logical component of the architecture that accomplishes a given function.
i.e. calculating a result, such as someone’s BMI
Registering a new applicant
Retrieving data from a database
Visualizing results
A tier the hardware platform on which the logical layer runs.
The 3-Layer Model
A 3-tier system has all three basic layers:
Presentation layer
Business/application/logic layers
Server/database layer
Presentation layer
The ‘frontend’, the user interface (UI).
Translates tasks so they are understandable and viewable by the user.
HTML, CSS, JavaScript, webforms
Sends requests to the other two layers.
Presents data retrieved from the server/database layer to the user.
Requires the least security.
Application/Business/Logic layer
The heart of the application, here is where the “business logic” is applied.
Business logic means how the application should be run to achieve its goals.
Accepts the client’s data and passes it on to the database layer much like an interface.
Coordinates processes.
Makes logical evaluations and decisions and performs calculations.
Database layer (the backend)
Contains the Database Management System
i.e. Cassandra, CouchDB, MongoDB
Stores data in databases.
Receives data from the business layer.
Performs the actual requested operations on the database.
i.e. SELECT statements
Sends back requested data via the business layer.
Advantages of n-tier architectures
Security: each of the three layers can be secured independently from one another.
A hacker has to hack all three layers independently to be successful.
Management: each of the three layers can also be managed independently.
Each component in the multi-tier architecture is:
Scalable: new resources can be added easily.
Reusable: each tier can easily be reused for other projects.
Each component in the multi-tier architecture is:
Flexible: each layer can be expanded any way you desire.
Different business logic in different countries.
Presentation layer in different languages.
Or in different layout on a PC, smart phone, or tablet.
Each tier can be developed quickly by itself.
N-tier architectures can be moved into the cloud which makes development cheaper.
Disadvantages of n-tier architectures
Due to the presence of multiple layers in the n-tier architecture, more effort is needed to establish it due to higher complexity.
More complexity also means more opportunities for system failure.
Performance may decrease due to constrictions in I/O flow.
Form validation
The data entered in HTML forms need to be validated:
HTML, PHP and Javascript make it possible to ensure that the right values are transmitted from the form.
Check for missing values
Check that values are within bounds (nobody has a negative height)
Checks if the input is the right pattern
Guard against SQL injections!
HTML form validation
In this case, the form is validated by certain elements in the HTML code itself.
If the conditions set in these fields are violated, the form is not submitted.
Each input field can have attributes for:
type, required, min, max, pattern, disabled, size, readonly, maxlength, etc…
required:
the input must be filled in and does not advance if empty
min and max
min: minimum value required. max: maximum value required.
pattern:
the input must conform to a specified pattern. It follows regex patterns (see Linux programming).
disabled:
user cannot enter data.
readonly:
user cannot enter data, thus the same value is submitted in all cases.
maxlength:
allows input up to a certain length. Good against hacking attacks.
HTML versus Javascript validation
HTML validation happens first, then Javascript validation. HTML also overrides JS validation if both reference the same HTML element.
Javascript form validation allows finer control than HTML.
For example, HTML allows any kind of eye or hair color, whereas Javascript can restrict it to certain values.
Validation with Javascript
Javascript can also be used to validate forms.
As mentioned earlier this can happen in the <head> portion of the HTML or between <script> tags.
A validation function handles form validation.
It retrieves the value of each element in this way:
document.forms["studentForm"]["name"].value:
documents: this represents the entire HTML page.
forms: this contains the names of all of the forms on the page.
document.forms["studentForm"]["name"] references the ‘name’ variable on the form called ‘studentForm’
Value represents the value of the name, i.e. John Smith.
Document Object Model
The Document Object Model (DOM) is a way of accessing HTML elements via Javascript.
Under development since the mid-1990s, we ae currently at DOM5.
Each HTML element in a page belongs to a hierarchy: forms, tables, input fields, etc.
Following this line of hierarchy, we can access every single HTML element.
Accessing HTML elements via DOM
There are three ways of accessing an HTML element via the DOM:
The DOM address
By its name
By its id
Access via DOM address
The root element of an HTML page is ‘document’.
Associated with each document is a set of forms, tables, frames, etc…
Therefore, to access the first form on the HTML page, you reference it by: document.forms[0]
The form’s elements may be accessed by: document.forms[0].elements[0]
Access via element name
This way we access the document’s elements by naming them.
Thus, the element
document.forms["patientForm"]["telephone"].value
Can be rewritten this way:
document.forms.patientForm.telephone.value
Direct access via id
Probably the simplest way of accessing HTML elements, you simply need to use the document.getElementById(<element id>) function.
This accesses the form element by id.
Thus, the element (by name)
document.forms["patientForm"]["telephone"].value
Can be rewritten this way:
document.getElementById(“telephone”)
REGEX Pattern
The pattern is always placed in between the two / symbols called anchors. The pattern must fit inside the two anchors.
Anchors represent regular expressions in awk, perl, and other languages.
The anchors are not symbols themselves, they only contain the pattern.
^ means that the text must begin with the specified pattern.
$ means that the text must end with the specified pattern.
\d
A digit
\D
Not a digit
\w
A word (alphanumeric character)
\W
Not a word character
\s
A whitespace character: space, return (\r), tab (\t), line feed (\n), form feed (\f)
\S
Not a whitespace
.
Any character. Note: \. Means a period.
[^]
Anything but what ever comes after the up arrow
{3}
means a digit occurs exactly 3 times, i.e.: “God’s number is 777”
{3,4}
means that a digit occurs 3 or 4 times, i.e. “-3882-” and “-601-”
{3,}
means it occurs at least 3 times, i.e. “92888181”, but “a34b” does not.
?
Means that the character occurs either once or never.
+
means that the character must occur at least once, i.e. /a+/ matches ‘cat’ and also ‘Transvaal’, but not ‘joke’
*
means that the character can occur any number of times, i.e. .txt matches all text files.
Non-relational databases
The first computer-based databases contained data in a non-relational format.
Relational: data in separate data tables are associated with one another in some way
The two main non-relational database types are:
Hierarchical databases
Network databases
Hierarchical databases
Each node may also have 0, 1, or more child nodes.
You go from the root node to leaf nodes by traversing many intermediate nodes.
Fast usage
Inflexible: to get to data at the bottom of the hierarchy you always have to go through all the parent nodes above it.
Network databases
Consists of:
Sets of records
Sets of links that define relationships between different records
Records contain fields (as in a data table)
Pointers are used to direct the user from one table to the next
Since many different relationships exist between different records, there is no need to go through all levels of a hierarchical database.
What is a relation?
Essentially a table. An entity is something of importance represented in the database as a row.
the seven most important characteristics of relations:
Rows contain related pieces of data about a specific, unique entity.
Columns contain data about the entity’s attributes.
All entries in a column must have the same type.
Each column has a unique name, and each row has a unique identity.
No two rows can be identical.
Cells in the table each hold a single value only, no comma-separated values.
Row and column order is unimportant (although it can be helpful).
relation structures
Relation_name(column_1, column_2, … column_n). Foreign keys are in italics. Primary Keys are underlined.
Database integrity constraints
Domain integrity
Entity integrity
Referential integrity
Domain integrity constraint
A domain is a data grouping that meets a specific definition.
All values in a given column must have the same type.
For example, every value in a hypothetical column first_name must be a string: Arnold, Betty, Cathy, Dylan, etc., not a number, like 86
Entity integrity constraint
When selecting a primary key, whether it has a single or multiple columns, it must have unique data in it.
Longer keys are more likely to be unique but need more overhead.
Shorter keys are more practical but may not be unique.
Referential integrity constraint:
When defining a foreign key that references another table, each foreign key must match up with a value in the other table.
Otherwise, you get an error.
This is important later on for performing data queries.
Key types(7)
Single column
Composite
Candidate
Primary
Alternate
Surrogate
Foreign
What is a key?
A key is one or more columns of a table that can be used to identify a set of rows.
A key can be unique or non-unique.
If the key is unique, it identifies only one single row.
Conversely, non-unique keys may identify one or multiple rows!!
We want unique keys!
Single Column Key
A single column key corresponds to a single column in the table that we want to use to uniquely identify rows.
composite key
covers two or more columns in order to be unique.
Primary Key
A good key that uniquely identifies each row. Unique to each table.
candidate keys
Several single-column/composite keys that could act as primary key
alternate keys
the “losing” candidate keys that were not chosen to be the primary key
Surrogate keys
The database structure may change, and as such, it is good to have surrogate keys if they need to become primary keys.
(Remember, surrogate keys were candidate keys that were not chosen – they act like vice presidents when the president is incapacitated)
Many times a simple solution is to assign a row number to each row, which will be a surrogate primary key. Simple and guaranteed to be unique.
Some DB systems automatically generate such a row number acting as a surrogate primary key using auto_increment.
Foreign key
Records in separate tables are connected by redundant values in a special column called the foreign key.
If you want to get more information in another table, you can navigate there via the foreign key which has the same value in both tables.
This is the relational aspect of relational databases.
What is a functional dependency?
If a box of cookies is $5, and we have 7 boxes, the total price is 7 x $5 = $35.
Here the NumberOfBoxes determines the TotalPrice.
X and NumberOfBoxes are so-called determinants.
NumberOfBoxes => TotalPrice is called a functional dependency.
Unsigned vs. Signed Ints
Signed - Positive or Negative
Unsigned - Only Positive
TinyINT
255, 1 Byte of Storage
SmallINT
65535, 2 bytes
Medium INT
16 million, 3 bytes
INT
4 billion, 4 bytes
BIGINT
more than 4 billion ig
Fixed point, decimal types
Decimal types have two parts:
The precision, or the number of digits for the entire number (integer and fraction parts together).
The scale, or the number of digits in the fractional part.
For example: expression_level DECIMAL(7,3) may contain numbers from -9999.999 to 9999.999
BIT
BIT(M), where M can range from 1 to 64 bits
BIT(5) can take values from 00000 (0) to 11111 (31)
2^5 = 32 possible values
CHAR(#)
Stores a string that HAS to be length of the number and will be padded to the length if not.
VARCHAR(#)
Stores a string with variable length that has a max length = to the #.
TEXT
Use these data types if you need something larger than char or varchar.
TEXT: this data type can contain a string of up to 65,536 characters, in 16 bytes (2 = 65536)
TINYTEXT: 2 = 255 characters
MEDIUMTEXT: 2 = 16,777,215 characters
LONGTEXT: 2 = 4,294,967,295 characters
ENUM
ENUM (enumeration): A string object can have as many as 65,536 distinct values, including NULL and ‘’ listed in the ENUM.
i.e. temperature ENUM(‘freezing’, ’cold’, ’mild’, ‘warm’, ‘hot’)
These must be referenced by their index number (1=freezing, 2=cold, etc.)
only one value can be selected
SET
SET: a set of zero or more unique values that you can choose from.
The empty set can be defined as a data type, but not useful practically speaking.
i.e. color SET(‘red’, ‘green’, ‘yellow’, ‘blue’, ‘orange’)
allows multiple values to be selected
What does CRUD stand for?
Create a data table
Read (query) a data table to extract information
Update, or change the data found in the data table
Delete data from a database
1:1 Relationship
If a row in a given table can reference only one row in another table, this is an example of a 1:1 relationship.
For example, if we have a table called men and a table called women, then one man may reference only one woman.