Skip to content

Instantly share code, notes, and snippets.

import { visit, print } from 'graphql'
import { gql } from 'graphql-tag'
// import the models from the generated code
import { getStudent, getTeacher, getClass } from '../graphql/queries'
const getModelSelectionSet = modelDoc =>
modelDoc.definitions[0].selectionSet.selections[0].selectionSet
const attachModelDoc = (doc, fieldName, childDoc) =>
visit(doc, {
@mattfysh
mattfysh / lookup.js
Last active December 30, 2021 00:00
DNS prefetch on Lambda
const dns = require('dns')
const https = require('https')
const url = 'https://example.com'
const { hostname } = new URL(url)
const doLookup = async () => new Promise(resolve => {
const start = new Date()
dns.lookup(hostname, () => {
console.log('dns.lookup', Date.now() - start)
@mattfysh
mattfysh / index.js
Created January 2, 2022 22:20
AWS Lambda + OpenTelemetry :: ADOT nodejs layer not working
const dns = require('dns')
const https = require('https')
const url = 'https://example.com'
const { hostname } = new URL(url)
const doLookup = () => new Promise(resolve => {
dns.lookup(hostname, resolve)
})
const opentelemetry = require('@opentelemetry/sdk-node')
// const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')
const { DnsInstrumentation } = require('@opentelemetry/instrumentation-dns')
const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda')
const { AWSXRayIdGenerator } = require('@opentelemetry/id-generator-aws-xray')
const { AWSXRayPropagator } = require('@opentelemetry/propagator-aws-xray')
// const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http')
const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-proto')
const CONSOLE_DEBUG = false
version: '3.8'
services:
api:
build:
# ...snip...
awscollector:
image: public.ecr.aws/aws-observability/aws-otel-collector
ports:
- '4317:4317'
@mattfysh
mattfysh / noob.py
Last active September 8, 2022 22:05
Reading dynamodb kinesis stream into databricks delta live table
import dlt
from pyspark.sql.functions import from_json, col, expr, transform_values, transform, coalesce
from pyspark.sql.types import *
nf_cdc_schema = StructType([
StructField('eventName', StringType()),
StructField('dynamodb', StructType([
StructField('ApproximateCreationDateTime', LongType()),
StructField('NewImage', StructType([
StructField('service', StructType([
import zlib
from datetime import datetime
import dpkt
def get_tcpip_frame(buf):
# standard pcap uses ethernet root layer
eth = dpkt.ethernet.Ethernet(buf)
if isinstance(eth.data, dpkt.ip6.IP6):
# print('Unexpected: IPv6 protocol')
@mattfysh
mattfysh / example.ts
Created October 8, 2022 01:44
xpath compatibility with parse5 and htmlparser2 tree
import { parse } from 'parse5'
import { adapter } from 'parse5-htmlparser2-tree-adapter'
import xpath from 'xpath'
const html = '...'
const selector = '...'
const doc = parse(html, { treeAdapter: adapter })
const htmlEl = doc.childNodes.find(c => c.name === 'html')
  • Running on Flink v1.13.2
  • as a AWS Kinesis Data Analytics application
const { visit, visitWithTypeInfo, TypeInfo, Kind } = require('graphql')
const { MapperKind, mapSchema, visitData } = require('@graphql-tools/utils')
const { GraphQLObjectType, GraphQLID } = require('graphql')
class Transform {
constructor(groupTypes, typeIdFields) {
this.groupTypes = groupTypes
this.typeIdFields = typeIdFields
}