Skip to content

Instantly share code, notes, and snippets.

View technikhil314's full-sized avatar

Nikhil Mehta technikhil314

View GitHub Profile
@technikhil314
technikhil314 / generate.sh
Created May 15, 2021 10:16
shell script using imagemagick cli
#!/bin/bash
arr=( "user1"
"user2"
"user3"
)
for i in "${arr[@]}"
do
convert -font 'Sacramento' -fill '#CC6478' -pointsize 42 -gravity center -draw "text 90,-20 '$i'" template.png ./outputDir/$i.png
convert -font helvetica -fill '#444' -pointsize 18 -gravity northwest -draw "text 264,425 '15 Aug 2020'" ./outputDir/$i.png ./outputDir/$i.png
@technikhil314
technikhil314 / generateDigest.js
Last active November 30, 2023 09:55
Generate sha-256 hash using crypto in browsers
const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.';
async function digestMessage(message) {
const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
return hashHex;
}
@technikhil314
technikhil314 / jwtRS256.sh
Created April 30, 2021 05:41 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@technikhil314
technikhil314 / app.jsx
Created April 26, 2021 08:07
use-page-visibility react hook
import { useEffect, useRef } from "react";
import usePageVisibility from "./usePageVisibility";
export default function App() {
const isPageVisible = usePageVisibility();
const videoRef = useRef();
useEffect(() => {
videoRef.current.muted = false;
}, []);
useEffect(() => {
@technikhil314
technikhil314 / snippet.js
Created April 7, 2021 14:32
Unregister all service workers on chrome
// run the following script on chrome://serviceworker-internals/?devtools
const allUnregisterButtons = document.querySelectorAll(".unregister");
for(item of allUnregisterButtons) {
item.click();
}
@technikhil314
technikhil314 / index.js
Last active May 4, 2022 05:29
Flatten javascript object
let o = {
k: 10,
a: {
b: {
c: ["10", "20"]
},
},
d: {
e: 20
},
@technikhil314
technikhil314 / README.md
Last active March 22, 2021 09:44
Link with hover media

The problem

I have added two link elements in index.html as follows

<link media="(hover: none)" href="/touch.css" rel="stylesheet" type="text/css" />
<link media="(hover: hover)" href="/demo.css" rel="stylesheet" type="text/css" />

when I serve these files over localhost using lite-server I see following output

@technikhil314
technikhil314 / with-reduce-finite.js
Last active October 15, 2021 07:05
Flattern array self implementations
let depthTraversed = 1;
function flattenArray(arr, depth) {
return arr.reduce((acc, current) => {
if (Array.isArray(current)) {
if (depthTraversed > depth) {
acc = acc.concat([current]);
return acc;
}
depthTraversed++;
@technikhil314
technikhil314 / optimised.js
Created February 5, 2021 07:36
Closest sum tuple from two arrays
// O(a+b) := O(2n) := O(n)
function optimizedFindClosestSumTupple(arr1, arr2, requiredSum) {
const map = new Map();
let minDiff = Number.MAX_VALUE;
const result = [];
arr1 = arr1.sort((a, b) => a - b > 0 ? 1 : -1);
arr2 = arr2.sort((a, b) => a - b > 0 ? 1 : -1);
for (let l = 0, r = arr2.length - 1; l < arr1.length && r >= 0;) {
const sum = arr1[l] + arr2[r];
const diff = Math.abs(sum - requiredSum);
@technikhil314
technikhil314 / gist:b7a2b6d4c7aff4b9da0d40970fd499f8
Created November 14, 2020 18:17 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue: