Skip to content

Instantly share code, notes, and snippets.

View johnsoncherian's full-sized avatar

Johnson Cherian johnsoncherian

View GitHub Profile
@mfehrenbach
mfehrenbach / chrome-device-dimensions.md
Last active November 19, 2024 19:17
Modern device dimensions for Chrome DevTools.

Modern Device Dimensions for Chrome DevTools

These are modern “Emulated Devices” (a.k.a. responsive dimensions) for Chrome DevTools’ Mobile Device Viewport Mode.

They are specifically Apple devices, subtracting for recent Safari UI (as in window.innerWidth/Height), and cleverly sorted with some dark-arts unicode shenanigans. (This glitchy, unloved portion of the tools sorts lexicographically, because of course it would.) Ergonomics!

before-after

Nest Hub Max? Come on. I dropped a bunch of devices that were older and/or close to these dimensions. It obviously doesn’t cover everything (sorry Android/Chrome), but offers a decent spread/increments for common 2023/2024 viewports.

@zcaceres
zcaceres / Include-in-Sequelize.md
Last active July 27, 2024 13:21
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

@mlocati
mlocati / color-scale.js
Last active October 25, 2024 13:11
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
// License: MIT - https://opensource.org/licenses/MIT
// Author: Michele Locati <[email protected]>
// Source: https://gist.github.com/mlocati/7210513
function perc2color(perc) {
var r, g, b = 0;
if(perc < 50) {
r = 255;
g = Math.round(5.1 * perc);
}
else {