Skip to content

Instantly share code, notes, and snippets.

{
"recent-launches": {
"recent-launch1": {
"course_id": 312,
"title": "Terence Tao Teaches Mathematical Thinking",
"slug": "terence-tao-teaches-mathematical-thinking",
"universal_link": "https://www.masterclass.com/classes/312",
"vanity_name": "TT",
"instructor_name": "Terence Tao",
"teaches": "Mathematical Thinking",
{"data":{"courses":{"terence-tao-teaches-mathematical-thinking":{"course_id":312,"title":"Terence Tao Teaches Mathematical Thinking","slug":"terence-tao-teaches-mathematical-thinking","universal_link":"https://www.masterclass.com/classes/312","vanity_name":"TT","instructor_name":"Terence Tao","teaches":"Mathematical Thinking","class_persona":null,"overview_text":"World-renowned mathematician Dr. Terence Tao teaches you his approach to everyday problem-solving—without complex equations or formulas.","course_header_image":"https://www.masterclass.com/course-images/attachments/ejmrzq89p4zpxdgih9327bk7cn1r","course_headshot":"https://www.masterclass.com/course-images/attachments/vyo6j7ix3zs1bcpegd1aest38fp9","5x12_image":"https://www.masterclass.com/course-images/attachments/3udqajqs3z7vvqiqbm54eprttjda","skill_1":"Math Fails","skill_1_img":"https://www.masterclass.com/course-images/attachments/mnyqbotlwy7erc123ksn2b86rynm","skill_2":"Stumped","skill_2_img":"https://www.masterclass.com/course-images/attachments/o
@brunvez
brunvez / auto-rspec
Last active August 18, 2020 17:52 — forked from timcour/auto-rspec
Automatically find and run specs corresponding to changed and new files or terms passed in.
#!/bin/bash
#
# Automatically find and run specs corresponding to changed files or
# terms passed in.
#
CMD="bin/rspec"
function usage {
echo "Usage: $0 [match terms]"
@brunvez
brunvez / client.js
Created June 15, 2020 15:09
IoT simple mock using Mosquitto
const mqtt = require('mqtt')
let client
const DEVICE_ID = '12345-abcd-el-propio'
/**
* Simulating the device's setup function/
*/
function setup() {
client = mqtt.connect('mqtt://test.mosquitto.org')
}
@brunvez
brunvez / n_2_belongs_to_solved.sql
Created June 7, 2020 02:57
Rails N + 2 Queries - N + 2 Belongs To Solved
Post Load (0.4ms) SELECT "posts".* FROM "posts"
Comment Load (0.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" IN ($1, $2, $3, $4, $5) ORDER BY "comments"."likes" DESC [["post_id", 1], ["post_id", 2], ["post_id", 3], ["post_id", 4], ["post_id", 5]]
@brunvez
brunvez / domain_with_belongs_to.rb
Created June 7, 2020 02:55
Rails N + 2 Queries - Domain with belongs to
class Post < ApplicationRecord
has_many :comments
has_many :uncensored_comments, -> { where(censored: false) }, class_name: 'Comment'
# rails will automatically limit the number of records for us
has_one :most_liked_comment, -> { order(likes: :desc) }, class_name: 'Comment'
end
@brunvez
brunvez / n_2_belongs_to.sql
Created June 7, 2020 02:54
Rails N + 2 Queries - N + 2 belongs to
Post Load (0.4ms) SELECT "posts".* FROM "posts"
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 ORDER BY "comments"."likes" DESC LIMIT $2 [["post_id", 1], ["LIMIT", 1]]
Comment Load (0.7ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 ORDER BY "comments"."likes" DESC LIMIT $2 [["post_id", 2], ["LIMIT", 1]]
Comment Load (0.6ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 ORDER BY "comments"."likes" DESC LIMIT $2 [["post_id", 3], ["LIMIT", 1]]
Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 ORDER BY "comments"."likes" DESC LIMIT $2 [["post_id", 4], ["LIMIT", 1]]
Comment Load (0.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 ORDER BY "comments"."likes" DESC LIMIT $2 [["post_id", 5], ["LIMIT", 1]]
@brunvez
brunvez / n_2_solved.sql
Created June 7, 2020 02:53
Rails N + 2 Queries - N + 2 solved
Post Load (0.5ms) SELECT "posts".* FROM "posts"
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE "comments"."censored" = $1 AND "comments"."post_id" IN ($2, $3, $4, $5, $6) [["censored", false], ["post_id", 1], ["post_id", 2], ["post_id", 3], ["post_id", 4], ["post_id", 5]]
@brunvez
brunvez / domain_with_association.rb
Created June 7, 2020 02:51
Rails N + 2 Queries - Domain with association
class Post < ApplicationRecord
has_many :comments
# we need to specify a new name, a lambda to filter the comments and the model class name
has_many :uncensored_comments, -> { where(censored: false) }, class_name: 'Comment'
end
@brunvez
brunvez / n_2_no_includes.sql
Created June 7, 2020 02:50
Rails N + 2 Queries - N + 2 no includes
Post Load (0.5ms) SELECT "posts".* FROM "posts"
Comment Load (6.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 AND "comments"."censored" = $2 [["post_id", 1], ["censored", false]]
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 AND "comments"."censored" = $2 [["post_id", 2], ["censored", false]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 AND "comments"."censored" = $2 [["post_id", 3], ["censored", false]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 AND "comments"."censored" = $2 [["post_id", 4], ["censored", false]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 AND "comments"."censored" = $2 [["post_id", 5], ["censored", false]]