Skip to content

Instantly share code, notes, and snippets.

@kiliman
kiliman / Remix-Logo-Black.svg
Created November 14, 2023 21:33
Remix logos with transparent background
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kiliman
kiliman / twitter-scroll-restore.js
Last active October 27, 2023 15:34
TamperMonkey script to fix Twitter scroll handling on replies
// ==UserScript==
// @name Twitter Scroll Restore
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author @kiliman
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?domain=twitter.com
// @grant none
// ==/UserScript==
@kiliman
kiliman / ts2js.sh
Last active October 11, 2023 00:43
Script to convert TypeScript files to JavaScript
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 source_folder target_folder"
exit 1
fi
source_folder="$1"
target_folder="$2"
@kiliman
kiliman / types.ts
Created August 11, 2023 14:43
Type helpers
export type MakeOptional<Type, Key extends keyof Type> = Omit<Type, Key> &
Partial<Pick<Type, Key>>;
export type PickNullable<T> = {
[P in keyof T as null extends T[P] ? P : never]: T[P];
};
export type PickNotNullable<T> = {
[P in keyof T as null extends T[P] ? never : P]: T[P];
};
@kiliman
kiliman / index.js
Last active July 20, 2023 21:21
Script to create Remix and Expo apps for Nx - Expo support is still work in progress
const { spawn } = require("child_process");
const fs = require("fs");
const command = process.argv[2];
const appName = process.argv[3];
if (!fs.existsSync("apps")) {
fs.mkdirSync("apps");
}
if (fs.existsSync(`apps/${appName}`)) {
@kiliman
kiliman / github-open-npm.js
Last active September 25, 2023 05:40
TamperMonkey script to open the npm package by Ctrl/Cmd+click on import statement from GitHub code view
// ==UserScript==
// @name GitHub open npm from import
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @description Opens the npm package by Ctrl/Cmd+click on import statement
// @author Kiliman
// @match https://github.com/*
// @icon https://www.google.com/s2/favicons?domain=github.com
// @grant none
// ==/UserScript==
@kiliman
kiliman / @remix-run+react+1.18.0.patch
Created June 26, 2023 21:25
Patch to add header to client-side requests in Remix
diff --git a/node_modules/@remix-run/react/dist/data.js b/node_modules/@remix-run/react/dist/data.js
index b3b935f..58a4874 100644
--- a/node_modules/@remix-run/react/dist/data.js
+++ b/node_modules/@remix-run/react/dist/data.js
@@ -61,6 +61,12 @@ async function fetchData(request, routeId, retry = 0) {
init.body = await request.formData();
}
}
+ init.headers = {
+ ...init.headers,
@kiliman
kiliman / entry.server.tsx
Last active April 10, 2024 15:46
Setup Sentry.io with Remix
const env = getEnvVars();
function myTracesSampler(samplingContext: SamplingContext) {
// Don't trace healthcheck or HEAD requests
const { transactionContext } = samplingContext;
if (
transactionContext.name === 'routes/healthcheck/_index' ||
transactionContext.tags?.method === 'HEAD'
) {
return false;
diff --git a/node_modules/@remix-run/server-runtime/dist/responses.js b/node_modules/@remix-run/server-runtime/dist/responses.js
index d042d61..1e6d5c6 100644
--- a/node_modules/@remix-run/server-runtime/dist/responses.js
+++ b/node_modules/@remix-run/server-runtime/dist/responses.js
@@ -47,7 +47,7 @@ function isDeferredData(value) {
return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
}
function isResponse(value) {
- return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
+ return value instanceof router.ErrorResponse || (value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined");
@kiliman
kiliman / index.tsx
Created February 7, 2023 21:31
Remix `useSubmitPromise` hook
import type { ActionArgs, LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import type { SubmitOptions } from "@remix-run/react";
import { useActionData, useNavigation, useSubmit } from "@remix-run/react";
import { useCallback, useEffect, useMemo } from "react";
export function loader({ request }: LoaderArgs) {
return json({ message: "Hello World" });
}