Skip to content

Instantly share code, notes, and snippets.

@zz85
Created June 5, 2020 19:59
Show Gist options
  • Save zz85/9f1cbddb9c9033d3b63be868a7aecd0c to your computer and use it in GitHub Desktop.
Save zz85/9f1cbddb9c9033d3b63be868a7aecd0c to your computer and use it in GitHub Desktop.
Happy fun times
<html>
<body>
<style>
body {
font-size: 20px;
text-align: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
'Droid Sans', 'Helvetica Neue', sans-serif !important;
padding: 40px;
}
textarea {
width: 400px;
font-size: 20px;
}
#label {
font-size: 40px;
}
</style>
<h1>Happy Funtimes Questions</h1>
<textarea id="textarea"></textarea>
<button id="butt">Pick Set 1</button>
<button id="butt2">Pick Set 2</button>
<br/><br/><br/><br/>
<div id="label"></div>
<script type="module">
var butt = document.getElementById('butt');
var textarea = document.getElementById('textarea');
var label = document.getElementById('label');
var salt = '';
var set1 = [
`Given the choice of anyone in the world, whom would you want as a dinner guest?`,
`Would you like to be famous? In what way?`,
`Before making a telephone call, do you ever rehearse what you are going to say? Why?`,
`What would constitute a “perfect” day for you?`,
`When did you last sing to yourself? To someone else?`,
`If you were able to live to the age of 90 and retain either the mind or body of a 30-year-old for the last 60 years of your life, which would you want?`,
`Do you have a secret hunch about how you will die?`,
`Name three things you and your colleagues appear to have in common.`,
`For what in your life do you feel most grateful?`,
` If you could change anything about the way you were raised, what would it be?`,
` Take four minutes and tell your life story in as much detail as possible.`,
` If you could wake up tomorrow having gained any one quality or ability, what would it be?`,
];
var set2 = [
`If a crystal ball could tell you the truth about yourself, your life, the future, or anything else, what would you want to know?`,
`Is there something that you’ve dreamed of doing for a long time? Why haven’t you done it?`,
`What is the greatest accomplishment of your life?`,
`What do you value most in a friendship?`,
`What is your most treasured memory?`,
`What is your most terrible memory?`,
`If you knew that in one year you would die suddenly, would you change anything about the way you are now living? Why?`,
`What does friendship mean to you?`,
];
console.log(set1, set2);
butt.onclick = async function () {
var val = textarea.value.trim() + salt;
const hashArray = await digestMessage(val);
var candidate = pick(set1, hashArray[0] * hashArray[1], 256 * 256);
label.innerHTML = candidate;
}
document.getElementById('butt2').onclick = async function () {
var val = textarea.value.trim()
const hashArray = await digestMessage(val);
var candidate = pick(set2, hashArray[3] * hashArray[4], 256 * 256);
label.innerHTML = candidate;
}
async function digestMessage(message) {
const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
return hashArray;
}
function pick(set, i, range) {
return set[i / range * set.length | 0]
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment