This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Password protect a subdomain on ExpressJS | |
* Uses HTTP Basic authorization... https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization | |
* with the WWW-Authenticate header... https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate | |
* | |
* By then checking if the user is visting from the given subdomain, you know they are authorized. | |
* I use this concept to password protect beta site features that aren't yet released publicly, on which | |
* certain pages are only accessible via the password protected 'beta.domain.com' url | |
*/ | |
const config = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** FizzBuzz challenge in 3 lines | |
* "Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”." | |
*/ | |
for (let i=1; i<=100; i++){ | |
console.log((((i%3==0)?'Fizz':'')+((i%5==0)?'Buzz':''))||i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Find the intersection between two JS arrays of objects | |
* finds based on an object property (using 'filter' and 'map') | |
*/ | |
products = [ // an array of products | |
{reference:'LOWP8F7H', name:'Nike Blazer', price:120, category:1}, | |
{reference:'3PFH3LDP', name:'Nike Kyrie', price:340, category:1}, | |
{reference:'FGH4P40K', NAME:'Nike Bomber', price:70, category:0} | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using Math.round() results in an uneven distribution, as mentioned here... | |
* https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range | |
*/ | |
function randomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendPushoverNotif(token, target, message, title){ | |
message = encodeURIComponent(message); // make url friendly | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "https://api.pushover.net/1/messages.json", true); | |
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
xhr.send(`token=${token}&user=${target}&message=${message}&title=${title}`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = 'https://example.com/api.json'; | |
$fields = array( | |
'key1'=>urlencode('value 1'), | |
'key2'=>urlencode('value 2'), | |
'key3'=>urlencode('value 3') | |
); | |
//url-ify the data for the POST | |
$fields_string = ""; | |
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getJwtPayload(){ | |
//retrieve JsonWebToken from cookies | |
var cookies = document.cookie.split(";"), | |
jwt; | |
for (cookie of cookies){ | |
var keyValue = cookie.trim().split('='); | |
if (keyValue[0] === "jwt"){ | |
jwt = keyValue[1]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// leads/read.read | |
'use_strict'; | |
const uuid = require('uuid'); | |
const AWS = require('aws-sdk'); | |
const IsEmail = require('isemail'); | |
const dynamoDb = new AWS.DynamoDB.DocumentClient(); | |
module.exports.create = function(event, context, callback) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^(?:[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------EXTRACT FORM INPUTS------ | |
* Returns Object of name:value pairs in .data | |
* .error will contain invalid input name on Error (e.g: empty required input) | |
*/ | |
function extractFormInputs( formEl ){ | |
// get all inputs from form | |
var inputs = formEl.querySelectorAll('input,textarea'); | |
// convert inputs to array | |
var inputsArr = Array.from(inputs); |