Skip to content

Instantly share code, notes, and snippets.

Vasanth vasanthv

Block or report user

Report or block vasanthv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vasanthv
vasanthv / quacku-docs.md
Last active Jan 18, 2020
Quacku webhook documentation
View quacku-docs.md

Quacku Docs

Quacku is a status only app, which lets you answer "What are you doing right now?".

It lets you automate your status by calling Quacku webhook URLs from any app. This way you can post automatic statuses to Quacku when you are doing certain activities in other apps, like posting a blog.

Your unique webhook url will be in the below format:

https://quacku.com/webhook/{WEBHOOK_KEY}
@vasanthv
vasanthv / mySubstring.js
Created Nov 18, 2019
Answer to cassidoo's Interview question "Implement the substring() function."
View mySubstring.js
String.prototype.mySubstring = function(start, end) {
let substr = '';
for (i = (start || 0); i <= ((end || this.length) - 1); i++) {
substr += this[i];
}
return substr;
}
console.log("hello world!".mySubstring(1, 5)); // => ello
View isPrime.js
function isPrime(num) {
if (num > 2 && num % 2 === 0) return false;
for (var i = 3; i < Math.sqrt(num); i += 2) {
if (num % i === 0) return false;
}
return num > 1;
}
@vasanthv
vasanthv / allCombinationOfArrays.js
Last active May 30, 2019
A function to get all possible combination of arrays.
View allCombinationOfArrays.js
const arr = [ [ '8', '0', '5', '7', '9' ], [ '1', '2', '4' ] ]
const output = arr.reduce((a, b) => {
let ret = [];
a.forEach(i => b.forEach(j => ret.push(i + j)));
return ret;
});
// output = [ '81', '82', '84', '01', '02', '04', '51', '52', '54', '71', '72', '74', '91', '92', '94' ];
@vasanthv
vasanthv / factorial.js
Last active Sep 19, 2018
Get factorial of the given number
View factorial.js
const factorial = (n) => (Array.from(Array(n), (_, i) => i + 1)).reduce((a, b) => a * b);
@vasanthv
vasanthv / get-combinations.js
Created May 7, 2018
Get combinations of all elements in an array with optional length filter.
View get-combinations.js
//Based on https://stackoverflow.com/a/42531964
function combinations(array, length) {
const arr = new Array(1 << array.length).fill().map(
(e1, i) => array.filter((e2, j) => i & 1 << j));
return length ? arr.filter(a => a.length == length) : arr;
}
//console.log(combinations([1, 2, 3, 8, 10], 2));
View randomNumberRange.js
const random = (i,j) => (Math.floor(Math.random() * (j - i)) + i);
@vasanthv
vasanthv / formatDate.js
Last active Apr 9, 2020
Formats a Date from datestring
View formatDate.js
function formatDate(dateString){
const date = new Date(dateString);
const hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
return [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ][date.getMonth()] + ' '
+ (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
+ date.getFullYear() + ' - '
+ (hours < 10 ? '0' + hours : hours) + ':'
+ (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ' '
+ (date.getHours() >= 12 ? 'PM' : 'AM');
}
@vasanthv
vasanthv / all-combinations.js
Created Mar 12, 2018
The function returns all possible combinations of a given number represented as array.
View all-combinations.js
//Based on https://stackoverflow.com/a/46880431/607608
function getComb(set, val) {
const res = [];
function comb(set, k, partial, pref) {
if (!partial) partial = [];
for (const element in set) {
if (k > 1) {
const set_copy = set.slice();
set_copy.splice(element, 1);
View get-random-n-elements.js
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
You can’t perform that action at this time.