Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
const { useRef } = React
const Graph = () => {
const fgRef = useRef();
return <ForceGraph2D
ref={fgRef}
graphData={data}
nodeCanvasObject={nodeCanvasObject}
nodePointerAreaPaint={nodePointerAreaPaint}
function nodeCanvasObject(node, ctx, globalScale) {
const nodeColour = 'red'
const fontSize = 12/globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
const textWidth = ctx.measureText(node.name).width;
const bckgDimensions = [textWidth, fontSize].map(n => n + fontSize * 0.2); // some padding
// node circle
ctx.fillStyle = 'red'
ctx.beginPath()
ReactDOM.render(
<ForceGraph2D
graphData={data}
/>,
document.getElementById('graph')
)
const data = {
nodes: [
{
id: "persona-unauthorised-user",
name: "Unauthorised user"
},
{
id: "persona-authorised-user",
name: "Authorised user"
},
@colinfwren
colinfwren / onAppear.swft
Created August 17, 2024 19:19
using onAppear to re-render PDF
struct CVDetailView: View {
@State private var cvdata: Data?
var body: some View {
VStack {
if (cvData != nil) {
CVPreviewView(pdfData: PDFDocument(data: cvData!)!)
}
}
.onAppear {
@colinfwren
colinfwren / CVPreviewView.swift
Created August 17, 2024 19:17
CV Preview View
import SwiftUI
import PDFKit
import PDFBlocks
struct CVPreviewView: UIViewRepresentable {
var pdfDocument: PDFDocument
init(pdfData pdfDoc: PDFDocument) {
self.pdfDocument = pdfDoc
}
@colinfwren
colinfwren / reading-values-after-test.ts
Created August 4, 2024 20:17
Reading values from Appwrite after test
async function getRecordDetails(recId: String): Promise<Models.Doc> {
const client = new Client()
.setEndpoint(APPWRITE_URL)
.setProject(APPWRITE_PROJECT)
.setKey(APPWRITE_API_KEY)
const databases = new Databases(client)
return databases.getDocument(DATABASE_ID, COL_ID, recId)
}
@colinfwren
colinfwren / calling-graphql-http.ts
Created August 4, 2024 20:15
Calling GraphQL via HTTP
const graphqlString = `
mutation Something($somethingData: SomethingInput!) {
something(somethingData: $somethingData) {
name
}
}
`
test('something that requires user auth', async () => {
const { jwt } = await getNewUser()
@colinfwren
colinfwren / graphql-hooks.ts
Created August 4, 2024 20:14
Setting up and tearing down Apollo
describe('a feature of the app', () => {
let server, url
beforeAll(async () => {
// assigns the values returned to the variables in the upper scope
({ server, url } = await createApolloServer({ port: 0 }))
})
afterAll(async () => {
await server?.stop()