Skip to content

Instantly share code, notes, and snippets.

View zcaceres's full-sized avatar
👨‍💻
programming

Zach Caceres zcaceres

👨‍💻
programming
View GitHub Profile
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active April 2, 2025 06:07
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

@zcaceres
zcaceres / Error-Handling-Patterns-Express.md
Last active August 3, 2023 13:40
error handling patterns in Express

Handling Errors

Express.js makes it a breeze to handle errors in your routes.

Express lets you centralizes your error-handling through middleware.

Let's look at patterns for how to get the most out of your error-handling.

First, our error-handling middleware looks like this:

Web Security: Defense Against the Dark Arts

  1. Authentication: are they who they say they are?
  2. Communication: transferring data through unreliable middleman
  3. Authorization: giving resource access to the right people
  4. Control: avoiding unexpected open-endedness in your app. Limiting capabilities of agents.

OWASP

  • Injection: server-side code execution
  • Broken Authentication: allows for impersonation
@zcaceres
zcaceres / curriculum-review.md
Created April 14, 2017 21:54
Curriculum Review notes

Passport

dependency injection

first class functions: functions are an object and can be passed to other functions

Sorting algos:

  • memorize
@zcaceres
zcaceres / Returning-in-Sequelize.md
Last active June 6, 2024 07:21
Using `Returning` with Sequelize and Postgres

Using Returning with Sequelize and Postgres

Some Sequelize commands don't return anything (or at least not anything useful) by default. Sequelize uses an option called returning to specify which data returns from a commands like .destroy() or update().

Let's look at three common Sequelize commands and see how to handle the data returned by each.

Create

By default, .create() returns the newly created instance. This is convenient, because we can then send data to the user:

@zcaceres
zcaceres / 12-principles.md
Created May 16, 2017 18:58
Gregg Pollack's 12 Principles
  1. Expectations. Incorrect expectations are often why things fail.
  • Get client closer to the team
  • Short feedback cycles (weekly communication and estimates to keep project spec up to date)
  • Project management tools
  1. Be mindful of your inner problem-solver Someone comes to you with an idea, don't shoot it down by 'diagnosing' all the problems.
@zcaceres
zcaceres / security-tips.md
Last active May 17, 2017 02:27
Security Tips from NCC

Security Tips from NCC

Intro

Internet is huge, processed 1 zettabyte (insanely huge).

Your data is being siphoned up, but NSA may not be watching you.

James Mickens "This World Of Ours"

Practice Good OpSec (Operational Security)

@zcaceres
zcaceres / Data-structures-and-algos-greatest-hits.md
Last active March 23, 2023 14:00
Data Structures and Algorithms: The Greatest Hits

Data Structures and Algorithms: The Greatest Hits

Relevant Chapters from CTCI

  • Arrays and Strings (1)
  • Linked Lists (2)
  • Stacks and Queues (3)
  • Trees and Graphs (4)
  • Bit Manipulation (5)
  • Math and Logic Puzzles (6)
  • Recursion and Dynamic Programming (8)
// musicPlayerModule.js

var musicPlayer = function () {
  // Let's make sure no one can directly access our songList
  var songList = ['California Girls', 'California Dreaming', 'Hotel California'];  

  // We'll expose all these functions to the user
  function play () {