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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Facebook Login Example</title> | |
<meta name="description" content="Facebook Login Example"> | |
<meta name="author" content="Matt Lockyer"> | |
</head> |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Facebook Login Example</title> | |
<meta name="description" content="Facebook Login Example"> | |
<meta name="author" content="Matt Lockyer"> | |
</head> |
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
let contact = 'test', data, error; | |
const first = contact.substring(0, 1) | |
if (first === '+' || first === '(' || !isNaN(first)) { | |
//phone | |
console.log('testing phone') | |
const phone = contact.replace(/[+|-|(|)|.| ]/g, "").toLowerCase() | |
if (phone === "" || isNaN(phone)) { | |
error = "Please enter a proper phone number."; | |
} else if (phone.length < 10) { | |
error = "Your phone number is not long enough. Please include the Area Code."; |
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
//helper function | |
const assignFuncs = (state, funcs) => funcs | |
.map((func) => ({[func.name]: (...args) => func(state, ...args)})) | |
.reduce((acc, func) => ({...acc, ...func})) | |
//example | |
const bark = (state, howManyTimes) => { | |
state.barks += howManyTimes |
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
const canBark = (state) => ({ | |
bark:(howManyTimes) => { | |
state.barks += howManyTimes | |
} | |
}) | |
const canEat = (state, howMuch) => { | |
state.food -= howMuch | |
} |
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
const canBark = (state, howManyTimes) => { | |
state.barks += howManyTimes | |
} | |
const canEat = (state, howMuch) => { | |
state.food -= howMuch | |
} | |
const dog = (name) => { | |
let state = { |
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
const canBark = (state) => ({ | |
bark:(howManyTimes) => { | |
state.barks += howManyTimes | |
} | |
}) | |
const canEat = (state) => ({ | |
eat:(howMuch) => { | |
state.food -= howMuch | |
} |
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
/* | |
Go to mobile.twitter.com | |
Click following and you should see the followers / following tabs at the top, make sure you're on "following". | |
Open the developer console and paste this bad boy in. | |
You can watch it working away... And stop it anytime by closing the tab. | |
It will start with your most recently followed first and work backwards chronological as it scrolls the accounts you follow. | |
*/ |
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
fetch('http://localhost:8080/test', { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({name:'matt', number:34}), | |
// optional | |
// mode: "cors", // no-cors, cors, *same-origin | |
// cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached |
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
//functions | |
const qs = (sel) => document.querySelector(sel) | |
const dhParams = (public) => ({ name: "ECDH", namedCurve: "P-256", public }) | |
const aesParams = (length, counter) => ({ name: "AES-CTR", length, counter }) | |
const keyInt = async(key) => new Uint8Array(await crypto.subtle.exportKey('raw', key)); | |
const derive = async() => await window.crypto.subtle.generateKey(dhParams(), true, ["deriveKey", "deriveBits"]) | |
const deriveAES = async(publicKey, privateKey) => await window.crypto.subtle.deriveKey( | |
dhParams(publicKey), privateKey, aesParams(256), true, ["encrypt", "decrypt"] | |
) | |
const encrypt = async (key, iv, data) => await window.crypto.subtle.encrypt(aesParams(128, iv), key, data) |