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 / index.js
Created July 4, 2020 11:00
deno momet bundle
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// This is a specialised implementation of a System module loader.
"use strict";
// @ts-nocheck
/* eslint-disable */
let System, __instantiate;
(() => {
@deepakshrma
deepakshrma / index.ts
Created July 4, 2020 10:59
deno moment sample
import moment from "https://cdn.pika.dev/moment@^2.26.0";
export function greet(name: string) {
return `Hello, Mr./Ms. ${name}`;
}
export function formattedDate() {
const todayMoment = moment(new Date());
const todayFormatted = todayMoment.format("MM/DD/YYYY hh:mm a");
return todayFormatted;
}
formattedDate()
@deepakshrma
deepakshrma / sample_employee.csv
Created June 6, 2020 07:12
Sample Employee CSV
Serial Number Company Name Employee Markme Description Leave
9788189999599 TALES OF SHIVA Mark mark 0
9780099578079 1Q84 THE COMPLETE TRILOGY HARUKI MURAKAMI Mark 0
9780198082897 MY KUMAN Mark Mark 0
9780007880331 THE GOD OF SMAAL THINGS ARUNDHATI ROY 4TH HARPER COLLINS 2
9780545060455 THE BLACK CIRCLE Mark 4TH HARPER COLLINS 0
9788126525072 THE THREE LAWS OF PERFORMANCE Mark 4TH HARPER COLLINS 0
9789381626610 CHAMarkKYA MANTRA Mark 4TH HARPER COLLINS 0
9788184513523 59.FLAGS Mark 4TH HARPER COLLINS 0
9780743234801 THE POWER OF POSITIVE THINKING FROM Mark A & A PUBLISHER 0
@deepakshrma
deepakshrma / safe_eval.ts
Last active May 20, 2020 17:03
Utils in typescript
const evalReg = /(\.)|(\[(\d)\])/;
const safeEval = (key: string, obj: any) => {
let lastKey;
let match;
do {
if (lastKey) {
if (match && match[2]) {
obj = obj[lastKey][match[3]];
} else {
obj = obj[lastKey];
@deepakshrma
deepakshrma / json_sample.json
Last active May 20, 2020 16:58
JSON Sample
{
"id": 1,
"version": "1.0.1",
"contributors": [
"deepak",
"gary"
],
"actor": {
"name": "Tom Cruise",
"age": 56,
@deepakshrma
deepakshrma / Enum.js
Last active May 10, 2020 09:05
Basic implementation of Enum of typescript in vanila javascript.
class Enum {
constructor(args, startIndex = 0, defaultValue) {
const em = args.split("|").reduce((m, key, index) => {
m[(m[key] = index + startIndex)] = key;
return m;
}, {});
em.value = em.key = (k) => em[k];
return new Proxy(em, {
get: (obj, prop) => (prop in obj ? obj[prop] : defaultValue),
set: (obj, prop, value) => {
@deepakshrma
deepakshrma / nodejs_init.js
Last active December 28, 2023 09:41
Init nodejs config like[prettier, husky]
/*
// How to use
curl -s https://gist.githubusercontent.com/deepakshrma/c77d297d5ff3e07ce172da2893bb49d0/raw/835f004cf234cf3a79fab1bd1b37df7db861773b/nodejs_init.js -O nodejs_init.js || node nodejs_init.js
*/
const path = require("path");
const fs = require("fs");
const cwd = process.cwd();
const fromRoot = (...args) => path.join(cwd, ...args);
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="app.css">
<style>
td {
border: 1px solid;
class TicTac {
constructor() {
this.mat = [
[-1, -1, -1],
[-1, -1, -1],
[-1, -1, -1],
];
}
move(i, j, m) {
m ? this.moveX([i, j]) : moveO([i, j]);
@deepakshrma
deepakshrma / stackoverflow.js
Last active April 2, 2020 13:48
stackoverflow
const snippets = [
{
scope: "javascript,typescript",
prefix: "st_key_map",
body: `const mapKeys = (obj, fn) => {
let mapper = fn;
if (typeof fn === "string") mapper = x => x[fn];
return Object.keys(obj).reduce((acc, k) => {
acc[mapper(obj[k], k, obj)] = obj[k];
return acc;