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
app.get('/dbinfo', (req, res) => { | |
const dbKeys = Object.keys(db); | |
const info = { | |
size: dbKeys.length | |
}; | |
if ('true' === req.query.details) { | |
info.keys = dbKeys; | |
} |
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
app.get('/get/:key', (req, res) => { | |
res.json({ value: db[req.params.key]}); | |
}); |
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
app.post('/set', (req, res) => { | |
db[req.body.key] = req.body.value; | |
res.status(201).json({ | |
status: 'OK' | |
}); | |
}); |
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
app.get('/', (req, res) => { | |
res.json({ | |
appName: process.env.npm_package_name, | |
appVersion: process.env.npm_package_version | |
}); | |
}); |
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 express = require('express'); | |
const app = express(); | |
const PORT = process.env.PORT || 3000; | |
const db = {}; | |
app.use(express.json()); | |
... | |
app.listen(PORT, () => { | |
console.log(`Express application listening on port ${PORT}.`); |
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
import machine | |
import time | |
import utime | |
blue_led = machine.Pin(2, machine.Pin.OUT) | |
blue_btn = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP) | |
green_led = machine.Pin(7, machine.Pin.OUT) | |
green_btn = machine.Pin(9, machine.Pin.IN, machine.Pin.PULL_UP) |
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 getCelebStatus = async (redis, celeb) => { | |
// Check for cached result. | |
const celebStatusKey = getKeyName(celeb, 'status'); | |
let status = await redis.hgetall(celebStatusKey); | |
if (Object.keys(status).length === 0) { | |
// Wasn't cached, fetch it and cache it. | |
status = await doa.getStatus(celeb); | |
await redis.hmset(celebStatusKey, status); | |
redis.expire(celebStatusKey, EXPIRY_TIME); |
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 validateAnswer = async (redis, celebName, isDead) => { | |
if (! celebName) { | |
return null; | |
} | |
// Get the celeb's status... | |
const celebStatus = await getCelebStatus(redis, celebName); | |
if (! celebStatus) { | |
return null; |
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 celebToCheck = sessionAttributes[CURRENT_CELEB_KEY]; | |
let speakOutput; | |
// Check what the status of this celebrity is... | |
const result = await validateAnswer(redis, celebToCheck, userSaidDead); | |
if (result) { | |
if (result.correct) { | |
speakOutput = 'Correct!'; |
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 getCeleb = async (redis, celebName) => { | |
const celeb = await redis.hgetall(getKeyName(celebName)); | |
return celeb; | |
}; |