Skip to content

Instantly share code, notes, and snippets.

View neharkarvishal's full-sized avatar

Vishal Neharkar neharkarvishal

View GitHub Profile
/**
* pipeAsyncFunctions.js
* tags: { JavaScript, Adapter, Function, Promise }
* Performs left-to-right function composition for asynchronous functions.
* Use Array.prototype.reduce() with the spread operator (...) to perform
* left-to-right function composition using Promise.then(). The functions can
* return a combination of: simple values, Promise's, or they can be defined as
* async ones returning through await. All functions must be unary.
*/
/**
* removeArrayElements.js
* tags: { JavaScript, Array }
* Removes elements from an array for which the given function returns false.
* Use Array.prototype.filter() to find array elements that return truthy
* values and Array.prototype.reduce() to remove elements using
* Array.prototype.splice(). The func is invoked with three
* arguments (value, index, array).
*/
/**
* zipObject.js
* tags: { JavaScript, Array, Object }
* Given an array of valid property identifiers and an array of values,
* return an object associating the properties to the values.
* Since an object can have undefined values but not undefined property
* pointers, the array of properties is used to decide the structure of
* the resulting object using Array.prototype.reduce().
*/
/**
* partitionArray.js
* tags: { JavaScript, Array, Object, Function }
* Groups the elements into two arrays, depending on the provided function's
* truthiness for each element.
* Use Array.prototype.reduce() to create an array of two arrays.
* Use Array.prototype.push() to add elements for which fn returns true to the
* first array and elements for which fn returns false to the second one.
*/
@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
echo-server-epoll
echo-server-poll
talk
talk.dSYM
/**
* getNumberOfDigits.js
* tags: { JavaScript, Array, RxJS }
*/
const { interval } = Rx;
const { scan, pluck, groupBy } = RxOperators;
interval(1000).pipe(
scan(
@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();
@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 / 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