Skip to content

Instantly share code, notes, and snippets.

@stellakunzang
Last active April 30, 2020 19:36
Show Gist options
  • Select an option

  • Save stellakunzang/bc2de047bd34cfcb4c4fdaf349c17224 to your computer and use it in GitHub Desktop.

Select an option

Save stellakunzang/bc2de047bd34cfcb4c4fdaf349c17224 to your computer and use it in GitHub Desktop.
Backend Mod2 Pre-work

B2 Intermission Work

Answer these Check for Understanding questions as you work through the assignments.

HTML

  1. What is HTML?

HTML is the standard markup language for Web pages.

  1. What is an HTML element?

HTML consists of a series of elements. The elements tell the browser how to display the content.

  1. What is an HTML attribute?

Attributes are used to provide additional information about HTML elements.

  1. What is the difference between a class and an id? When would you use one vs. the other?

An id attribute is used to define a special style for one special element. A class attribute defines a style for special types of elements. One would decide which to use based on whether it was a single instance or occured multiple times.

  1. What HTML would you write to create a form for a new dog with a "name" and an "age"?
<form>
  <label for="dogname">Dog name:</label><br>
  <input type="text" id="dogname" name="dogname"><br>
  <label for="dogage">Dog age:</label><br>
  <input type="text" id="dogage" name="dogage">
</form>
  1. What are semantic tags? When would you use them over a div?

A semantic element describes its meaning to both the browser and the developer. Semantic elements are useful because they allow data to be shared and reused across applications, enterprises, and communities.

  1. Explain what each of the following HTML tags do and when you would use them:

In general, a browser reads the HTML tags in order to determine how to display content.

  • <h1>, <h2>, etc.

    These are tags that designate headers of different sizes.

  • <p>

    Tag for paragraph element.

  • <body>

    Tag for visible page content.

  • <a> and the href attribute

    Tag for a link, and it utilizes the href attribute to hold the link's destination.

  • <img> and the src attribute

    Tag used to define images, and src designates the source file.

  • <div>

    This is a block-level element and is used a container for other HTML elements.

  • <section>

    This tag defines a section in a document. More specifically, "A section is a thematic grouping of content, typically with a heading."

  • <ul>, <ol>, and <li>

    The first tag defines an unordered list while the second defines an ordered or numbered list. The final tag is used to designate individual items in the list.

  • <form>

    This tag defines a form that is used to collect user input.

  • <input>

    The input tag is the most important form element and is paired with a type attribute that defines the buttons and fields in the form.

CSS

  1. What is CSS?

CSS describes how HTML elements are to be displayed on screen, paper, or other media. HTML was not designed to contain tags for formatting a web page, for example designating fonts and colors.

  1. What is a CSS selector? How do you use the ID selector? The class selector?

The selector points to the HTML element you want to style. The id selector uses the id attribute of an HTML element to select a specific element. The class selector selects HTML elements with specific class attributes.

  1. What are the three ways to include CSS in your HTML documents? What are the pros and cons of each?

Inline, internal, and external. Inline is used to apple a unique style to a single HTML element. Internal is used to define a style for a single HTML page. And external is used to define the style for many HTML pages. The advantage of external CSS is that you can alter the look of an entire web site by changing a single file. The external style sheet can be written in any text editor.

  1. What is the Box Model? Describe each component of the Box Model.

All HTML elements can be considered as boxes. The term "box model" is used when talking about design and layout in CSS. It consists of margins, borders, padding, and the actual content.

SQL

Jumpstart Lab Tutorial

  1. What is a database?

Databases are at the core of almost every web application. They are a means of storing, fetching, calculating, and sorting data.

  1. What is SQL?

SQL stands for Structured Query Langauge. It is a programming language we use to interact with most databases. The most popular SQL-based databases include PostgreSQL, MySQL, Oracle...

  1. What is SQLite3?

SQLite stores data in a plain-text file. This makes it easy to move, rename, delete, or transfer the database. It is therefore great for experiments and local development, but not for production. SQLite3 is built into MacOS.

  1. What is a Table?

A table organizes data into rows and columns.

  1. What is a primary key?

The primary key in a SQL table is automatically assigned a unique ID number whenever a new row is inserted into the table.

  1. What is a foreign key?

A foreign key is when the primary key from one table is used as a reference in another table.

  1. Explain what each of the following SQL commands do:
  • insert

    This command is simply used to insert data into a table.

  • select

    This command is used to find rows in a table.

  • where

    This is used to scope down SELECT queries, meaning it limits the returned rows to only those matching the attributes specified.

  • order by

    Output will be in the order it was inserted, unless you use this command specify how you want it ordered.

  • inner join

    This command is used to specify how to join data from separate tables into a new table.

Extra Notes on SQL

  • Many programmers use intermediary libraries to generate SQL. Essentially these libraries doe a form of metaprogramming.
  • SQL is not object-oriented; it is based on relationships.
  • Ruby libraries for interacting with databases are called "Object-Relational Mappers." This means they convert the relational data from the database into Ruby objects.
  • ActiveRecord (AR) is the dominant player in this arena. It is the default database library for Rails and is powerful.
  • Question: What does library mean in this context?

PG Exercises

  1. How can you limit which columns you select from a table?

By specifying the columns using the select command.

  1. How can you limit which rows you select from a table?

By using select and specifying the specific rows using the where command.

  1. How can you give a selected column a different name in your output?

By using the as operator.

  1. How can you sort your output from a SQL statement?

By using the order_by operator.

  1. What is joining? When do you need to join?

Joining allows you to combine related information from mutliple tables to answer a question.

  1. What is an aggregate function?

Aggregate functions are used to extract information about whole groups of rows.

  1. List three aggregate functions and what they do.
  • 'count' : selects the rows that fit the given specifications, and then total the number of rows.
  • 'sum' : adds together everyting in the column specified
  • 'having' : filters the ouput from aggregate functions
  1. What does the group statement do?

The group statement allows us to easily batch data into groups.

  1. How does the group statement relate to aggregates?

The group statement batches data and then we are able to run the aggregation function separately for each group.

Rails Tutorial: Task Manager

Copy and Paste the link to your Task Manager repo here: https://github.com/stellakunzang/task_manager

Copy and Paste the link to your Static Challenge here: https://github.com/stellakunzang/static_challenges

  1. Define CRUD.

Create, Read, Update, and Delete; these are actions the programs we built will be able to carry out.

  1. Define MVC.

Model View Controller; this is an architectural pattern used by Rails. This helps us create interactive and dynamic websites.

  1. What three files would you need to create/modify for a Rails application to respond to a GET request to /tasks, assuming you have a Task model.

I don't fully understand what this question is asking for, but here is my best guess:

  • config/routes.rb
  • app/controllers/welcome_controller.rb
  • app/views/welcome/index.html.erb
  1. What are params? Where do they come from?

The params are :title and :description. They come from user input.

  1. Check out your routes. Why do we need two routes each for creating a new Task and editing an existing Task?

One route creates the news tasks object and the other reads information from that object into the tasks controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment