Skip to content

Instantly share code, notes, and snippets.

View MostlyFocusedMike's full-sized avatar

Mike Cronin MostlyFocusedMike

  • New York City
View GitHub Profile
SELECT SUM(cats.net_worth)
FROM owners
INNER JOIN cats_owners
ON owners.id = cats_owners.owner_id
JOIN cats ON cats_owners.cat_id = cats.id
WHERE cats_owners.owner_id = 2;
# which will return the following
SUM(cats.net_worth)
-------------------
TABLE: cats
id name age breed net_worth
---------- ---------- ---------- ------------- ----------
1 Maru 3 Scottish Fold 1000000
2 Hana 1 Tabby 21800
3 Grumpy Cat 4 Persian 181600
4 Lil\' Bub 2 Tortoiseshell 2000000
===============================================================
||
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
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
class Show
attr_accessor :stand_up, :club
@@all = []
def initialize(stand_up, club)
@stand_up = stand_up
@club = club
@@all << self
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 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
// 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);
function grabber(resource, fakeStatus) {
return new Promise((resolve, reject) => {
window.setTimeout(() => {
if (fakeStatus === 200) {
resolve(`load ${resource}`)
} else {
reject("Error")
}
}, 3000);
});