Skip to content

Instantly share code, notes, and snippets.

@joeyharbert
Last active April 15, 2019 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyharbert/19be89d7744b99704e7ad251acf252b1 to your computer and use it in GitHub Desktop.
Save joeyharbert/19be89d7744b99704e7ad251acf252b1 to your computer and use it in GitHub Desktop.
Today I Learned

2/17:

  • I learned that SQL is a relational database (much like a spreadsheet). I also learned that documents llike this are useful to prove knowledge, as well as helping concretize knowledge and have a place of reference for things in case I forget something. I also learned that "```" (three backticks) will start and end a block of code format in this file. If you put the programming language after the opening backticks in lowercase (on it's own line) it will give you syntax highlighting for that language.
  • ls -l = -l is a list flag for terminal
  • ls -a: -a flag that shows files starting with '.'
  • clear terminal command
  • ls -GF gives syntax highlighting
  • cd .. goes up a level of file (I keep forgetting that)
  • pwd = print working directory
  • mkdir = make directory (make a new folder)
  • touch = make file
  • cat = to show file contents
  • rm = remove file
  • rmdir = remove directory (only works if the folder is empty)
  • rm -rf = remove directory and contents (adult delete)
  • history # = where # is the number of commands, shows the command history (you can use the command number with !#)
  • !! = runs the previous line of code
  • sudo stands for super user do (run as admin)
  • tab for autocomplete in terminal
  • git init = start git track
  • Commit version
    git add --all
    git commit -m "message"
    
  • git status = checks if last save == current file
  • git diff = tells what's changed since last commit
  • git log = tells who did what when
  • commit messages are always in present tense

2/18

  • HOD (hotkey of the day): cmd + tab (same as alt+tab on windows) cycle through programs
  • "cmd + /" to comment out a block of text
  • "cmd + d" highlights next instance of a word and allows you to edit both
  • when creating repository the name has to exactly match the file name in your computer
  • in ruby, single and double quotes operate the same until you try interpolation (concat is fine) this is because single quotes are faster than double quotes, so the ruby community prefers double quotes unless you need interpolation.
  • cmd + shift + d = copies current line
  • you can write a hash with key: value instead of key => value
  • cmd + shift + enter = creates a new line above the line you're on
  • shift + option = selects word

2/19

  • HOD: cmd + space: spotlight search (We been knew sis)
  • 'git checkout .' returns to last commit
  • in sublime press k then b to show file system you're in
  • within a class, if you're calling a method inside another method, ruby checks first to see if there is a local variable of that name. Second it will check for local methods.
  • #/ to end a "block" of comments eg: # getter methods ......code..... #/getter methods
  • cmd + down = gets you to end of file
  • attr_reader :variable1, :variable2, etc is equivalent of getter method
  • attr_writer :var1, :var2, var3 is same for setter method
  • ^^^ always at beginning of class before init
  • you can use a hash to allow more flexible initialization of a class
  • when you're passing a hash into an instance of a new class, you don't need to use the curly braces inside the parentheses
  • '<' for inherit classes
  • you can only inherit from one class, but you can chain inherits
  • 'super' checks what we're inheriting from and brings all that code down (so we are able to add to a method without overriding it)

2/20

  • HOD: cmd + shift + tab = backwards cmd + tab
  • cntrl+shift+right highlights word
  • module naming usually ends in -able
  • looks like class, holds methods for multiple classes to access (wrapper for a bunch of methods) to use a module use the keyword 'include {modulename}' in the class
  • classes Capitalized, singular, camelcase
  • require is normally used for gem, but you can use it for files you just need to use './' to have require look in the folder you're in. require './filename.rb' to use other files (for classes and such)
  • require_relative does same thing as require you just don't have to use './' (it means start looking in this directory not in the gem directory)
  • cmd + ] is tab for highlighted text
  • you can use a module to wrap a class so that your class doesn't override classes with the same name you call it by using Module::Class

