Skip to content

Instantly share code, notes, and snippets.

@karlhorky
karlhorky / R2_storage.ts
Created May 1, 2023 05:54 — forked from AndrewIngram/R2_storage.ts
Read/write from Cloudflare R2 in a Vercel edge function w/default
import { AwsClient } from "aws4fetch";
import { deflate } from "pako";
const R2_ACCOUNT_ID = "SOMETHING"
const R2_ACCESS_KEY_ID = "SOMETHING"
const R2_SECRET_ACCESS_KEY ="SOMETHING"
const R2_BUCKET = "SOMETHING"
const R2_URL = `https://${R2_BUCKET}.${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`;
@karlhorky
karlhorky / alpine-linux-deploy.log
Created April 6, 2023 07:51
Alpine Linux deploy logs: corepack prepare pnpm@latest --activate
2023-04-03T07:53:27.8474256Z Requested labels: ubuntu-latest
2023-04-03T07:53:27.8474294Z Job defined at: upleveled/next-js-example-winter-2023-vienna-austria/.github/workflows/test-playwright-and-deploy-to-fly-io.yml@refs/heads/main
2023-04-03T07:53:27.8474316Z Waiting for a runner to pick up this job...
2023-04-03T07:53:28.1009892Z Job is waiting for a hosted runner to come online.
2023-04-03T07:53:30.6303409Z Job is about to start running on the hosted runner: GitHub Actions 2 (hosted)
2023-04-03T07:53:32.8886204Z Current runner version: '2.303.0'
2023-04-03T07:53:32.8913724Z ##[group]Operating System
2023-04-03T07:53:32.8914198Z Ubuntu
2023-04-03T07:53:32.8914499Z 22.04.2
2023-04-03T07:53:32.8914804Z LTS
@karlhorky
karlhorky / _app.js
Created November 3, 2022 14:34 — forked from claus/_app.js
Restore scroll position after navigating via browser back/forward buttons in Next.js
import useScrollRestoration from "utils/hooks/useScrollRestoration";
const App = ({ Component, pageProps, router }) => {
useScrollRestoration(router);
return <Component {...pageProps} />;
};
export default App;
@karlhorky
karlhorky / delete-local-git-branches-with-gone-remote-branches.sh
Created July 22, 2022 09:46
Delete Local Git Branches with "Gone" Remote Branches
# https://stackoverflow.com/a/33548037/1268612
git fetch --prune && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done
@karlhorky
karlhorky / recaptcha_fallback.js
Created March 29, 2022 20:03 — forked from luckylooke/recaptcha_fallback.js
Google recaptcha wrapper for grecaptcha.execute() with version 2 fallback.
function execute(action, callback) {
// create real promise, because execute method does not return the real one
// (missing documentation what actually returns)
const promise = new Promise((resolve, reject) => {
grecaptcha.ready(() =>
grecaptcha.execute(key, { action }).then(token => {
resolve(token);
},
reject)
);
@karlhorky
karlhorky / solutions-stacks.csv
Created June 1, 2021 20:40 — forked from Potherca/solutions-stacks.csv
Solution Stack Acronyms
Stack Name Stack Type Operating System / Platform Server Database Language or SDK Framework UI Message Bus / Queue
AMP Web (Backend) Apache MySQL / MariaDB Perl / PHP / Python
BAMP Web (Backend) BSD Apache MySQL / MariaDB Perl / PHP / Python
BAPP Web (Backend) BSD Apache PostgreSQL Perl / PHP / Python
BCHS Web (Backend) BSD SQLite httpd C
DAMP Web (Backend) Darwin Apache MySQL / MariaDB Perl / PHP / Python
ELK Time Series Data Logstash Elasticsearch Kibana
ELKB Time Series Data Logstash Elasticsearch Beats Kibana
FAMP Web (Backend) FreeBSD Apache MySQL / MariaDB Perl / PHP / Python
FWAP Web (Backend) Windows Apache Firebird Perl / PHP / Python
@karlhorky
karlhorky / .readme.md
Last active May 8, 2021 11:41
Use new `node:` prefix on Repl.it with Node v12

node: schema prefixes on repl.it

If you want to use the node: prefixes for builtin modules on repl.it, then (as of May 2021) you need to do a few things:

  1. In .replit, add the [packager] section with the ignoredPackages configuration seen in the example file below. This will disable the automatic installation on repl.it of these packages.
  2. In .replit, change the start script to yarn start
  3. In package.json, add a scripts section with the start script as seen in the example file below. This will transpile away the node: prefixes for the older Node v12 version using @upleveled/babel-plugin-remove-node-prefix.
  4. Run yarn add --dev @babel/core @babel/node @upleveled/babel-plugin-remove-node-prefix

Example repl here: https://replit.com/@karlhorky/node-prefix-babel-demo#index.js

@karlhorky
karlhorky / try-catch.ts
Last active October 19, 2022 23:43
Try-catch helper for promises and async/await
export default async function tryCatch<Data>(
promise: Promise<Data>,
): Promise<{ error: Error } | { data: Data }> {
try {
return { data: await promise };
} catch (error) {
return { error };
}
}
@karlhorky
karlhorky / add-favicon-app-badge.js
Last active April 16, 2021 17:30
Dynamically Add App Badge To Favicon
const faviconHref = document.querySelector('[rel="icon"]').href;
const faviconSize = 32;
const canvas = document.createElement('canvas');
canvas.width = faviconSize;
canvas.height = faviconSize;
const context = canvas.getContext('2d');
const img = document.createElement('img');
@karlhorky
karlhorky / createIndex.ts
Created March 30, 2021 07:30 — forked from tricinel/createIndex.ts
Creating a lunr index
import lunr from 'lunr';
import { pick, propEq, map, filter, prop } from 'ramda';
interface FieldConfigAttributes {
boost: number;
}
interface FieldConfig<T> {
name: keyof T;
store: boolean;