Skip to content

Instantly share code, notes, and snippets.

ajmas / OpenId.ts
Created May 4, 2022 21:56
Code for dealing with OpenId tokens, in node.js
View OpenId.ts
import axios from 'axios';
import { Request, Response, NextFunction } from 'express';
import jwt, { GetPublicKeyOrSecret, Secret } from 'jsonwebtoken';
import jwksClient, { JwksClient } from 'jwks-rsa';
import UnauthenticatedError from '../errors/UnauthenticatedError';
import { getLogger } from './logging';
const logger = getLogger('openid');
View Coding Style

This is a "work in progress" coding style philosophy document. It doesn't define the style we should go for, rather what we should be thinking about when defining the style rules of a project.

I go with the idea that a team is made up of juniors, intermediates and seniors, and we should make it easy for all of them to be able to contribute to the project.

  • Readability: if takes another developer 30 seconds as opposed to 5 seconds to read the code, depending on style then maybe it needs to be clearer
ajmas / MarkdownFaq.vue
Created November 6, 2020 20:17
Vue Markdown FAQ
View MarkdownFaq.vue
<div :class="cssClass">
<div v-html="html" ref="html"/>
* This component takes some markdown and then presents it as a
* collapsable list.
ajmas / markdownToFaq.js
Last active November 6, 2020 17:27
Converts Markdown formatted text representing a FAQ to an array of FAQ entries
View markdownToFaq.js
const md = require('markdown-it')()
const { XMLSerializer, DOMParser } = require('xmldom')
const sampleMarkdown = `
## Question 1
ajmas /
Last active November 1, 2020 22:19
CLI File Conversion methods, with open source tools

Note, all commands represent the bare minimum need to do the conversion. Optimisations are generally not indicated, unless they are really needed. Also, you'll need to install the necessary tools, since many are are unlikely to be installed by default. This list is by no means definitive and is more something I put together as a reference for myself.

Text and Marked Up Documents

PDF to text

Using pdftotext: pdftotext -layout input.pdf output.txt

Doc/Docx to text

ajmas / mongoose-and.ts
Last active October 7, 2020 20:13
Testing performance advantage of `$and` in mongodb
View mongoose-and.ts
/* eslint-disable no-console */
import mongoose from 'mongoose';
let User;
function generateRandomString (length = 6) {
return Math.random().toString(20).substr(2, length)
async function createEntries () {
ajmas / numberformat.js
Created September 2, 2020 17:01
International Number Formatting in JS
View numberformat.js
const suffixes = {
en: {
one: 'st',
two: 'nd',
few: 'rd',
other: 'th'
fr: {
one: 'er',
two: 'e',
ajmas / date-utils.js
Last active August 25, 2020 00:24
JS Date Utilities
View date-utils.js
* Given an array of days of week, return in how many days the
* next candidate day is. If no candidate is found, then -1 is
* returned, since delta is always positive and non-zero.
* The following chart expresses the logic, where 'X' represents
* the `dayOfWeek` and `daysOfWeek` represent the days of next
* possible occurrence.
* ```
ajmas / status-check
Last active August 4, 2020 23:32
Simple server health check, that sends failure to a discord or slack channel
View status-check
## simple server health checker. when the service does not respond it calls a
## Discord or Slack webhook
## adjust values below according to you needs:
ajmas / post-checkout
Created July 22, 2020 18:40
Git hook for NodeJS development
View post-checkout
## Checks to see if the package.json changed following a checkout or merge and then automatically
## runs `npm install`. If you use yarn or pnpm, then change the line with `npm install` as needed.
## add this code to both .git/hooks/post-checkout and .git/hooks/post-merge
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]