Skip to content

Instantly share code, notes, and snippets.

@mishushakov
Last active November 7, 2021 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishushakov/eb281f8edbb7e2bd2e6580de193d87f4 to your computer and use it in GitHub Desktop.
Save mishushakov/eb281f8edbb7e2bd2e6580de193d87f4 to your computer and use it in GitHub Desktop.
Pepe the Frog from Deno Deploy Demo
// Grab ascii pepe from gist
const pepe = await fetch('https://gist.github.com/mishushakov/eb281f8edbb7e2bd2e6580de193d87f4/raw/15c4dcb0c913a33d71ae0f84879fd311f6811652/pepe_small.txt')
const pepe_txt = await pepe.text()
// List of greetings to which pepe responds
const greetings = ['Hello', 'Hi', 'Hey', 'hello', 'hi', 'hey', 'pepe']
// Last time pepe appeared
let lastgreeting = Date.now()
const connect = function () {
// Connect to the demo
const ws = new WebSocket('wss://mini-ws-chat.deno.dev')
ws.onmessage = async (m) => {
// Check if pepe was greeted
if (greetings.includes(m.data)) {
// Calculate the difference (in seconds) between last time pepe was greeted
const difference = Math.floor((Date.now() - lastgreeting) / 1000)
// If difference is greater than 60 seconds, draw the pepe
if (difference >= 60) {
pepe_txt.split(/\r?\n/).forEach(line => ws.send(line))
// Reset the date
lastgreeting = Date.now()
}
}
}
// Handle error
ws.onerror = (e) => console.log(e)
// Handle connection drop
ws.onclose = () => connect()
}
connect()
████████ ██████
█░░░░░░░░██ ██░░░░░░█
█░░░░░░░░░░░█░░░░░░░░░█
█░░░░░░░███░░░█░░░░░░░░░█
█░░░░███░░░███░█░░░████░█
█░░░██░░░░░░░░███░██░░░░██
█░░░░░░░░░░░░░░░░░█░░░░░░░░███
█░░░░░░░░░░░░░██████░░░░░████░░█
█░░░░░░░░░█████░░░████░░██░░██░░█
██░░░░░░░███░░░░░░░░░░█░░░░░░░░███
█░░░░░░░░░░░░░░█████████░░█████████
█░░░░░░░░░░█████ ████ ████ █████ █
█░░░░░░░░░░█ █ ███ █ ███ █ █
█░░░░░░░░░░░░█ ████ ████ ██ ██████
░░░░░░░░░░░░░█████████░░░████████░░░█
░░░░░░░░░░░░░░░░█░░░░░█░░░░░░░░░░░░█
░░░░░░░░░░░░░░░░░░░░██░░░░█░░░░░░██
░░░░░░░░░░░░░░░░░░██░░░░░░░███████
░░░░░░░░░░░░░░░░██░░░░░░░░░░█░░░░░█ HELLO HELLO, THIS IS PEPE FROM HACKERNEWS!
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ MORE: https://news.ycombinator.com/item?id=29131751
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ CODE: https://git.io/JXTZu
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
░░░░░░░░░░░█████████░░░░░░░░░░░░░░██
░░░░░░░░░░█▒▒▒▒▒▒▒▒███████████████▒▒█
░░░░░░░░░█▒▒███████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░░░░░░█▒▒▒▒▒▒▒▒▒█████████████████
░░░░░░░░░░████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░░░░░░░░░░░░░░░██████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
██░░░░░░░░░░░░░░░░░░░░░░░░░░░██
▓██░░░░░░░░░░░░░░░░░░░░░░░░██
▓▓▓███░░░░░░░░░░░░░░░░░░░░█
▓▓▓▓▓▓███░░░░░░░░░░░░░░░██
▓▓▓▓▓▓▓▓▓███████████████▓▓█
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█
▄█▀▀▀▀▀▀█▄ ▄▀▀▀▀▀▀▄
▄▀░░░░░░▄▄▄▄▀█░░░░░░░░▀▄
█░░░░░░▀▀░░░░▀▀█▄▀▀▀▀▀▀▀█▄
█░░░░░░░░▄▄████████▄░▄███████▄
▄▀░░░░░░░▀███████████▄██████████▄
█▀░░░░░▄▀▀█▀░▄█▄███▄░▀█░▄█▄███░░░█
█░░░░░░░▀▀█▀▀▄▄█████▄▄▀▀▄▄█████▀▀▀█
█▀░░░░░░░░░░▀▄▄▄▄▄▄▄▄▄▄▀░░░░░░░░▄█▀ HELLO HELLO, THIS IS PEPE FROM HACKERNEWS!
█░░░░░░░░░░░░░░░░░░▄▀░░░░░░▀█▀▀▀█▄ MORE: https://news.ycombinator.com/item?id=29131751
█░░░░░░░░░░░▄▄▄▄░░░░░░░░░░░░░░░░░█ CODE: https://git.io/JXTZu
█░░░░░░░░▄▀▀░▄▄░▀▀▀▀▀▄▄▄▄▄▄▄▀▀▀▀▀▀█
▀█░░░░░█░▀▄▀▀░░▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄█
▄█▄▄░░░▀▄░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▀
▄▀▀░▀██▄░░░▀▀░░░░░░░░░░░░░░▄▄▄▀▀
░░░░░░▀▀███▄▄▄▄▄▄▄▄▄▄▄▄▄████▄
░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀░░░▀█▄
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment