Skip to content

Instantly share code, notes, and snippets.

View simonprickett's full-sized avatar
💭
I'm not your friend on Facebook.

Simon Prickett simonprickett

💭
I'm not your friend on Facebook.
View GitHub Profile
@simonprickett
simonprickett / server.js
Created May 23, 2021 15:28
Getting Started with Express Part 1: Database information route
app.get('/dbinfo', (req, res) => {
const dbKeys = Object.keys(db);
const info = {
size: dbKeys.length
};
if ('true' === req.query.details) {
info.keys = dbKeys;
}
@simonprickett
simonprickett / server.js
Created May 23, 2021 15:24
Getting Started with Express Part 1: Get key value route
app.get('/get/:key', (req, res) => {
res.json({ value: db[req.params.key]});
});
@simonprickett
simonprickett / server.js
Last active May 23, 2021 15:26
Getting Started with Express Part 1: Set key to value route
app.post('/set', (req, res) => {
db[req.body.key] = req.body.value;
res.status(201).json({
status: 'OK'
});
});
@simonprickett
simonprickett / server.js
Created May 23, 2021 15:21
Getting Started with Express Part 1: Home Page Route
app.get('/', (req, res) => {
res.json({
appName: process.env.npm_package_name,
appVersion: process.env.npm_package_version
});
});
@simonprickett
simonprickett / server.js
Created May 23, 2021 13:59
Getting Started with Express Part 1: Initalization
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}.`);
@simonprickett
simonprickett / main.py
Created March 6, 2021 18:42
MicroPython example code for button presses and LEDs on Raspberry Pi Pico
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)
@simonprickett
simonprickett / index.js
Created February 7, 2021 21:58
getCelebStatus function for the Alexa Dead or Alive Redis game.
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);
@simonprickett
simonprickett / index.js
Created February 7, 2021 21:38
validateAnswer function for Alexa Dead or Alive Redis skill.
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;
@simonprickett
simonprickett / index.js
Created February 7, 2021 21:25
Checking the user's answer for the Alexa Dead or Alive Redis skill.
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!';
@simonprickett
simonprickett / index.js
Created February 7, 2021 21:10
Implementation of getCeleb for the Alexa Dead or Alive game that uses Redis.
const getCeleb = async (redis, celebName) => {
const celeb = await redis.hgetall(getKeyName(celebName));
return celeb;
};