Skip to content

Instantly share code, notes, and snippets.

@m5r
m5r / background-job.ts
Last active March 25, 2022 06:20
Node.js worker-based background jobs
import { Worker } from "worker_threads";
import path from "path";
import fs from "fs";
import { nanoid } from "nanoid";
type Handler<Job> = (job: Job) => Promise<void> | void;
export class BackgroundJob<Job> {
private static readonly workersDir = "/tmp/background-jobs";
private readonly workerPath: string;
@m5r
m5r / delete-account-form.tsx
Created December 14, 2021 22:05
Remix background jobs using a resource route
import type { ActionFunction } from "remix";
import { Form, redirect, useTransition } from "remix";
import { enqueueDeleteUserData } from "~/app/routes/queues/delete-user-data";
import authenticator from "~/app/auth/authenticator";
import { destroySession, getSession } from "~/utils/session.server";
import db from "~/utils/db.server";
export const action: ActionFunction = async ({ request }) => {
const user = await authenticator.isAuthenticated(request, { failureRedirect: "/auth/sign-in" });
@m5r
m5r / index.tsx
Created February 26, 2022 20:22
bullmq job queue in Remix
import notifierQueue from "~/queues/notifier.server.ts";
export const loader = async () => {
await notifierQueue.add("test", { emailAddress: "[email protected]" });
return null;
};
import vm from "node:vm";
import path from "node:path";
import glob from "glob";
const routes = glob.sync(path.join(basePath, "/public/build/routes/**/*.js"));
const stylesheets = [];
function linker(specifier) {
const module = fs.readFileSync(path.join(basePath, "public", specifier));
if (!module) {
@m5r
m5r / script.js
Created February 16, 2024 02:53 — forked from gd3kr/script.js
Download a JSON List of twitter bookmarks
/*
the twitter api is stupid. it is stupid and bad and expensive. hence, this.
Literally just paste this in the JS console on the bookmarks tab and the script will automatically scroll to the bottom of your bookmarks and keep a track of them as it goes.
When finished, it downloads a JSON file containing the raw text content of every bookmark.
for now it stores just the text inside the tweet itself, but if you're reading this why don't you go ahead and try to also store other information (author, tweetLink, pictures, everything). come on. do it. please?
*/