Skip to content

Instantly share code, notes, and snippets.

Introduction to Sinatra

1. What is the purpose of the server file (routing)?

The server file is the gatekeeper that receives and appropriately responds to client requests based on the verb (GET, POST, DELETE, PUT) and the path present in the request.

2. How do you pass variables into the views?

By adding them in a hash erb(:index, :locals => {:variable => variable}) for local variables, or as instance variables s/a @variable.

@kamiboers
kamiboers / cfu_crud_in_sinatra.markdown
Last active March 23, 2016 04:20 — forked from rwarbelow/cfu_crud_in_sinatra.markdown
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.

CRUD stands for Create, Retrieve, Update, and Delete. These are the major functions of a database application.

  1. There are seven verb + path combinations that are necessary in a basic Sinatra app in order to provide full CRUD functionality. List each of the seven combinations, and explain what each is for.

Get, render index of objects Get, render data object by id Get, render form to post new data object Post, redirect to new data object (with id)

## Models, Databases, Relationships in Rails
#### What is the difference between a primary key and a foreign key? Where would we find a primary key? What would it be called by default? Where would we find a foreign key? What is the naming convention for a foreign key?
A unique primary key exists for every element/row in a table, and would be called that object's id. A foreign key is the identifier of an object/row in a table different from the one in which it is found, and does not have to be unique in the table in which it is found. It points to a related object. The naming convention is the table/object name + _ + id.
#### Write down one example of:
* a `one-to-one `relationship: student to locker assignment
* a `one-to-many relationship`: teacher to students
* a `many-to-many relationship`: students to classes

Git Commands

  • git stash is used to temporarily store the uncommitted changes that you've made on one branch in order to go and work on another branch without being forced to commit files that aren't ready to be committed.
  • git stash apply applys the changes from the most recent stash when you return to the branch. You can view all previous stashes with git stash list, and apply changes from a specific stash with git stash apply stash@{#}, where # is the stash id.
  • git shortlog summarizes the git log output, and can be modified to provide a numbered list (-n) or summary (-s), among several other options accessible at git shortlog --help.
  • git commit --amend is used to edit local commit messages. In order to alter the version pushed to github, a force command must be used.
  • git reset --hard resets the index and the working tree. Any changes to tracked files in the working tree since the last commit are discarded.
  • git reset --soft does not reset the index or

Setting Group Expectations

Group Member Names:

  1. When are group members available to work together? What hours can each group member work individually? Are there any personal time commitments that need to be discussed?
  • Kami: happy to stay until evening but don't want to spend forever here. Generally want to be able to take work with us if possible.
  • Chris: has some personal commitments in the afternoon
  • Ashwin: some things on M W at 630 but also doesn't want to stay in basement
  1. How will group members communicate? How often will communication happen, and how will open lines of communication be maintained?
  1. What does it mean to concatenate files? Find an image of an example concatenated file. Why would we want to concatenate files? Joining or merging files. We might want to concatenate files to reduce the size of the files and speed up our app's use of assets. Concatenated Files

  2. What does it mean to precompile files? What does this have to do with coffeescript and sass files? Pricompiled files are compiled into an intermediate form that is faster to process for the compiler.
    Coffeescript is an abbreviated language that compiles into JavaScript. Sass is faster to write than CSS, and it is reusable and read more efficiently by the computer.

  3. What does it mean to minify files? Find an image of an example minified file. Why would we want to minify files?

Week 5 Diagnostic

When and why would you rebase? In preparation to merge your branch into master, in order to squash small commits and make the git log easier to interpret.

What are the steps to do a basic rebase via the command line? git rebase -i HEAD~<# of steps backward in the commit log>

Our cart in Little Shop is not stored in the database. How does its state persist across requests? As of right now, it's stored in a session that is only cleared when the user leaves/logs out.

Most Frequent Word in a String

Description: Write a function that, given a string of text (possibly with punctuation and line-breaks), returns an array of the top-3 most occurring words, in descending order of the number of occurrences.

Assumptions:

  • A word is a string of letters (A to Z) optionally containing one or more apostrophes (') in ASCII. (No need to handle fancy punctuation.)
  • Matches should be case-insensitive, and the words in the result should be lowercased.
  • Ties may be broken arbitrarily.
  • If a text contains fewer than three unique words, then either the top-2 or top-1 words should be returned, or an empty array if a text contains no words.

###Leap