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 / 0. How you should not write code - 2.md
Created March 5, 2021 17:16
How you should not write code-2

How you should not write code | JavaScript Part-II

@deepakshrma
deepakshrma / even-odd-generator.js
Last active October 16, 2021 11:03
even-odd-generator.js
const fill = function* (start = 0, end = 100, filter = (_) => true, mapper = (x) => x) {
while (start < end) {
if (filter(start))
yield start;
mapper(start++);
}
};
const isEven = (num) => num % 2 === 0;
const isOdd = (num) => num % 2 !== 0;
const evens = [...fill(0, 100, isEven)];
@deepakshrma
deepakshrma / App.tsx
Last active October 25, 2021 15:41
Download PDF/View/Display using react
import React, { useEffect, useState } from "react";
import { Document, Page } from "react-pdf/dist/esm/entry.webpack";
import "./App.css";
let fnGetFileNameFromContentDispostionHeader = function (header: string = "") {
let contentDispostion = header.split(";");
const fileNameToken = `filename*=UTF-8''`;
let fileName = "downloaded.pdf";
for (let thisValue of contentDispostion) {
if (thisValue.trim().indexOf(fileNameToken) === 0) {
fileName = decodeURIComponent(
[
{
"id": "0",
"level": "2",
"summary": "I dare you to Stand up for 2 turns",
"time": "",
"turns": "2",
"type": "Dare"
},
{
@deepakshrma
deepakshrma / truth-dare.py
Created November 21, 2021 21:40
Code for Truth and Dare game
#!/usr/bin/python3
import json
from urllib.request import urlopen
import random
def print_logo(): printline("""
_________ __ __________ __
/_ __/ _ \/ / / /_ __/ // /
@deepakshrma
deepakshrma / 01-date.js
Last active November 24, 2021 15:19
JavaScript Weird Part: Working with Date code samples
/**
* today: Get the current date
*/
exports.today = () => new Date();
// main.js
const { today } = require("./date");
console.log(today()); // 2021-08-22T15:59:47.482Z
@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: {
@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 / 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-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;