Skip to content

Instantly share code, notes, and snippets.

View lusan's full-sized avatar
🎯
Focusing

Lusan Das lusan

🎯
Focusing
View GitHub Profile
@lusan
lusan / HttpStatusCode.ts
Created July 17, 2023 05:26 — forked from scokmen/HttpStatusCode.ts
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
import React from 'react';
class AsyncComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
component: null,
error: null
}
@lusan
lusan / asyncLocalStorage.js
Created September 16, 2021 04:26
async localstorage
// Source: https://stackoverflow.com/questions/42921220/is-any-solution-to-do-localstorage-setitem-in-asynchronous-way-in-javascript
// localStorage is a synchronous API. You could defer the setItem method execution with the Promise object, giving them an asynchronous behaviour:
const asyncLocalStorage = {
setItem: function (key, value) {
return Promise.resolve().then(function () {
localStorage.setItem(key, value);
});
},
@lusan
lusan / soFetch.js
Created September 7, 2021 12:10 — forked from wayanjimmy/soFetch.js
Reusable fetch function from wesbos
// https://twitter.com/wesbos/status/1063515277911052290/photo/1
async function soFetch(input, settings = {}) {
const response = await fetch(input, {
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
...settings
});
@lusan
lusan / events.json
Created March 15, 2021 08:16
calendar events json
[
{
"date": "2020-01-01",
"events": [
{
"name": "Meeting with Ivan",
"time": "2020-01-01 09:28:13 +0530",
"duration_minutes": 15,
"accepted": false
},
export default {
pageTitle: 'iPhone 12',
results: [
{
id: Date.now(),
imageSrc: 'https://rukminim1.flixcart.com/image/300/350/kg8avm80/mobile/y/7/n/apple-iphone-12-dummyapplefsn-original-imafwg8dqq7z8cgh.jpeg?q=90',
title: 'Apple iPhone 12 (White, 128 GB)',
rating: {
value: 4.7,
count: 545
export default {
pageTitle: 'iPhone 12 64 GB',
product: {
id: Date.now(),
imageSrc: 'https://rukminim1.flixcart.com/image/300/350/kg8avm80/mobile/y/7/n/apple-iphone-12-dummyapplefsn-original-imafwg8dqq7z8cgh.jpeg?q=90',
title: 'Apple iPhone 12 (White, 128 GB)',
rating: {
value: 4.7,
count: 545
},
// https://codepen.io/bradtraversy/pen/Bwapow
var form = document.getElementById('addForm');
var itemList = document.getElementById('items');
var filter = document.getElementById('filter');
// Form submit event
form.addEventListener('submit', addItem);
// Delete event
itemList.addEventListener('click', removeItem);
@lusan
lusan / domBasics.js
Created July 25, 2019 13:18
How to traverse and move around the DOM with properties like parentNode, parentElement, nextElementSibling and so on. We will also learn how to insert elements with createElement() and createTextNode()
// Traversy Media
// Original Video link https://www.youtube.com/watch?v=mPd2aJXCZ2g
// EXAMINE THE DOCUMENT OBJECT //
// console.dir(document);
// console.log(document.domain);
// console.log(document.URL);
// console.log(document.title);
// //document.title = 123;
// console.log(document.doctype);
@lusan
lusan / deepCloneObject.js
Created July 5, 2019 13:54
Deep clone object polyfill
function deepClone(object){
var newObject = {};
for(var key in object){
if(typeof object[key] === 'object' && object[key] !== null ){
newObject[key] = deepClone(object[key]);
}else{
newObject[key] = object[key];
}
}
return newObject;