Skip to content

Instantly share code, notes, and snippets.

@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?
*/
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 / 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: "mokhtar@remixtape.dev" });
return null;
};
@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 / 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;
import type { FunctionComponent } from "react";
export const combineProviders = (providers: FunctionComponent[]) => providers.reduce(
(Combined, Provider) => ({ children }) => (
<Combined>
<Provider>{children}</Provider>
</Combined>
),
);
@m5r
m5r / magic.ts
Last active October 14, 2021 20:08
Magic login link generation and verification
import jwt from "jsonwebtoken";
import { User } from "./entities/user";
export function generateSignInUrl(user: User) {
const token = generateSignInToken(user);
return `${process.env.APP_URL}/auth/verify?token=${token}`;
}
declare global {
interface Window { Paddle: any; }
}
const VENDOR_ID = 111;
const PRODUCT_ID = 222;
type BuyParams = {
coupon?: string | null;
meta?: Record<string, string>;
export function serializeServerDataToJsonString(data: Object): string {
const jsonString = JSON.stringify(data);
return jsonString
.replace(/<\/script/gim, '</_escaped_script')
.replace(new RegExp('\u2028', 'g'), '\\u2028')
.replace(new RegExp('\u2029', 'g'), '\\u2029')
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
#!/bin/bash
if [ -z "$1" ]; then
echo "Error: No argument passed" >&2; exit 1
fi
if ! [[ $1 =~ ^[0-9]+$ ]] ; then
echo "Error: Argument is not a number" >&2; exit 1
fi
PIDToKill=$(lsof -i:$1 | grep LISTEN | awk '{print $2}' | uniq)