Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@GavinRay97
GavinRay97 / objectDestructuringExamples.js
Last active December 25, 2017 02:09
Working with Complex Objects via ES6 Object Destructuring/Pattern Matching
var myObject = {
name: 'myObject',
number: 9001,
nestedObject: {
nestedName: 'nestedName',
nestedBasicArray: [1,2,3],
nestedObjectArray: [{firstThing: 11, secondThing: 12}, {firstThing: 21, secondThing: 22}, {firstThing: 31, secondThing: 32}]
}
}
@GavinRay97
GavinRay97 / substring.js
Created April 29, 2018 06:39
Find all unique substrings of a string
const findUniqueSubstrings = (str) => {
const arr = [...str].reduce((acc, _, idx) =>
acc.concat(Array.from({length: str.length}, (_, innerIdx) =>
str.substring(idx, innerIdx + 1)
)), [])
return new Set(arr)
}
findUniqueSubstrings("Your string here")
@GavinRay97
GavinRay97 / api.v
Created January 1, 2020 20:29
V match-expression web routing
module main
import (
os
net
net.http
net.urllib
strings
)
@GavinRay97
GavinRay97 / print-element.js
Created January 27, 2020 23:45
Print DOM element (avoids rendering issues)
printElement(selector) {
const elem = document.querySelector(selector)
var printWindow = window.open('','PrintWindow', 'width=400,height=200');
html2canvas(elem).then(canvas => {
var doc = printWindow.document
var img = doc.createElement('img')
img.src = canvas.toDataURL('image/png')
doc.body.appendChild(img)
setTimeout(() => {
printWindow.print()
@GavinRay97
GavinRay97 / index.md
Last active April 12, 2024 18:31
Hasura organization permissions

Introduction

This document outlines how to model a common organization-based permission system in Hasura. Let's assume that you have some table structure like the following:

Table Name Columns Foreign Keys
User id, name, email
Organization User id, user_id, organization_id user_id -> user.id, organization_id -> organization.id
Organization id, name
@GavinRay97
GavinRay97 / file.ts
Created May 13, 2020 22:08
Vue 3 Composition API Typescript Component Props
import { defineComponent, computed, ref } from '@vue/composition-api'
interface User {
firstName: string
lastName: number
}
export default defineComponent({
props: {
user: {
@GavinRay97
GavinRay97 / Pulumi.production.yaml
Created June 29, 2020 23:00
Deploy Hasura on Fargate, including creating a Route53 Domain w/ Cert Manager certificate, and Load Balancer configured for HTTPS on new domain
config:
aws:region: us-east-2
my-project:HASURA_GRAPHQL_DATABASE_URL:
secure: <snipped>
@GavinRay97
GavinRay97 / guide.md
Last active January 4, 2022 05:38
Configuring Nuxt for Composition API and TSX Support

Main

EDIT: DO NOT USE THIS. THIS WAS FROM WHEN ALL OF THIS WAS NEW/EXPERIMENTAL AND NOT OFFICIALLY SUPPORTED. PLEASE SEE THE LINK BELOW FOR THE PROPER, EASIER INTEGRATION NOWADAYS =)

Use create-nuxt-app and enable the Typescript related options to scaffold a new boilerplate TS Nuxt repo:

yarn create nuxt-app 
@GavinRay97
GavinRay97 / HasuraMetadataV2.hs
Created July 6, 2020 18:44
Hasura Metadata V2 Haskell Generated
{-# LANGUAGE StrictData #-}
{-# LANGUAGE OverloadedStrings #-}
module QuickType
( PGColumn (..)
, ComputedFieldName (..)
, RoleName (..)
, TriggerName (..)
, RemoteRelationshipName (..)
, RemoteSchemaName (..)
@GavinRay97
GavinRay97 / hasura_metadata_v2.go
Created July 6, 2020 18:47
Hasura Metadata V2 Go Generated
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// pGColumn, err := UnmarshalPGColumn(bytes)
// bytes, err = pGColumn.Marshal()
//
// computedFieldName, err := UnmarshalComputedFieldName(bytes)
// bytes, err = computedFieldName.Marshal()
//
// roleName, err := UnmarshalRoleName(bytes)