Skip to content

Instantly share code, notes, and snippets.

View vasanthv's full-sized avatar

vasanth vasanthv

View GitHub Profile
@vasanthv
vasanthv / mySubstring.js
Created November 18, 2019 08:19
Answer to cassidoo's Interview question "Implement the substring() function."
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
@vasanthv
vasanthv / capitalize.js
Created July 12, 2020 14:32
Captalize first letter of a string
const captilize = ([fL, ...rest]) => fL.toUpperCase()+rest.join("");
@vasanthv
vasanthv / timeago-short.js
Last active February 15, 2021 17:29
The short timeago function which return 1h, 1M, 2Y etc
const formatDate = (datestring) => {
const seconds = Math.floor((new Date() - new Date(datestring)) / 1000);
let interval = seconds / 31536000;
if (interval > 1) return Math.floor(interval) + "Y";
interval = seconds / 2592000;
if (interval > 1) return Math.floor(interval) + "M";
interval = seconds / 86400;
if (interval > 1) return Math.floor(interval) + "d";
interval = seconds / 3600;
if (interval > 1) return Math.floor(interval) + "h";
@vasanthv
vasanthv / extract.js
Created March 15, 2024 20:04 — forked from Sennahoi/extract.js
Extract bookmarks from a netscape bookmark file with node.js
var cheerio = require("cheerio"),
fs = require("fs");
fs.readFile('bookmarks.html', "utf-8", function read(err, data) {
if (err) {
throw err;
}
var $ = cheerio.load(data);
$("a").each(function(index, a) {