Skip to content

Instantly share code, notes, and snippets.

View mutaimwiti's full-sized avatar
🕵️‍♂️
JavaScripting

Mutai Mwiti mutaimwiti

🕵️‍♂️
JavaScripting
View GitHub Profile
@mutaimwiti
mutaimwiti / index.js
Created September 3, 2023 17:03 — forked from morphatic/index.js
Example of polling a REST API every 1.5 seconds with Observables in NodeJS
/**
* Instructions
*
* 1. mkdir test
* 2. cd test
* 3. npm init
* 4. accept all defaults is fine
* 5. npm install @akanass/rx-http-request
* 6. paste code below into new file index.js
* 7. update username, password, other variables
@mutaimwiti
mutaimwiti / redux.test.js
Created September 1, 2021 01:17 — forked from arjunattam/redux.test.js
Redux store testing with Playwright
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.launch();
const context = await browser.newContext();
// set addInitScript to run this on every page load in this context
// in the app, use window.IS_PLAYWRIGHT to set window.store = store;
await context.addInitScript('window.IS_PLAYWRIGHT = true;')
@mutaimwiti
mutaimwiti / jwt-expiration.md
Created November 16, 2020 05:44 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@mutaimwiti
mutaimwiti / app.js
Created January 22, 2019 14:46 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@mutaimwiti
mutaimwiti / huawei_e303_api_device
Created August 26, 2016 08:03 — forked from manuel-rabade/huawei_e303_api_device
API del modem Huawei E303
$ curl http://192.168.1.1/api/device/information
<?xml version="1.0" encoding="UTF-8"?>
<response>
<DeviceName>E303</DeviceName>
<SerialNumber>K3XBYAxxxxxxxxxx</SerialNumber>
<Imei>xxxxxxxxxxxxxxx</Imei>
<Imsi>xxxxxxxxxxxxxxx</Imsi>
<Iccid>xxxxxxxxxxxxxxxxxxxx</Iccid>
<Msisdn></Msisdn>
<HardwareVersion>CH2E303SM</HardwareVersion>