Skip to content

Instantly share code, notes, and snippets.

View samundrak's full-sized avatar
👽
(function () { return 'Hello World' }) ()

Samundra Khatri samundrak

👽
(function () { return 'Hello World' }) ()
View GitHub Profile
@samundrak
samundrak / current-focus-element.js
Created February 24, 2021 10:46
Will continuously console log current active element
window.addEventListener('focusin',() => {
console.log(document.activeElement)
})
@samundrak
samundrak / convert-all-images-in-folder.js
Last active January 25, 2021 16:55
Will scan given directory and convert the image by extension.
#! /usr/bin/env node
const glob = require("glob");
const sharp = require("sharp");
glob("./data/**/*.+(jpeg|png)", (err, files) => {
Promise.allSettled(
files.map((file) => {
const link = file.split("/");
link.pop();
const newFile = `${link.join("/")}/main.jpeg`;
@samundrak
samundrak / react.js
Last active November 22, 2019 09:13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./style.css">
<title>Adopt Me</title>
</head>
@samundrak
samundrak / FontUploadForm.tsx
Last active December 21, 2021 11:35
Formik, ReactHooks, TypeScript, Antd
import React, { useState, useReducer } from 'react';
import {
Form as FormikForm,
Formik,
Field,
FieldProps,
ErrorMessage,
} from 'formik';
import { Form, Upload, Button, Icon, AutoComplete } from 'antd';
import SimpleError from './SimpleError';
@samundrak
samundrak / gist:e562037915ba4d4e67647b43f30af8e5
Created July 8, 2019 17:45 — forked from ichord/gist:9808444
demo of using pdf.js to extract pages to images
<script src="http://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing-api.min.js"></script><html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/pdfjs-helloworld-v2/8598/edit
-->
<body>
<canvas id="the-canvas" style="border:1px solid black"></canvas>
<input id='pdf' type='file'/>
<!-- Use latest PDF.js build from Github -->
const collection = [
{ name: 'samundra', rank: 3 },
{ name: 'abina', rank: 5 },
{ name: 'hari', rank: 1 },
{ name: 'bibek', rank: 2 },
{ name: 'suman', rank: 4 },
];
function sortBy(collection, compareBy) {
return collection.sort((item, lastItem) => {
function flat(arr, carryOverArray = []) {
arr.forEach(element => {
if (Array.isArray(element)) {
flat(element, carryOverArray);
} else {
carryOverArray.push(element);
}
});
return carryOverArray;
}
function insertInArray(string, index, arr) {
const sliceBefore = arr.slice(0, index);
const sliceAfter = arr.slice(index, arr.length);
return sliceBefore.concat([string], sliceAfter);
}
function differ(arr1, arr2) {
const diff = [];
arr2.forEach((element, index) => {
@samundrak
samundrak / gist:efe0d273187f1f5f201f7317cb35cf0e
Created November 15, 2018 12:19
node-graphql-apollo-boost
import 'cross-fetch/polyfill';
import ApolloClient, { gql } from 'apollo-boost';
import 'dotenv/config';
const client = new ApolloClient({
uri: 'https://api.github.com/graphql',
request: operation => {
operation.setContext({
headers: {
authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`,
@samundrak
samundrak / outerJoinArray.js
Created August 16, 2018 07:07
Outer Join of array in js using Map, Set, Array
const a = [
{ id: 3, name: 'Matt' },
{ id: 4, name: 'Greg' },
{ id: 1, name: 'David' },
{ id: 2, name: 'John' },
];
const b = [
{ id: 7, position: 'Outlier' },
{ id: 2, position: 'Leader' },
{ id: 3, position: 'Captain' },