Skip to content

Instantly share code, notes, and snippets.

View ilyahuman's full-sized avatar
🏠
Working from home

Ilya Human ilyahuman

🏠
Working from home
View GitHub Profile

Interview Questions

Node.js

Q1: What do you mean by Asynchronous API? ☆☆

Answer: All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.

Source: tutorialspoint.com

@boxgames1
boxgames1 / observable-pattern-pizza.js
Last active April 22, 2022 06:40
Observable pattern - Pizza Maker
const EventEmitter = require("events").EventEmitter;
class Pizza extends EventEmitter {
constructor(size = 1) {
super();
this.ovenTime = this._ovenTime(size);
this.maxIngredients = this._maxIngredients(size);
this.ingredients = [];
this.timeToReleasePizza = 5;
}
import { useRef, useState } from 'react'
function useUndo([state, setState]) {
const history = useRef([state])
const [index, setIndex] = useState(0)
function undo() {
setIndex(Math.max(index - 1, 0))
}
function redo() {
// We want to subscribe to some data. Here are 2 ways to do the SAME thing.
// 1. setup some state
// 2. subscribing to a uid, set posts when they come in
// 3. unsubscribing when the component unmounts
// 4. when the uid changes:
// - unsubscribing from prev uid
// - re-subscribing to the new uid
// Here's a render prop:
@mjackson
mjackson / useStorage.js
Last active November 4, 2021 06:36
A React hook for persisting state between page refreshes (also SSR compatible)
import { useEffect, useRef } from 'react';
function getItem(storage, key) {
const value = storage.getItem(key);
if (!value) return null;
try {
return JSON.parse(value);
} catch (error) {
@dmitriy-novikov
dmitriy-novikov / infer-value-types.ts
Last active November 5, 2020 12:52
Action Type Inference
import * as actions from 'action-creators';
// Тип, который берет action-creators, выводит типы всех экшенов по отдельности и собирает их в union
type InferValueTypes<T> = T extends { [key: string]: infer U }
? U
: never;
type ActionTypes = ReturnType<InferValueTypes<typeof actions>>;
@simonrelet
simonrelet / asynchronous.js
Last active March 18, 2023 20:13
React hooks for asynchronous calls
import React from 'react'
/**
* @typedef {object} State The state of asynchronous hooks.
* @property {object | null} error The error.
* @property {boolean} pending Whether the call is pending.
* @property {any | null} result The result of the asynchronous call.
*/
/** @type {State} */
@zmts
zmts / tokens.md
Last active April 16, 2024 13:37
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active April 17, 2024 18:56
Vanilla JavaScript Quick Reference / Cheatsheet