Skip to content

Instantly share code, notes, and snippets.

View ZempTime's full-sized avatar

Chris Zempel ZempTime

View GitHub Profile
@ZempTime
ZempTime / costview.rb
Created March 26, 2021 14:33
Redshift cost analyzer
# ex: ruby ./costsort.rb /path/to/query.txt
# look for biggest change furthest in middle of tree
path = ARGV[0]
line_number = 0
results = []
File.open(path, 'r').each_line do |line|
if line.include?("cost=")
@ZempTime
ZempTime / convertScript.js
Last active June 12, 2020 22:19
Chameleon Conversion Script - place in root, then run with default vscode node launcher
const fs = require("fs");
const path = require("path");
/**
for each package
Convert src/* kebab-case to ClassCase
Look inside, remove any customElements.define usage
for each camelCase name not containing style or .d.ts or Index.js -
write a kebab-cased export that defines custom element
for each camelCase name not containing Index.js
@ZempTime
ZempTime / mixins.ts
Created May 13, 2020 19:57
Mixin Exploration
// Following along withhttps://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/
// Basic Mixin Implementation
const MyMixin = (superclass: any) =>
class extends superclass {
foo() {
console.log("foo from MyMixin");
}
@ZempTime
ZempTime / authzexample.ts
Created January 25, 2020 17:03
GraphQL Directives
// Example usage:
// type Query {
// organizations(
// where: OrganizationWhereInput
// first: Int
// skip: Int
// orderBy: OrganizationOrderByInput
// ): [Organization]! @hasPermission(requires: [OEM_ADMIN, ORG_ADMIN])
// organization(id: ID!): Organization
// associatedOrganization: Organization @isAuthenticated
@ZempTime
ZempTime / directives.ts
Created November 19, 2019 23:07
Authz Schema Directives
import { SchemaDirectiveVisitor } from "apollo-server-koa";
import { GraphQLField, defaultFieldResolver } from "graphql";
class IsAuthenticatedDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field;
field.resolve = async function(...args) {
const ctx = args[2];
if (!ctx.state.user.id) {
throw new Error("You must be signed in to do this.");
@ZempTime
ZempTime / machine.js
Created November 12, 2019 18:00
Generated by XState Viz: https://xstate.js.org/viz
const programsQuery = ctx => {
return new Promise(resolve => {
setTimeout(() => {
resolve({
program: {
id: ctx.params.id,
name: 'hey',
},
});
}, 1000);
@ZempTime
ZempTime / machine.js
Last active November 10, 2019 16:50
Generated by XState Viz: https://xstate.js.org/viz
const buildTask = (taskName, resolver) => {
return {
[taskName]: {
initial: "resolving",
states: {
resolving: {
invoke: {
id: taskName,
src: ctx => resolver(ctx),
onError: "errored",
@ZempTime
ZempTime / machine.js
Created September 18, 2019 21:02
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine(
{
id: 'multiply',
initial: 'addThenMultiply',
states: {
addThenMultiply: {
on: {
TOGGLE: 'multiplyThenAdd',
INCREMENT: {
@ZempTime
ZempTime / machine.js
Created September 17, 2019 18:37
Generated by XState Viz: https://xstate.js.org/viz
const wordMachine = Machine({
id: 'word',
type: 'parallel',
states: {
bold: {
initial: 'off',
states: {
on: {
on: { TOGGLE_BOLD: 'off' }
},
@ZempTime
ZempTime / machine.js
Created September 17, 2019 17:39
Generated by XState Viz: https://xstate.js.org/viz
const lightMachine = Machine({
id: 'light',
initial: 'green',
type: 'compound',
states: {
green: {
on: {
TIMER: 'yellow'
}
},