Skip to content

Instantly share code, notes, and snippets.

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

Santosh Subedi SantoshCode

🏠
Working from home
View GitHub Profile
gcap() {
git add . && git commit -m "$*" && git push
}
# NEW.
gnew() {
gcap "📦 NEW: $@"
}
# IMPROVE.

Common Docker Command

Spin up a alpine container

$ docker run -it --name nodejs-alpine --rm alpine:3.10

--name -> giving custom name

const a = item => new Promise(resolve => setTimeout(() => resolve(item), 10))
const b = item => new Promise(resolve => setTimeout(() => resolve(item), 100))
const c = item => new Promise(resolve => setTimeout(() => resolve(item), 200))
// Parallel
const parallel = async () => {
const processes = [a(), b(), c()]
const [output1, output2, output3] = await Promise.all(processes)
return `parallel is done: ${output1} ${output2} ${output3}`

GraphQL over RestFul Api

Setting up an endpoint becomes messier as we go along with creating endpoints for nested relationsship

For Example endpoint for getting users friends of friends company, position

Making too many HTTP request

We need to make many request to get friends of friends company, position like

Understanding Container

How did we came down to Container or Why Container?

Bare Setup

Historically, in order to host website for a company they usually contact server/hardware providers to setup a sever farm. But this way had some serious down sides

  • Managing hardwares was pain in the a**.
  • Security risk, if we had another service to run in our server there was no any isolation, every service had access to do any thing with

Understanding React a bit more

"state dispatch function" accepts current state value as first parameter so use that

setCount(count + 1) --> Wrong way

Problem of using above approach

Next.js

The React Framework for Production (A fullstack framework for ReactJS)

By default React is a JavaScript library for building user interfaces

NextJS solves common problems and makes building React apps easier!

In React, for routing we have to use third party libraries for handling various features like for routing we might use react-router-dom.

@SantoshCode
SantoshCode / RerenderComponent.md
Last active May 16, 2021 16:26
How to re-render a component even on memoization like when using selectors

How to re-render a component even on memoization like when using selectors?

Afte the task has been done simply reset the state but useEffect dependency should have memoized state as dependency

e.g.

if (taskIsCompleted){
  dispatch({type: "RESET_STATE"})
}
@SantoshCode
SantoshCode / settings.json
Created May 10, 2021 11:35
Clean vscode setup
{
"workbench.iconTheme": "material-icon-theme",
"files.autoSaveDelay": 5000,
"editor.wordWrap": "off",
// "editor.fontFamily": "'SF Mono','Fira Code','Operator Mono','Monolisa','Cascadia Code','JetBrains Mono', 'monospace', 'Droid Sans Fallback','Segoe Ui Emoji','Noto Color Emoji'",
"workbench.colorCustomizations": {
// "editorGutter.addedBackground": "#141A1F",
// "editorGutter.modifiedBackground": "#141A1F",
// "editorGutter.background": "#141A1F"
@SantoshCode
SantoshCode / jwt.md
Created May 8, 2021 04:08
JSON Web Tokens

JSON Web Tokens

What are JSON Web Tokens?

  • Open-source industry standart (RFC-7519).
  • Usable for Authorization or secure exchange of information bretween parties.
  • Verify that the sender is who it/he/she claims to be.
  • Signed by the issuer, using a secret or keypair (HMAC algorithm, RSA or ECDSA).

JWT Structure