2/21

  • cmd + option + 2 for split screen in sublime
  • Web verbs: - GET is for reading - POST is for changing - PATCH is for updating - DELETE is for removing (duh)
  • Technically, patch and delete are sub-commands of post
  • API generally refers to making web requests and getting back JSON data (instead of HTML), though API is a much, much broader term.
  • Status code: -100 = info -200 = Success -300 = Redirect -400 = Client Error (your fault) -500 = Server Error (developer fault/my fault)
  • ALWAYS DELETE API KEY BEFORE PUSHING CODE

2/24 RAILS DAY

  • HOD: cmd + enter = move from middle of line to next line cmd + shift + enter = move up a line
  • opt + right arrow move my word instead of character
  • rails won't work until you have a database (you'll get an error)
  • "rails server" makes a testing server on your computer
  • Beginning commads for creating a rails app (for now)
    rails new sample_app
    cd sample_app
    rails generate controller api/example_pages
    rails db:create
    rails server
  • Steps once you hit enter to get a website:
▼ ▼ ▼ ▼ STEPS ▼ ▼ ▼ ▼
---------------------
1. WEB REQUEST
2. API ROUTE
3. API CONTROLLER (gets data from MODEL)
4. API VIEW
5. WEB RESPONSE 
  • cmd + shift + d = copies a line
  • If the error doesn't pop up on the screen, you can check your server messages for the error

