Skip to content

Instantly share code, notes, and snippets.

View lenivene's full-sized avatar
🖖
Full-stack dev

Lenivene Bezerra lenivene

🖖
Full-stack dev
View GitHub Profile
@lenivene
lenivene / AttributesWithObjectId.d.ts
Created May 13, 2021 17:47
Extend attributes schema mongoose with _id
import { ObjectId } from "mongoose";
export type AttributesWithObjectId<Attr> = {
_id: ObjectId
} & Attr
@lenivene
lenivene / value-is-boolean.js
Created October 7, 2020 23:33
Check value string is boolean
String.prototype.valueIsBool = function() {
return /^\s*(true|1)\s*$/i.test(this);
};
  • \s Any whitespace character
  • \v Vertical whitespace
  • \h Horizontal whitespace
  • x Ignore whitespace (end line)
@lenivene
lenivene / generate_number.js
Created September 19, 2020 23:07
Generate random numbers in JavaScript
function generate_number(){
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
module.exports = async function sleep(time){
return new Promise(function (resolve) {
setTimeout(resolve, time);
})
}
export default function preg_match(regex: RegExp, str: string) {
return regex.test(str);
}
@lenivene
lenivene / unique-in-array.js
Last active June 20, 2020 13:43
Remove duplicate values from array
const array = ["Lenivene", "World", "Bezerra", "Hello", "Lenivene"];
array.reduce((unique, item) => {
return unique.includes(item) ? unique : [...unique, item]
}, []);
@lenivene
lenivene / force-site-https.js
Created May 1, 2020 03:35
Force site load with protocol HTTPS
if (location.protocol != "https:") {
location.href = "https:" +=window.location.href.substring(window.location.protocol.length);
}
console.log("Hello World"):
@lenivene
lenivene / type-password-in-input-number.css
Last active April 23, 2020 12:46
Show input number equal input password
input[type=number] {
-webkit-text-security: disc;
}