Skip to content

Instantly share code, notes, and snippets.

@ajmas
ajmas / doc_thumbnail.sh
Last active September 11, 2024 03:40
Creating thumbnail for different media
#!/bin/sh
## Draft tool to create thumbnails from office documents, since unoconv wasn't working for me.
soffice_cmd="/Applications/LibreOffice.app/Contents/MacOS/soffice"
input_file="$1"
extension="${input_file##*.}"
noext_filepath="${input_file%.*}"
tmp_filepath="${TMPDIR}docthumb-$(date +%s)"
@ajmas
ajmas / MarkdownEdit.vue
Created March 16, 2024 00:58
MarkdownEdit
<template>
<q-card class="markdown-edit" outlined>
<q-toolbar dense>
<q-tabs v-model="mode" align="left" dense >
<q-tab name="edit" :label="$t('label.write')"/>
<q-tab name="preview" :label="$t('label.textPreview')"/>
</q-tabs>
<q-space />
<q-toolbar v-if="mode === 'edit'">
<q-space />
@ajmas
ajmas / webp2mp4.sh
Last active January 5, 2024 03:40
Convert WEBP to MP4
#!/bin/sh
## Quick script to convert webp files to mp4. Makes use of webpmux, ImageMagick and ffmpeg
input=$1
output_base=/tmp
output_file=output.mp4
regex="Number of frames: ([0-9]+)"
info=`webpmux -info "$1"`
@ajmas
ajmas / OpenId.ts
Created May 4, 2022 21:56
Code for dealing with OpenId tokens, in node.js
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');
/**

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
ajmas / MarkdownFaq.vue
Created November 6, 2020 20:17
Vue Markdown FAQ
<template>
<div :class="cssClass">
<div v-html="html" ref="html"/>
</div>
</template>
<script>
/**
* This component takes some markdown and then presents it as a
* collapsable list.
@ajmas
ajmas / markdownToFaq.js
Last active November 6, 2020 17:27
Converts Markdown formatted text representing a FAQ to an array of FAQ entries
const md = require('markdown-it')()
.use(require('markdown-it-attrs'))
.use(require('markdown-it-header-sections'));
const { XMLSerializer, DOMParser } = require('xmldom')
const sampleMarkdown = `
# XYZ
## Question 1
@ajmas
ajmas / conversions.md
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
ajmas / mongoose-and.ts
Last active October 7, 2020 20:13
Testing performance advantage of `$and` in mongodb
/* 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
ajmas / numberformat.js
Created September 2, 2020 17:01
International Number Formatting in JS
const suffixes = {
en: {
one: 'st',
two: 'nd',
few: 'rd',
other: 'th'
},
fr: {
one: 'er',
two: 'e',