This file contains hidden or 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 hidden or 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
| Array.prototype.isEqualTo = function(arr2){ // defining the Array method | |
| var arr1 = this; // accesing the first array | |
| if (arr1.length==arr2.length){ // if they have the same length | |
| arr1 = arr1.filter(item=>{ // filter through arr1 | |
| if (arr2.indexOf(item) > -1){ // if item from arr1 is in arr2 | |
| return false; // remove from arr1 so we know its been accounted for | |
| } | |
| return true; // keep in arr1 as not in arr2 | |
| }); | |
This file contains hidden or 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 hidden or 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 hidden or 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 validEmail(address) { | |
| // Regular Express from http://emailregex.com | |
| const emailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/; | |
| if (emailRegex.test(address)) return true; | |
| return false; | |
| } |
This file contains hidden or 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
| var xmlhttp = new XMLHttpRequest(); | |
| var url = "myFile.json"; | |
| xmlhttp.onreadystatechange = function() { | |
| if (this.readyState == 4 && this.status == 200) { | |
| var myArr = JSON.parse(this.responseText); | |
| myFunction(myArr); | |
| } | |
| }; | |
| xmlhttp.open("GET", url, true); |
This file contains hidden or 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 hexToRGBA(hex, opacity){ | |
| var rgba = "rgba("; | |
| var inc = Math.abs(hex.length - 5); | |
| for (var i = 1; i < hex.length; i+=inc){ | |
| var component = hex[i] + hex[i + (inc-1)]; | |
| rgba += parseInt(component, 16) + ","; | |
| } | |
| return rgba + opacity + ")"; | |
| } | |
| // abs() gives absolute val (modulus); -5 just produces correct increment (1 or 2, based on length of 4 or 7... #f0f vs #ff00ff) |
This file contains hidden or 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
| // Based on Glacier's example: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/examples.html#Amazon_Glacier__Multi-part_Upload | |
| var fs = require('fs'); | |
| var AWS = require('aws-sdk'); | |
| AWS.config.loadFromPath('./aws-config.json'); | |
| var s3 = new AWS.S3(); | |
| // File | |
| var fileName = '5.pdf'; | |
| var filePath = './' + fileName; | |
| var fileKey = fileName; |