Skip to content

Instantly share code, notes, and snippets.

@KeKs0r
KeKs0r / get-jwt.ts
Created January 24, 2023 14:11
Get JWT Token from service account for GCP (to use Google Api in cloudflare workers)
import { subtle } from 'crypto'
import { Base64 } from 'js-base64'
type ServiceAccount = {
private_key_id: string
private_key: string
client_email: string
}
@KeKs0r
KeKs0r / .zshrc
Last active October 22, 2022 10:58
Git Clean Branches
# Delete branches that were deleted on remote
alias git.clean_remote_deleted='git fetch --all -p; git branch -vv | grep ": gone]" | awk '"'"'{ print $1 }'"'"' | xargs -n 1 git branch -D'
# Delete branches that have been merged into main/dev/prod/master
alias git.clean_locally_merged='git branch --merged | egrep -v "(^\*|main|master|dev|prod)" | xargs git branch -d'
alias git.clean='git.clean_remote_deleted && git.clean_locally_merged'
@KeKs0r
KeKs0r / settings.json
Created September 29, 2022 14:52
Tailwind VSCode Config
{
"tailwindCSS.experimental.classRegex": [
"tw:(.*)",
"tw-start([\\w\\W]*?)tw-end",
"[cC][lL][aA][sS][sS].+\"(.*)\"",
"[cC][lL][aA][sS][sS].+'(.*)'",
"clsx\\([\\w\\W]*?\\)",
"twMerge\\([\\w\\W]*?\\)",
"focus:(.*)",
"hover:(.*)",
@KeKs0r
KeKs0r / Description.md
Last active July 8, 2022 14:56
Marcs React Structure 2019 Examples

How I currently write React Apps (2019 Hooks Edition)

Foreword

Most of my products are very MVP-ish, so I dont focus too much on super clean code and high quality, but there are a few patterns that I reuse quite a bit and find useful. But this is not an exhaustive list and the examples might not be as clean as one would think.

Technology Stack

Usually I am not using any sophisticated state Library anymore, the react hooks useState and useReducer in combination with context is absolutely sufficient, at least for UI-State. Everything else is in data persistence, which is in my case either Firebase or Graphql (= Apollo).

@KeKs0r
KeKs0r / error-bubbles-up.js
Created June 17, 2019 14:22
Zeit Would swallow issue
// This actually shows the error in the zeit logs and results in this response
/*
An error occurred with this application.
NO_STATUS_CODE_FROM_LAMBDA
*/
async function start() {
console.log("Before Server");
const server = require("./server");
@KeKs0r
KeKs0r / changeStatus.js
Created May 8, 2019 13:18
Apollo Hooks Mutation Test
import gql from "graphql-tag";
import { get } from "lodash";
import { useCallback } from "react";
import { useMutation } from "react-apollo-hooks";
import { GET_LEAD_HEADER } from "./getLeadHeader";
const CHANGE_STATUS = gql`
mutation changeStatus($id: ID!, $status: String!) {
changeStatus(id: $id, status: $status) {
id
const functions = require("firebase-functions");
const got = require("got");
const _ = require("lodash");
const notifyNewSignup = functions
.runWith({ memory: "128MB" })
.region("europe-west1")
.auth.user()
.onCreate(user => {
const email = user.email;
@KeKs0r
KeKs0r / hapi-arena.js
Last active August 16, 2018 17:29
Get Bull Admin UI (Arena) working with Hapi
const Arena = require('bull-arena');
const _ = require('lodash')
function queueToConfig(queue){
return {
hostId: 'Main Host',
name: queue.name,
prefix: queue.keyPrefix,
host: queue.eclient.options.host,
function queryMiddleware() {
return next => action => {
if (action && action[SIMPLE] !== undefined && action[SIMPLE].query) {
const request = action[SIMPLE];
const query = qs.stringify(request.query, {
arrayFormat: 'brackets',
encode: false
});
request.endpoint = [request.endpoint.replace(/\?*/, ''), query].join('?');
delete request.query;
@KeKs0r
KeKs0r / launch.json
Created March 21, 2018 14:27
Debug Jest Tests in VSCode
{
"name": "Jest",
"type": "node",
"request": "launch",
"env": {
"NODE_ENV": "test"
},
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/node_modules/.bin/jest",
"stopOnEntry": false,