Skip to content

Instantly share code, notes, and snippets.

View masautt's full-sized avatar
🏠
Working from home

masautt

🏠
Working from home
View GitHub Profile
@masautt
masautt / points.json
Last active July 7, 2019 18:13
points.json is a list of points of interest for Jarupa Mountain Discovery center
[
{
"name": "Restrooms",
"lat": 34.01648,
"long": -117.4498,
"text": [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
[
{
"question": "What is JQuery?",
"answer": "",
"tags": [
"JavaScript",
"Front-End",
"JS Libraries"
],
"type": "Definition",
@masautt
masautt / qvbghki.js
Last active September 3, 2019 21:43
How can you validate an email address in JavaScript?
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
@masautt
masautt / ncrmxrg.js
Created September 3, 2019 21:42
How can I include a JavaScript file in another JavaScript file?
// EXPORTING A DEFAULT
// separateFile.js
export default function foo() {
console.log("bar");
}
// index.js
import foo from "./separateFile"
@masautt
masautt / ccv7qtn.js
Created September 3, 2019 21:46
How can you check whether a box is checked using JavaScript?
let checkBox = document.getElementById("myCheckBox");
console.log(checkBox.checked) //--> true or false
@masautt
masautt / irpqnt.js
Created September 3, 2019 21:48
How can you generate a GUID / UUID in JavaScript?
function genUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
console.log(genUUID()) //--> 26a63d24-aef9-4047-9284-9fdb366bae95
@masautt
masautt / q72rjvf.js
Created September 3, 2019 22:07
How do you get a timestamp in JavaScript?
//Get the EPOCH Time
console.log(Date.now()) //--> 1567548304725
//Get a string date
console.log((new Date).toLocaleString()); //--> 9/3/2019, 3:07:03 PM
@masautt
masautt / isy74qv.js
Last active September 3, 2019 23:04
How to capitalize first letter of string in JavaScript?
let str = "mylowercasestring";
let cappedStr = str.charAt(0).toUpperCase() + name.slice(1));
console.log(cappedStr); //--> "Mylowercasestring"
@masautt
masautt / kr0ns2b.js
Last active September 3, 2019 23:03
How to append to array in JavaScript?
let myArr = ["1", "2", "3"];
myArr.push("4");
console.log(myArr);
@masautt
masautt / js40uib.js
Last active September 3, 2019 23:02
How to prevent submit button from refreshing page when clicked using JavaScript
document.getElementById("myBtn").addEventListener("click", e => {
//some code
e.preventDefault(); //This specifically removes the default behavior of refreshing the page
})