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 Adapter = { | |
baseUrl: "http://localhost:3000/tasks", | |
toJSON: function(data) { | |
return data.then((res) => res.json()) | |
}, | |
getAll: function() { | |
return this.toJSON(fetch(this.baseUrl)); | |
}, | |
getOne: function(id) { | |
return this.toJSON(fetch(`${this.baseUrl}/${id}`)) |
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
fetch('https://jsonplaceholder.typicode.com/users/1') | |
.then(function(response) { | |
console.log(`status: ${response.status}`); | |
console.dir(response.body); | |
return response.json() // the important line | |
}) | |
.then(function(myJson) { | |
document.write( | |
`User: ${myJson.name} <br/> | |
Email: ${myJson.email} <br /> |
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
function grabber(resource, fakeStatus) { | |
return new Promise((resolve, reject) => { | |
window.setTimeout(() => { | |
if (fakeStatus === 200) { | |
resolve(`load ${resource}`) | |
} else { | |
reject("Error") | |
} | |
}, 3000); | |
}); |
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
// we'll use arrow functions for brevity | |
let asynchProm = new Promise((resolve, reject) => { | |
let fakeCode = 200; | |
window.setTimeout(() => { | |
if (fakeCode === 200) { | |
resolve({status: "OK"}) | |
} else { | |
reject({status: "ERROR"}) | |
} | |
}, 3000); |
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 BelongsToClass | |
# accessors and whatnot | |
@@all = [] | |
def initialize(has_many_class_a_obj, has_many_class_b_obj) | |
@has_many_class_a_obj = has_many_class_a_obj | |
@has_many_class_b_obj = has_many_class_b_obj | |
end | |
def self.all | |
@@all | |
end |
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 StandUp |class Club | |
| | |
attr_accessor :name | attr_accessor :club_name | |
| | |
@@all = [] | @@all = [] | |
| | |
def initialize(name) | def initialize(club_name) | |
@name = name | @club_name = club_name | |
@@all << self | @@all << self | |
end | end |
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 Show | |
attr_accessor :stand_up, :club | |
@@all = [] | |
def initialize(stand_up, club) | |
@stand_up = stand_up | |
@club = club | |
@@all << self | |
end |
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
SELECT * | |
FROM owners | |
INNER JOIN cats_owners | |
ON owners.id = cats_owners.owner_id | |
INNER JOIN cats | |
ON cats_owners.cat_id = cats.id; | |
# returns | |
id name cat_id owner_id id name age breed net_worth | |
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- |
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
SELECT cats.name AS cat, owners.name AS owner |P | SELECT * | |
FROM owners |R | FROM owners | |
INNER JOIN cats_owners |E | INNER JOIN cats_owners | |
ON owners.id = cats_owners.owner_id |V | ON owners.id = cats_owners.owner_id; | |
INNER JOIN cats |I | | |
ON cats_owners.cat_id = cats.id; |O | # which returned: | |
|U | | |
# returns this: |S ->| id name cat_id owner_id | |
| | ---------- ---------- ---------- ---------- | |
cat owner |L | 2 Sophie 3 2 |
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
SELECT * | |
FROM owners | |
INNER JOIN cats_owners | |
ON owners.id = cats_owners.owner_id; | |
# which would return: | |
id name cat_id owner_id | |
---------- ---------- ---------- ---------- | |
2 Sophie 3 2 | |
3 Penny 3 3 |