Skip to content

Instantly share code, notes, and snippets.

View rohitsaini1196's full-sized avatar
High on life

Rohit Saini rohitsaini1196

High on life
View GitHub Profile
module.exports = {
postSomething: async (req, res) => {
const { title, description, userId } = req.body;
const thing = new Field({
title,
description,
userId,
});
try {
@rohitsaini1196
rohitsaini1196 / getUniqueColorFromUniqueString.js
Last active May 8, 2022 13:04
Generate Unique Color from a Unique string
function toColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var c = (hash & 0x00ffffff).toString(16).toUpperCase();
return "#" + c;
}
console.log(toColor("cool"))
@rohitsaini1196
rohitsaini1196 / firstLetterUpperCase.js
Last active October 10, 2020 06:56
JavaScript Capitalize first letter of the string. You can use it in react js as well.
function ucFirstJS(string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
//Fastest way to generate random string in JavaScript
var x = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
console.log(x)