Skip to content

Instantly share code, notes, and snippets.

View deepakshrma's full-sized avatar
🎯
Focusing

Deepak Vishwakarma deepakshrma

🎯
Focusing
View GitHub Profile
@deepakshrma
deepakshrma / react-flow-simple-traverse.js
Created August 1, 2022 14:26
react-flow Simple Tree Traverse
const data = {
nodes: [
{
width: 150,
height: 36,
id: "id_1",
data: { label: "Node 1" },
position: { x: 100, y: 100 },
positionAbsolute: { x: 100, y: 100 },
},
@deepakshrma
deepakshrma / js-observable.js
Created June 26, 2022 09:42
JavaScript Observable
const debounce = (fn, ms = 0) => {
let id;
return (...args) => {
if (id) clearTimeout(id);
id = setTimeout(() => fn(...args), ms);
};
};
const observable = (render) => {
const that = {};
const _render = debounce(render);
@deepakshrma
deepakshrma / Java01.java
Last active June 19, 2022 16:38
Working with XML Serialization and Response in Java and Kotlin
// imports
@SpringBootApplication
@RestController
public class XmlDemoApplication {
public static void main(String args[]) {
SpringApplication.run(XmlDemoApplication.class, args);
}
@RequestMapping(
value = "/xml",
method = RequestMethod.GET,
@deepakshrma
deepakshrma / DOMParserDemo.kt
Created June 11, 2022 11:05
XSD Parser Kotlin
import org.w3c.dom.Document
import org.xml.sax.SAXException
import org.xml.sax.SAXParseException
import org.xml.sax.helpers.DefaultHandler
import java.io.StringReader
import javax.xml.XMLConstants
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory
@deepakshrma
deepakshrma / 01-react.tsx
Last active May 4, 2022 15:59
Using Context and TypeScript to build an Alert Messenger in React.js
// index.tsx
import { StrictMode } from "react";
import ReactDOMClient from "react-dom/client";
import { createGlobalStyle, ThemeProvider } from "styled-components";
import App from "./App";
import { AlertContextProvider } from "./components/Alert/AlertContextProvider";
const Global = createGlobalStyle`
p,
h1,
h2,
@deepakshrma
deepakshrma / 01-read.py
Last active March 20, 2022 17:26
Reading Data with Python | Easy Learning
# Read entire file one time
page = ""
with open("app.log", 'r') as file:
page = file.read()
print(page)
"""
# Output
03/22 08:51:06 TRACE :...read_physical_netif: Home list entries returned = 7
03/22 08:51:06 INFO :...read_physical_netif: index #0, interface VLINK1 has address 129.1.1.1, ifidx 0
...
@deepakshrma
deepakshrma / 01-builderdemo.java
Last active February 26, 2022 10:22
Kotlin - Design Pattern In Easy Way | Creational Patterns
class Car {
String type;
String model;
String color;
int speed;
Car(String type, String model, String color) {
this.type = type;
this.model = model;
@deepakshrma
deepakshrma / final-interceptor.js
Created December 18, 2021 07:41
How To Write Services Using JavaScript
console.log("Welcome to How To Write Services Using JavaScript")
const http = {
cb: [],
intercept(cb) {
this.cb.push(cb);
},
async get(url, options = {}) {
return this.request(url, null, options)
},
@deepakshrma
deepakshrma / 01-fun.js
Last active October 27, 2022 16:21
Functional Programming In JavaScript-TypeScript for Beginners
function calculateInterest(p: number, t: number, r: number) {
return (p * t * r) / 100;
}
console.log(calculateInterest(1000, 5, 5));
//250
@deepakshrma
deepakshrma / 01-w-r-o.js
Last active November 28, 2021 17:45
Why React.js is overrated- codes
// Draft Service class
const services = {
fetchTodos: () =>
fetch("https://jsonplaceholder.typicode.com/todos/")
.then((d) => d.json())
.then((list) => list.slice(0, 5)), // Show last 5
createTodo: (todo) =>
fetch("https://jsonplaceholder.typicode.com/todos/", {
method: "POST",
headers: {