Skip to content

Instantly share code, notes, and snippets.

View dralletje's full-sized avatar
🛰️
😱🦁🤨

Michiel Dral dralletje

🛰️
😱🦁🤨
View GitHub Profile
@dralletje
dralletje / useFragment.ts
Created June 25, 2025 12:43
`useFragment` composable for Vue & Apollo
import type { Reference, StoreObject, TypedDocumentNode } from '@apollo/client';
/**
* Returns an always-up-to-date view of whatever data the cache currently contains for a given fragment and useFragment
* never triggers network requests of its own.
*
* Based on https://www.apollographql.com/docs/react/api/react/hooks#usefragment code at https://github.com/apollographql/apollo-client/blob/a8fe0a1217d9784d3165e0ec2e88a2caca0f82d7/src/react/hooks/useFragment.ts#L1-L108
*
* I've taken this from https://github.com/vuejs/apollo/issues/1510 with a bit more tweaks from the apollo react codebase.
*
{
/// Bunch of not showing stuff
"editor.lineNumbers": "off",
"editor.minimap.enabled": false,
"editor.renderLineHighlight": "none",
"editor.occurrencesHighlight": "off",
"window.customTitleBarVisibility": "windowed",
"workbench.layoutControl.enabled": false,
"breadcrumbs.enabled": false,
"scm.diffDecorations": "none",
# ╔═╡ 0518f61d-daa5-4d9d-a953-d05d8e1f2870
import HypertextLiteral: @htl
# ╔═╡ 35f8353a-6fd6-4d66-8a76-17b3c51bc1ad
import Printf: @sprintf
# ╔═╡ 938f5064-ace6-4614-a6ec-b1b555d4fb1e
function displayround(number::Number; digits::Number)
@htl """
<div style=$(Dict(
@dralletje
dralletje / awesome-line-wrapping.js
Created October 13, 2022 19:40
Latest version of my soft-wrapping codemirror extension
/**
* Plugin that makes line wrapping in the editor respect the identation of the line.
* It does this by adding a line decoration that adds padding-left (as much as there is indentation),
* and adds the same amount as negative "text-indent". The nice thing about text-indent is that it
* applies to the initial line of a wrapped line.
*
* The identation decorations have to happen in a StateField (without access to the editor),
* because they change the layout of the text :( The character width I need however, is in the editor...
* So I do this ugly hack where I, in `character_width_listener`, I fire an effect that gets picked up
* by another StateField (`extra_cycle_character_width`) that saves the character width into state,
### A Pluto.jl notebook ###
# v0.17.1
using Markdown
using InteractiveUtils
# ╔═╡ 19f83c25-828c-4cf3-9086-9088e51f07f9
import HypertextLiteral: @htl
# ╔═╡ fc30418d-ed9a-4287-be30-ed1fa4ec3fc7
### A Pluto.jl notebook ###
# v0.17.1
using Markdown
using InteractiveUtils
# ╔═╡ 169b7cf5-e220-43e9-8041-6d22936bb5bd
import Pkg
# ╔═╡ e24a3b1f-bc46-44e6-83d7-fa0f98011fd8
### A Pluto.jl notebook ###
# v0.17.1
using Markdown
using InteractiveUtils
# ╔═╡ 19f83c25-828c-4cf3-9086-9088e51f07f9
import HypertextLiteral: @htl
# ╔═╡ fc30418d-ed9a-4287-be30-ed1fa4ec3fc7
### A Pluto.jl notebook ###
# v0.17.1
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@dralletje
dralletje / awesome-line-wrapping.js
Created September 25, 2021 20:25
Codemirror 6 line wrapping that preserves indentation
import _ from "lodash"
import { StateEffect, StateField } from "@codemirror/state"
import { EditorView, Decoration } from "@codemirror/view"
/**
* Plugin that makes line wrapping in the editor respect the identation of the line.
* It does this by adding a line decoration that adds padding-left (as much as there is indentation),
* and adds the same amount as negative "text-indent". The nice thing about text-indent is that it
* applies to the initial line of a wrapped line.
*
@dralletje
dralletje / ColoredTerminal.jl
Last active November 18, 2023 22:25
Colored `with_terminal` for Pluto.jl
### A Pluto.jl notebook ###
# v0.15.1
using Markdown
using InteractiveUtils
# ╔═╡ 2da76520-1615-11ec-1ad7-8f93957b2e6e
import IOCapture
# ╔═╡ 7d63286d-2320-49bf-a8a1-e538f53ba829