Skip to content

Instantly share code, notes, and snippets.

View karlhorky's full-sized avatar

Karl Horky karlhorky

View GitHub Profile
@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;
@karlhorky
karlhorky / cookies.js
Created March 24, 2021 12:22 — forked from jeroenvisser101/cookies.js
Set browser-wide cookies with Puppeteer
export const setCookies = async (page, cookies) => {
const items = cookies
.map(cookie => {
const item = Object.assign({}, cookie);
if (!item.value) item.value = "";
console.assert(!item.url, `Cookies must have a URL defined`);
console.assert(
item.url !== "about:blank",
`Blank page can not have cookie "${item.name}"`
);
@karlhorky
karlhorky / index.ts
Last active March 13, 2021 14:52
Use full Chrome with Puppeteer (instead of Chromium)
// Modified / modernized version of https://github.com/puppeteer/examples/blob/master/lighthouse/chromelauncher_puppeteer.js
/**
* Copyright 2018 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@karlhorky
karlhorky / clear-npx-cache.sh
Last active February 7, 2024 05:16
Clear npx cache
# First, remove all the folders in the npx cache location
# https://github.com/npm/cli/issues/1935#issuecomment-745561262
rm -rf $(npm get cache)/_npx/*
@karlhorky
karlhorky / 1-setup.md
Created January 5, 2021 17:04 — forked from troyfontaine/1-setup.md
Signing your Git Commits using GPG on MacOS Sierra/High Sierra

Methods of Signing with GPG

There are now two ways to approach this:

  1. Using gpg and generating keys
  2. Using Kryptonite by krypt.co

This Gist explains how to do this using gpg in a step-by-step fashion. Kryptonite is actually wickedly easy to use-but you will still need to follow the instructions

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing with either GPG or Krypt.co.