Skip to content

Instantly share code, notes, and snippets.

View krfong916's full-sized avatar
🦁
Organizing for a brighter future

Kyle Fong krfong916

🦁
Organizing for a brighter future
  • University of California, Santa Cruz
View GitHub Profile
@chooie
chooie / 3_things_ive_learned_in_5_years_of_javascript_software_development.md
Last active January 4, 2022 01:17
3 things I've learned in 5 years of JavaScript Software Development

3 things I've learned in 5 years of JavaScript Software Development

Code should lead with the higher-level concepts. The lower-level pieces should follow

Don't force the reader of your code to scroll past the minutiae.

function makeBreakfast() {
  const ingredients = fetchIngredients();
  const friedBacon = fryBacon(ingredients.bacon);
  const cookedScrambledEggs = whiskEggsAndFryThem(ingredients.eggs);
 const preparedMeal = plateAndSeasonMeal(friedBacon, cookedScrambledEggs);
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var domStyle = document.createElement("style");
domStyle.append(
'* { color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }\
* * { background-color: rgba(0,255,0,.2) !important; }\
* * * { background-color: rgba(0,0,255,.2) !important; }\
* * * * { background-color: rgba(255,0,255,.2) !important; }\
* * * * * { background-color: rgba(0,255,255,.2) !important; }\
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var styleEl = document.getElementById('css-layout-hack');
if (styleEl) {
styleEl.remove();
return;
}
styleEl = document.createElement('style');
styleEl.id = 'css-layout-hack';
@stemmlerjs
stemmlerjs / aggregate-or-domain-services.ts
Last active March 24, 2021 21:50
An example of the trade offs using either aggregates or using domain services to encapsulate business logic. Based on code from https://khalilstemmler.com/articles/typescript-domain-driven-design/ddd-vs-crud-design/
/*
* By designing the Customer as an Aggregate Root and including a reference all of the
* movies that it rented, we can place the validation logic for renting movies
* directly on the customer entity.
*
* Advantages: More declarative-reading code. The operation is a lot closer to the
* entity itself, which improves the discoverability and understanding what a customer
* can do.
*
* Disadvantages: Additional overhead. Having to pull the ids of rented movie everytime we
@gaearon
gaearon / uselayouteffect-ssr.md
Last active May 2, 2024 13:42
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {
@stevekinney
stevekinney / web-performance.md
Last active January 31, 2024 14:23
Web Performance Workshop

Web Performance

Requirements

Repositories

@zhirzh
zhirzh / multiple-inheritance.js
Created February 8, 2018 15:59
Multiple Inheritance in JS
function inheritsObject(baseObject, superObject) {
Object.setPrototypeOf(baseObject, superObject);
}
function inheritsMultipleObjects(baseObject, superObjects) {
inheritsObject(
baseObject,
new Proxy({}, {
get(target, key, rec) {
@nikgraf
nikgraf / .eslintrc.js
Last active July 12, 2019 19:11
Prettier / Eslint Setup
module.exports = {
root: true, // make to not take in any user specified rules in parent folders
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/flowtype', 'prettier/react'],
env: {
browser: true,
node: true,
jest: true,
},
plugins: ['flowtype'],
@rushilgupta
rushilgupta / GoConcurrency.md
Last active January 25, 2024 14:59
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines