Skip to content

Instantly share code, notes, and snippets.

View amkhrjee's full-sized avatar

Aniruddha Mukherjee amkhrjee

View GitHub Profile
@amkhrjee
amkhrjee / SSRvsSSGvsCSR.md
Created March 9, 2022 13:40
Different Types of Websites

What the heck is Tree Shaking?

Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code. (Like shaking a tree to get rid of the dead leaves/fruits).

It relies on the import and export statements in ES2015 to detect if code modules are exported and imported for use between JavaScript files.

In modern JavaScript applications, we use module bundlers (e.g., webpack or Rollup) to automatically remove dead code when bundling multiple JavaScript files into single files. This is important for preparing code that is production ready, for example with clean structures and minimal file size.

A Json Web Token made up of three parts. The header, the payload and the signature Now the header is just some metadata about the token itself and the payload is the data that we can encode into the token, any data really that we want. So the more data we want to encode here the bigger the JWT. Anyway, these two parts are just plain text that will get encoded, but not encrypted.

So anyone will be able to decode them and to read them, we cannot store any sensitive data in here. But that's not a problem at all because in the third part, so in the signature, is where things really get interesting. The signature is created using the header, the payload, and the secret that is saved on the server.

And this whole process is then called signing the Json Web Token. The signing algorithm takes the header, the payload, and the secret to create a unique signa

When encrypting, you use their public key to write a message and they use their private key to read it.

When signing, you use your private key to write message's signature, and they use your public key to check if it's really yours.

I want to use my private key to generate messages so only I can possibly be the sender.

I want my public key to be used to read the messages and I do not care who reads them

This is signing, it is done with your private key.

@amkhrjee
amkhrjee / PowerShellConfig.ps1
Last active December 22, 2022 19:57
My Powershell config with Oh-My-Posh and other customizations
oh-my-posh init pwsh --config $env:POSH_THEMES_PATH\craver.omp.json | Invoke-Expression
Import-Module PSReadLine
Import-Module z
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
Import-Module -Name Terminal-Icons

Types of errors

Regression Testing

Something that works for first phase of time but then breaks.

Testing Levels

  • System: Test the whole system (aka E2E -> End to End Testing)
  • Integration: Test a couple of components together
  • Unit: Test a single unit

The Testing Pyramid

CORS

CORS (Cross-Origin Resource Sharing) is a system, consisting of transmitting HTTP headers, that determines whether browsers block frontend JavaScript code from accessing responses for cross-origin requests.

The same-origin security policy forbids cross-origin access to resources. But CORS gives web servers the ability to say they want to opt into allowing cross-origin access to their resources.

Read this.

Origin

Web content's origin is defined by scheme(protocol), hostname (domain), and port of the URL used to access it. Two objects have the same origin only when the scheme, hostname, and port all match.

Some operations are restricted to same-origin content, and this restriction can be lifted using CORS.

Examples

These are same origin because they have the same scheme (http) and hostname (example.com), and the different file path does not matter:

  • http://example.com/app1/index.html
  • http://example.com/app2/index.html

Functional Motion

  • Improve usablity & ux
  • drag & drop
  • animated hover & click states

Structural Motion

  • elemets moving on & off screen
  • items growing to detail views
  • modals, dropdowns, tooltips
  • parallax
@amkhrjee
amkhrjee / web_servers.md
Created February 13, 2022 11:04
Web Servers

Web Servers

Web Servers are software that do these things at the very basic:

  1. Listens
  2. On a port
  3. For a request
  4. via a Transport protocol
  5. gives Response
  6. with the Resources