Skip to content

Instantly share code, notes, and snippets.

View aungthuoo's full-sized avatar
💭
I am looking for a job.

Aung Thu Oo @ Andrew Maung aungthuoo

💭
I am looking for a job.
View GitHub Profile
@aungthuoo
aungthuoo / 1. Simple example.md
Last active June 24, 2024 04:51
Node.js modular express application

To make express web application modular use router factories: Module:

// greet.js
const express = require("express");
module.exports = function (options = {}) {
  // Router factory
  const router = express.Router();
  router.get("/greet", (req, res, next) => {
 res.end(options.greeting);
@aungthuoo
aungthuoo / Basic routing without using express.md
Last active June 24, 2024 04:26
Node.js basic routing without using express.js

Node.js basic routing

const http = require("http");

var routes = {
  "/": function index(request, response) {
    response.writeHead(200);
    response.end("Hello, World!");
  },
 "/foo": function foo(request, response) {
@aungthuoo
aungthuoo / create-project.md
Last active June 24, 2024 03:44
hello-world-http-server.md
mkdir first-app 
cd first-app 
npm init 
touch index.js 

What is Throttling?

Quick notes (Using JavaScript )

Js code

// throttling
let count = 0;
function printScroll() {
  count += 1;
  console.log("scroll called", count);
}

JavaScript Promise

A promise is an object that will produce a single value sometime in the future. If the promise is successful, it will produce a resolved value, but if something goes wrong then it will produce a reason why the promise failed.

Simply said:- It behaves very much similar to real life promises.

// promises
let fruits = ["apple", "banana", "orange"];

const animateOne = (fruit, animate) => {

JavaScript Callback

A JavaScript callback is a function which is to be executed after another function has finished execution.

Simply said:- Any function that is passed as an argument to another function so that it can be executed in that other function is called as a callback function. This results in callback hell.

// callbacks an callback hell
let fruits = ["apple", "banana", "orange"];

Debounce with React.js search example with Github repo

Debouncing is a strategy used to improve the performance of a feature by controlling the time at which a function should be executed.

Simple words:- It delays the execution of your code until the user stops performing a certain action for a specified amount of time. It is a practice used to improve browser performance.

Debouncing is a technique used to limit the rate at which a function is invoked. In the context of search functionality, debounce can be incredibly useful. When a user types into a search bar, it triggers a function to update the search results. However, if this function is invoked every time a keystroke occurs, it can lead to performance issues, especially if the search involves fetching data from a server.

Debouncing is a technique used to limit the rate at which a function is invoked. In the context of search functionality, debounce can be incredibly useful. When a user types into a search bar, it triggers a function to u

Using Google's ReCaptcha V3 with NextJS 13 and the New App Router

Quick notes

React.js installation

npx create-next-app@latest my-recaptcha-app
cd my-recaptcha-app

npm install axios react-google-recaptcha-v3
npm run dev 
@aungthuoo
aungthuoo / Download.php
Last active June 10, 2024 06:23
Download a file using Laravel Livewire
<?php
use Livewire\Component;
class Download extends Component
{
public function download()
{
// get the path to the file
$path = "";

Feed data to the components using getInitialProps

In the previous chapter we had an issue with dynamically generating the post page, because the component required some data up front, and when we tried to get the data from the JSON file:

import { useRouter } from 'next/router'
import posts from '../../posts.json'

export default () => {
  const router = useRouter()

 const post = posts[router.query.id]