Skip to content

Instantly share code, notes, and snippets.

@pixeldrew
pixeldrew / make-token.ts
Last active August 21, 2023 13:51
JWT with vault key using vault encryption
import {
KeyClient,
CryptographyClient,
} from "@azure/keyvault-keys";
import { DefaultAzureCredential } from "@azure/identity";
import { createHash } from "crypto";
const vaultUrl = `https://${process.env.AZURE_KEYVAULT_NAME}.vault.azure.net`;
const credential = new DefaultAzureCredential();
const keyClient = new KeyClient(vaultUrl, credential);
@pixeldrew
pixeldrew / make-token.ts
Last active August 20, 2023 03:19
Usint a cert stored in Azure Keyvault to generate an RS256 JWT Token
import { SecretClient } from "@azure/keyvault-secrets";
import { DefaultAzureCredential } from "@azure/identity";
import * as jose from "node-jose";
const vaultUrl = `https://${process.env.AZURE_KEYVAULT_NAME}.vault.azure.net`;
const credential = new DefaultAzureCredential();
const secretClient = new SecretClient(vaultUrl, credential);
async function main() {
const keyVaultKey = await secretClient.getSecret("jwkdemo");
@pixeldrew
pixeldrew / downloads
Last active June 17, 2022 02:25
This will get a decent docker/podman dev setup with kubectl and az client environment setup for m1
#!/bin/bash
export WORK=work
# download https://download.developer.apple.com/Developer_Tools/Xcode_13.4.1/Xcode_13.4.1.xip
curl -LO https://github.com/macports/macports-base/releases/download/v2.7.2/MacPorts-2.7.2-12-Monterey.pkg
read -rsp $'Install XCode and Macports then Press any key to continue...\n' -n1 key
@pixeldrew
pixeldrew / cursor-helper.js
Last active January 19, 2022 22:21 — forked from pcattori/gist:2bb645d587e45c9fdbcabf5cef7a7106
relay-style cursor-based pagination capable of filtering/sorting for SQL
const { Base64 } = require('js-base64')
const { Op } = require('sequelize');
// https://github.com/graphql/graphql-relay-js/issues/94#issuecomment-232410564
const effectiveOrder = ({ last }, orderBy) => {
/* adds `id ASC` to end of `ORDER BY` if `id` is not already in the `ORDER BY` clause
flips `ASC` to `DESC` (and vice-versa) if pagination arg `last` is defined
*/
const order = orderBy
@pixeldrew
pixeldrew / .config
Last active October 5, 2021 00:41
Klipper config with skr min e3 with Ender 3, EZ-ABL and Pi connected via UART on the TFT out header
CONFIG_LOW_LEVEL_OPTIONS=y
# CONFIG_MACH_AVR is not set
# CONFIG_MACH_ATSAM is not set
# CONFIG_MACH_ATSAMD is not set
# CONFIG_MACH_LPC176X is not set
CONFIG_MACH_STM32=y
# CONFIG_MACH_RP2040 is not set
# CONFIG_MACH_PRU is not set
# CONFIG_MACH_LINUX is not set
# CONFIG_MACH_SIMU is not set
BUSINESS_RELEASE=loris
RELEASE_DATE="October 20th, 2020"
## update local repo
git fetch
# housekeeping
# delete local branches that are merged
git branch --merged | egrep -v "(^\*|master|dev)" >/tmp/merged-branches && \
vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
# prune remote
ssh_authorized_keys:
- github:pixeldrew
k3os:
k3s_args:
- server
- "--no-deploy"
- traefik
ssh_authorized_keys:
- github:pixeldrew
k3os:
k3s_args:
- server
- "--no-deploy"
- traefik
@pixeldrew
pixeldrew / useForm.js
Created September 1, 2019 03:09
Simple Form Hook
function useForm(callback, defaultValues, schema) {
const [values, setValues] = useState({ ...defaultValues });
const [errors, setErrors] = useState([]);
const [validateOnChange, setValidateOnChange] = useState(false);
async function validate() {
if (schema) {
const errors = await catchErrors();
if (errors.length > 0) {
setErrors([...errors]);
@pixeldrew
pixeldrew / server.js
Created August 5, 2019 04:45
NextJS and ApolloServer playing nice
const path = require("path");
const next = require("next");
const express = require("express");
const { createServer } = require("http");
const { ApolloServer } = require("apollo-server-express");
const helmet = require("helmet");
const { PORT = 3000, NODE_ENV = "dev" } = process.env;
const port = parseInt(PORT, 10);