Skip to content

Instantly share code, notes, and snippets.

View neharkarvishal's full-sized avatar

Vishal Neharkar neharkarvishal

View GitHub Profile
@neharkarvishal
neharkarvishal / sha-256.js
Created August 11, 2022 06:22
Calculate SHA-256 hash (Node.js)
/**
* Creates a hash for a value using the SHA-256 algorithm. Returns a promise.
*
* Use crypto.createHash() to create a Hash object with the appropriate
* algorithm.
*
* Use hash.update() to add the data from val to the Hash, hash.digest() to
* calculate the digest of the data.
*
* Use setTimeout() to prevent blocking on a long operation. Return a Promise to
function fizzBuzz(n: number) {
return (
{ true: '', false: 'Fizz' }[`${n % 3 === 0}`] +
{ true: '', false: 'Buzz' }[`${n % 5 === 0}`] ||
n.toString()
)
}
function fizzBuzzFunctional(n: number) {
let test =
/**
* Workaround to set up a handshake, lazy-loading by resolving a promise
*/
let settleReadyState = {}
let subprocess = {}
// following code outputs: Promise {<pending>} on console and sets
// settleReadyState = { resolve: ƒ, reject: ƒ}
// subprocess = {ready: Promise<pending>}
/**
* fibonacciGenerator.js
* tags: { JavaScript, Generator, Iterator }
*/
function* fibonacciGenerator() {
var [prev, curr] = [0, 1]
while(true) {
[prev, curr] = [curr, prev + curr]
yield curr
@neharkarvishal
neharkarvishal / openWithSublimeText.bat
Last active November 15, 2020 11:50
Open folders and files with Sublime Text 3 from windows explorer context menu.
@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@neharkarvishal
neharkarvishal / git.migrate
Created July 28, 2020 10:21 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@neharkarvishal
neharkarvishal / errorHandlingGoStyle.ts
Created July 10, 2020 07:03
Typescipt error handling
/* Return tuple types, with a nullable error component just like Go */
/* meta: Typescript 3.9.5 */
type Err = Error | null;
async function getUser(): Promise<[string, Err]> {
try {
const res = await fetch('/me');
const data = await res.json();
/**
* getNumberOfDigits.js
* tags: { JavaScript, Array, RxJS }
*/
const { interval } = Rx;
const { scan, pluck, groupBy } = RxOperators;
interval(1000).pipe(
scan(
echo-server-epoll
echo-server-poll
talk
talk.dSYM
@neharkarvishal
neharkarvishal / gist_blog.md
Created December 25, 2019 11:15 — forked from ww9/gist_blog.md
Using Gist as a blog #blog

Blogging with Gist

Gist simplicity can turn blogging into a liberating experience.

Pros Cons
✅ Free, simple, fast, hassle-free ❌ Image upload in comments only
✅ Tagging ❌ No post pinning
✅ Search ❌ Doesn't look like a blog
✅ Revisions ❌ Unfriendly URLs