Skip to content

Instantly share code, notes, and snippets.

View karlhorky's full-sized avatar

Karl Horky karlhorky

View GitHub Profile
@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 / 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.

@karlhorky
karlhorky / .bash_profile
Last active May 5, 2023 14:10 — forked from SherryQueen/.bash_profile
git-bash
alias ...=../..
alias ....=../../..
alias .....=../../../..
alias ......=../../../../..
alias 1='cd -'
alias 2='cd -2'
alias 3='cd -3'
alias 4='cd -4'
alias 5='cd -5'
alias 6='cd -6'
@karlhorky
karlhorky / analyzequotes.sh
Created January 30, 2020 13:10 — forked from pspi/analyzequotes.sh
Calculate ratio of single quotes to double quotes in .js and .ts files
#!/usr/bin/env bash
# TODO:
# - DRY relevant parts
singlequotes=`find -type f \( -iname \*.js -o -iname \*.ts \) -not -path '*node_modules/*' -exec cat \{\} \; | tr -cd \' | wc -c`
doublequotes=`find -type f \( -iname \*.js -o -iname \*.ts \) -not -path '*node_modules/*' -exec cat \{\} \; | tr -cd '"' | wc -c`
total=$(($singlequotes + $doublequotes))
@karlhorky
karlhorky / authentication_with_express_postgres.md
Created October 22, 2019 18:52 — forked from laurenfazah/authentication_with_express_postgres.md
Authentication with an Express API and Postgres

Authentication with an Express API and Postgres

Setting Up

Let's make sure our Express app has the required base modules:

# within root of API
npm install --save express pg knex bcrypt
npm install --save-dev nodemon
  1. Set up a docker-compose.yaml file (file content at the bottom of this page).

  2. Also create a data/mysql folder in your project.

  3. In order to set up a volume for MySQL in Docker Toolbox, we will need a VirtualBox Shared Folder, just like mentioned in Fixing Volumes in Docker Toolbox.

    VirtualBox by default has a c/Users Shared Folder that we can use for this (as long as your project is within C:\Users. Verify that this shared folder is set up properly:

    Capture

  4. Add a new volume to the mydatabase service in the docker-compose.yaml for the database files. Because we are using docker-toolbox and VirtualBox, we need an absolute path, starting with //c/:

    volumes:
  • //c/Users/your_username/projects/wordpress-docker-stack/data/mysql:/var/lib/mysql
@karlhorky
karlhorky / engine-ua-sniffer.js
Created July 10, 2019 16:01 — forked from domenic/engine-ua-sniffer.js
Rendering engine UA sniffer
// This is a minimal UA sniffer, that only cares about the rendering/JS engine
// name and version, which should be enough to do feature discrimination and
// differential code loading.
//
// This is distinct from things like https://www.npmjs.com/package/ua-parser-js
// which distinguish between different branded browsers that use the same rendering
// engine. That sort of distinction is maybe useful for analytics purposes, but
// for differential code loading it is overcomplicated.
//
// This is meant to demonstrate that UA sniffing is not really that hard if you're
import React, { useState, useEffect } from "react";
import "./packages/combobox/styles.css";
import {
Combobox,
ComboboxInput,
ComboboxList,
ComboboxOption,
ComboboxPopup
} from "./packages/combobox/index";
@karlhorky
karlhorky / .gitconfig
Last active July 18, 2023 01:28 — forked from gnarf/..git-pr.md
Fetch and delete refs to GitHub pull request branches
[alias]
fetch-pr = "!f() { git fetch origin refs/pull/$1/head:pr/$1; } ; f"
delete-prs = "!git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done"