2/25

  • HOD: cmd + down/up brings you to bottom/top of file
  • .sample picks raandom element out of an array
  • .shuffle randomly shuffles an array
  • cmd + cntrl + up/down to move lines
  • MODEL is ruby class that takes data from database, packages it into a ruby class that we can access
  • controller name is plural of model
  •     rails db: migrate
    
  • CRUD = Create Read Update Delete (or Destroy)
  • Model automatically has initialize function (even though it's not in the file) that takes in an options hash that has the keys and values of our generate model command
  • if an instance of a model has an id it is in the database, if the id is nil, then it is not in the database
  • any time you modify an instance of a model, you have to save it to the database again

2/26

json.array! @array_name.each do |item|
  #normal json assignment code 
end 
  • to add gem to web app, add to Gemfile, stop server, use 'bundle install'
  • sql vs no-sql databases sql more popular and older, no-sql is up and coming sql operates as spreadsheet, but no-sql can operate in other was (such as key value pairs)
  • MVC = Model View Controller
  • Model defines how we interact with stored information
  • Model = stored data
  • View = Interface -JSON or HTML, forms, UI
  • Controller = Logic Flow -usually involves if statements filters or CRUD operations. -combines all these pieces together
  • Ideally, want to do calculations in the Model, not Controller
  • cmd + cntrl + up/down = moves a line up or down
  • if a method only returns boolean the name should end with a question mark

2/27

  • query string, url, body parameters to get dynamic info from user
  • rails knows that once it sees a question mark in a route that everything after is a query
  • rails will then create a hash of key value pairs (called params) based on the queries
  • in params you can call strings and symnbols both for they key (they are strings, but traditionally people use symbols)

2/28

  • HOD: can cmd + c without higlighting on a line in sublime
  • by default, rails won't accept anything that's not a get request that's not from within rails
  • To get around this: protext_from_forgery with: :null_session in application_controller.rb

3/3

  • HOD: cmd + ~ switch between windows of an application
  • cmd + opt + [a number] = split screen in sublime

3/5

  • if you're in the views folder and the file begins with an underscore, then it's a partial
  • json.partial! "blah.json.jbuilder", noun: @noun notice that there is no underscore before the filename

3/6

  • Upper camel case for migration file
  • rails generate migration NameOfFile
  • migrations can act as version control for your database
  • use _ for previous command (so x = _)
  • learned about validations see documentation
  • .save fails quietly, returns false
  • use .errors.full_messages to return an array of all the error messages

3/7

  • SQL SELECT column1, column2 FROM table;
  • SELECT * FROM table; Select all
  •     WHERE column = 'something' ```
    
  • Only use single equal in SQL
  • Only single quote in Postico
  • chain WHERE's together with AND
        WHERE blah
        AND   blah; ```
    
  •     WHERE blah
        OR blah;   ```
    
  • LIMIT number;
  • ORDER BY column;
  • WHERE ingredients LIKE '%blah%'; search for string within a string
  • SELECT COUNT(*) FROM table
  • SUM, COUNT, AVG (Average)

3/10

  • can use .where(key: "value") in ruby like WHERE in SQL
  • one to many relationship: one object owns/or is attached to many objects

3/11

  • Normalizing = DRYing up talbles by splitting them up
  • primary key - key on current table
  • foreign key - key pointing to a different table
  • 'g' is shortcut for generate in console e.g. 'rails g migration'
  • likewise 's' works for server
  • reload! does the same thing as exiting out and reloading rails console
  • use 'belongs_to :parent' in place of connecting parent to child
    • in order for this to work, the table has to be named correctly, there has to be a parent_id column
  • conversely has_many works to connect child to parent

3/12

  • if you have a belongs_to, it automatically creates a validation so that the child has to reference an instance of the parent when being created
  • ls -ltr lists files by most recently added
  • cmd + shift + d duplicates line

3/13

  • HOD: shift + cntrl + left/right : highlight until capital letter or _

3/14

  • CHECK YOUR SERVER FOR ERRORS (when working with front end)

3/17

  • For many to many, create "join table" that houses id's
  • name the joiner by smashing the two names together e.g. for products and categories tables, the join name would be category_products
  • name should be in alphabetical order (categoryproducts not productcategories)

3/18

  • HOD: fn + del: is backwards delete

3/19

  • cntrl + tab cycles through tabs (based on most recent in sublime)

3/20

  • rails s -p 3001 = runs rails server on localhost:3001
  • with figaro, you have to restart your server anytime you edit the application.yml file

3/21

  • HOD: cmd + option + left bracket : collapses HTML tags
  • forms can be used to make a request!
  • <% %> to run ruby code <%= %> to render in HTML in erb
  • redirect_to works like a link in ruby
  • For constant header and footer use application.html.erb in layouts (in views)

3/23

  • cmd + opt + j = view source

  • chrome only understands get and post requests by default

  • <- patch workaround

  • rel="nofollow" tells the bots to not click this link

  • Capstone:

    • Idea
    • User stories -Trello -See Brian
    • Does the data I need exist? (N/A for me)
    • Schema
    • What happens in db for each user story
    • rails new ... API
    • test associations in rails console (see if everything is wired up correctly)
    • make rest of app...
  • MVP = minimum viable product

  • 25m then 5m break

3/25

  • CSS:
    • is for ID's

    • . is for classes
    • id is only used once, class can be used multiple times
    • float: left; goes left to right, right does the opposite

3/26

  • cmd+opt+j opens js console

3/27

  • cmd+shift+f is find for entire app

3/28

  • JS convention uses camelcase instead of snake case

3/31

  • cmd + r to search methods

4/1

  • server side javascript is node (can access files and folders)
  • client side javascript is the js that runs in chrome (can't access files and folders)
  • vue.js good framework to output js into html
  • use {{ }} similar to <%= %> in rails
  • webpack is awesome

4/2

  • rails db:setup = rails db:create && rails db:migrate && rails db:seed
  • rails db:reset drops db and runs above
  • => (fat arrow) functions for axios

4/4

  • Nested DIVs are fine in Vue template, but consecutive divs are not
  • HOD: cntrl + A, go to beginning of line on terminal

4/7

  • HOD: cntrl + E, end of line terminal

4/8

  • cntrl + g searches by line

4/9

  • cntrl + shift + down highlight character directly below

4/10

  • cmd + j adds next line to end of current line

4/14

  • cmd + L : highlights entire line and moves cursor to beginning of next line

4/15

  • cntrl + m : toggles between beginning and ending curly braces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment