Skip to content

Instantly share code, notes, and snippets.

@ajmas
ajmas / bluesky-posts-fetcher.ts
Created March 12, 2025 01:54
Fetches the posts a person has made in Bluesky
import { AtpAgent, AtpSessionEvent, AtpSessionData } from '@atproto/api'
import { FeedViewPost } from '@atproto/api/dist/client/types/app/bsky/feed/defs';
import { ExternalEmbedView, ImagesEmbedView, VideoEmbedView } from '@atproto/bsky/dist/views/types';
const identifier = 'myuser.bsky.social';
const password = 'xxxx-xxxx-xxx-xxxx';
const bSkyService = 'https://bsky.social';
const bSkyPublicService = 'https://public.api.bsky.app';
function displayPost (feedEntry: FeedViewPost) {
@ajmas
ajmas / upload-dnd.css
Last active March 11, 2025 17:43
Basic HTML Drag and drop for files
.dropzone.dropzone-active {
box-shadow: 0px 0px 15px 0px rgba(73, 245, 54, 0.75);
}
.dropzone.dropzone-badtype {
cursor: no-drop;
box-shadow: 0px 0px 15px 0px rgba(248, 19, 19, 0.75);
content: url("./white-x-icon.svg");
}
@ajmas
ajmas / discordForumToHtml.ts
Last active January 19, 2025 05:47
Discord Forum Threads to HTML
import { AnyThreadChannel, Channel, ChannelType, Client, FetchedThreads, ForumChannel, ForumThreadChannel, IntentsBitField, Message, Partials, ThreadChannel } from "discord.js";
let client: Client;
let botToken = 'xxxxxxxxxx';
async function getClient (): Promise<Client<boolean>> {
if (!client && botToken) {
// eslint-disable-next-line no-async-promise-executor
client = await new Promise(async (resolve, reject) => {
const intents: number[] = [
@ajmas
ajmas / EmailAddressUtils.ts
Last active December 20, 2024 20:24
Generates a normalised email address, with support for extended latin as input
function removeAccents (text: string) {
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
/**
* Converts a string, that may include extended latin characters
* and accents, to the more limited range supported by the English
* alphabet and 128 bit ASCII.
*
* There may be some disagreement in the character mapping, but we
@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.