This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = { username: 'example' }; | |
fetch('https://example.com/profile', { | |
method: 'POST', // or 'PUT' | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify(data), | |
}) | |
.then((response) => response.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////Classes and subClasses | |
//ES5 | |
var Person5 = function (name, yearOfBirth, job) { | |
this.name = name; | |
this.yearOfBirth = yearOfBirth; | |
this.job = job; | |
}; | |
Person5.prototype.calcAge = function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get the average pixels | |
function getAveragePixels(cssObj) { | |
return Object | |
.values(cssObj) | |
.filter(el => el.includes('px')) | |
.map(el => parseInt(el)) | |
.reduce((acc, nr, index, array) => acc = (acc + nr) / array.length) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//npm install --dev eslint prettier eslint-config-airbnb@^15.0.1 eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y@^5.1.1 | |
{ | |
"extends": ["airbnb", "prettier", "prettier/react"], | |
"plugins": ["prettier"], | |
"parser": "babel-eslint", | |
"parserOptions": { | |
"ecmaVersion": 2016, | |
"sourceType": "module", | |
"ecmaFeatures": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /newsletters # Show all newsletters | |
POST /newsletters # Create a new newsletter | |
GET /newsletters/new # Render the form for creating a new newsletter | |
GET /newsletters/:id/edit # Render the form for editing a newsletter | |
GET /newsletters/:id # Show a specific newsletter | |
PATCH /newsletters/:id # Update a newsletter | |
DELETE /newsletters/:id # Delete a newsletter | |
----------------------------------------------------------------------------- | |
Nested Routes | |
#We often need to access resources as they relate to parent resources, and our RESTful |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.all; | |
// returns all the nodes inside the document object | |
document.contentType; | |
// returns the type of content contained. Most web pages should return "text/html" | |
document.URL; | |
// returns the URL of the document object | |
---------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; | |
// => undefined | |
alphabet.length; | |
// => 26 | |
alphabet[alphabet.length - 1]; | |
// => "z" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number.isInteger() | |
Number.isInteger(42); | |
//=> true | |
Number.isInteger(0.42); | |
//=> false | |
------------------------------ | |
Number.isFinite() | |
Number.isFinite(9001); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SongsController < ApplicationController | |
before_action :set_song, only: [:show, :edit, :update, :destroy] | |
def index | |
@songs = Song.all | |
end | |
def new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthorsController < ApplicationController | |
def create | |
@author = Author.new(author_params) | |
if @author.valid? | |
@author.save | |
redirect_to author_path(@author) | |
else | |
render :new | |
end |
NewerOlder