Skip to content

Instantly share code, notes, and snippets.

View mgwedd's full-sized avatar
⚒️

Michael Wedd mgwedd

⚒️
View GitHub Profile
CREATE TABLE Users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255)
);
CREATE TABLE Booklets (
id SERIAL PRIMARY KEY,
@mgwedd
mgwedd / rbac_booklet.js
Last active April 27, 2023 02:39
RBAC example for fine grained auth on booklets
app.put('/booklets/:bookletId', async (req, res) => {
const bookletId = req.params.bookletId;
const userId = req.user.sub; // Assuming you've set req.user.sub to the user's ID from the JWT.
// Fetch the user's role for the booklet.
// role could be an enum
const result = await db.query('SELECT role FROM UserBooklets WHERE user_id = $1 AND booklet_id = $2', [userId, bookletId]);
// If there's no role, the user doesn't have any relationship with the booklet.
if (result.rows.length === 0) {
class MotorsWheels:
def __init__(
self, r_wheel_forward=6, r_wheel_backward=13, l_wheel_forward=19, l_wheel_backward=26):
self.r_wheel_forward = r_wheel_forward
...
GPIO.setmode(GPIO.BCM)
GPIO.setup(r_wheel_forward, GPIO.OUT)
GPIO.setup(r_wheel_backward, GPIO.OUT)
...