Skip to content

Instantly share code, notes, and snippets.

View MostlyFocusedMike's full-sized avatar

Mike Cronin MostlyFocusedMike

View GitHub Profile
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}`))
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 />
function grabber(resource, fakeStatus) {
return new Promise((resolve, reject) => {
window.setTimeout(() => {
if (fakeStatus === 200) {
resolve(`load ${resource}`)
} else {
reject("Error")
}
}, 3000);
});
// 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);
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
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
class Show
attr_accessor :stand_up, :club
@@all = []
def initialize(stand_up, club)
@stand_up = stand_up
@club = club
@@all << self
end
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
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
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
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