Skip to content

Instantly share code, notes, and snippets.

View nurmdrafi's full-sized avatar
:octocat:
Focusing

Nur Mohamod Rafi nurmdrafi

:octocat:
Focusing
View GitHub Profile
@nurmdrafi
nurmdrafi / secret.md
Created June 11, 2024 10:56
Hello Raju
@nurmdrafi
nurmdrafi / Socket.IO.md
Last active June 14, 2024 15:49
Socket.IO Handbook

https://shav.dev/blog/socket-io-and-redux-middleware

What is Socket.io?

Socket.IO is a Javascript lirary that enables real-time, bidirectional communication between web clients (browsers) and servers. It simplifies the process of bulding interactive web applications by allowing data to be transmitted instantly and continuously between the client and server, facilitating features like chat applications, live updates, and multiplayer gamimg.

What is Bidirectional Communication?

Bidirectional communication means that information can flow in two directions, both the web client(browser) and the server can send and receive data to and from each other in real-time. So if something changes on the server, it can immediately notify the client, and vice versa, without the client needing to constantly ask the server if there's new information available.

Analogy

Think of bidirectional communication like a phone call. When you're talking on the phone with someone, you can both speak and listen at the same t

@nurmdrafi
nurmdrafi / notification.md
Created May 4, 2024 16:33
Push Notification R&D

// Sending and receiving push messages

  1. if user grant notification permission, the user subscribes to the push service
  2. the push service returns a subscription object, which includes a public key to enable messages to be encrypted and an endpoint URL for the browser's push service, which is unique for each user
  3. send push messages from this URL from server, encrypted with the public key and the push service forward this message to the right client, device and browser
  4. service worker handle the push messages, when a push event is fired shows up message

// subscribe to the push service

navigator.serviceWorker.getRegistration().then(reg => {

@nurmdrafi
nurmdrafi / Render Customize Map Styles Using Hooks.md
Created April 29, 2024 05:58
Render Customize Map Styles Using Hooks

useCustomMapStyles.ts

import { useState, useEffect } from 'react'
import { MAP_API_ACCESS_TOKEN } from '../app.config'

const useCustomMapStyles = () => {
  // States
  const [mapStyles, setMapStyles] = useState<any>([])

  // On Load Fetch Map Styles
@nurmdrafi
nurmdrafi / Update software version with time using script.md
Created April 28, 2024 05:12
Update software version with time using script

add this update-version.js file inside utils folder

const fs = require('fs')
let packageJson = require('../package.json')

// Current Time
const now = new Date()
@nurmdrafi
nurmdrafi / Basic NGINX Config.md
Created April 22, 2024 11:08
Basic NGINX Config

Create File

sudo nano /etc/nginx/sites-available/test

Basic Config

If project running on server using docker or pm2
server {
 listen 80;
@nurmdrafi
nurmdrafi / Building a Progressive Web App (PWA) in Next.js.md
Last active May 4, 2024 16:33
Building a Progressive Web App (PWA) in Next.js

Related Docs

Benefits of Progressive Web App (PWA)

  1. Offline Functionality: PWAs can operate seamlessly offline, providing users with uninterrupted access to content and functionality even in low or no connectivity environments. This is achieved through service workers, enabling cached content to be served when the network is unavailable.
@nurmdrafi
nurmdrafi / NextJS Content Security Policy.md
Last active April 22, 2024 11:19
NextJS Content Security Policy
@nurmdrafi
nurmdrafi / swapfile.md
Created April 9, 2024 06:19
Create, Resize, or Extend a Linux Swap File
# check memory
$ free

# check swap file location, (default location - '/')
$ swapon

# turn off swap using swapfile location
$ sudo swapoff /swapfile
@nurmdrafi
nurmdrafi / Github Actions Workflow Example.md
Last active April 22, 2024 11:06
Github Actions Workflow Example

NextJS Deploy with Docker

name: Docker Image CI/CD for Staging

on:
  push:
    branches: ["staging"]

env: 
  DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}