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 / 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)
@GavinRay97
GavinRay97 / hasuraMetadataV2.ts
Created July 6, 2020 18:48
Hasura Metadata V2 Typescript Generated
// To parse this data:
//
// import { Convert, TableName, QualifiedTable, TableConfig, TableEntry, CustomRootFields, FunctionName, QualifiedFunction, Function, FunctionConfiguration, ObjectRelationship, ObjRelUsing, ObjRelUsingManualMapping, ArrayRelationship, ArrRelUsing, ArrRelUsingFKeyOn, ArrRelUsingManualMapping, InsertPermissionEntry, InsertPermission, SelectPermissionEntry, SelectPermission, UpdatePermissionEntry, UpdatePermission, DeletePermissionEntry, DeletePermission, ComputedField, ComputedFieldDefinition, EventTrigger, EventTriggerDefinition, EventTriggerColumns, OperationSpec, HeaderFromValue, HeaderFromEnv, RetryConf, CronTrigger, RetryConfST, RemoteSchema, RemoteSchemaDef, RemoteRelationship, RemoteRelationshipDef, QueryCollectionEntry, QueryCollection, AllowList, CustomTypes, InputObjectType, InputObjectField, ObjectType, ObjectField, CustomTypeObjectRelationship, ScalarType, EnumType, EnumValue, Action, ActionDefinition, InputArgument, HasuraMetadataV2 } from "./file";
//
// const pGColum
@GavinRay97
GavinRay97 / v-switch.vue
Last active July 13, 2020 15:09
v-switch component
<!-- File: `v-switch.vue` -->
<script>
export default {
functional: true,
props: {
value: { type: [String, Number], required: true }
},
render(h, { data, props, scopedSlots }) {
const { value } = props
const slotFn = value in scopedSlots ? scopedSlots[value] : scopedSlots.default
@GavinRay97
GavinRay97 / example.sh
Last active July 13, 2020 20:36
Bash Regex with capture groups
#! /bin/bash
# VERSION NAME SOURCE STATUS DATABASE STATUS
# 1594317652188 - Not Present Present
# 1594317688377 - Not Present Present
# 1594320512973 - Not Present Present
# 1594320556497 - Not Present Present
function scan_entries_for_not_present() {
# timestamp name source status database status
@GavinRay97
GavinRay97 / index.js
Created August 4, 2020 17:13
GraphQL Tx over Websocket SDK
const WebSocket = require('ws')
const WebSocketAsPromised = require('websocket-as-promised')
// SDK Code
const socketFactory = (url) =>
new WebSocket(url, 'graphql-tx', {
headers: {
'X-Hasura-Tx-Isolation': 'serializable',
},
})