Skip to content

Instantly share code, notes, and snippets.

View marcolink's full-sized avatar
🪐

Marco Link marcolink

🪐
View GitHub Profile
class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {
@getify
getify / 1-CalendarItem.js
Last active March 21, 2024 09:11
an illustration (non-trivial example) of many newer JS class features
// abstract class, not intended to be instantiated directly
class CalendarItem {
static #UNSET = Symbol("unset")
static #isUnset(v) {
return v === this.#UNSET;
}
static {
for (let [idx,msg] of [
"ID is already set.",
"ID is unset.",
@MichaelCurrin
MichaelCurrin / README.md
Last active March 5, 2024 22:06
GitHub GraphQL - Get files in a repository

Get GitHub Files

Get the metadata and content of all files in a given GitHub repo using the GraphQL API

You might want to get a tree summary of files in a repo without downloading the repo, or maybe you want to lookup the contents of a file again without download the whole repo.

The approach here is to query data from GitHub using the Github V4 GraphQL API.

About the query

@jeffposnick
jeffposnick / service-worker.js
Created September 20, 2019 00:56
Example of InjectManifest in Workbox v5
// Add any other logic here as needed.
import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin';
import { CacheFirst } from 'workbox-strategies/CacheFirst';
import { createHandlerForURL } from 'workbox-precaching/createHandlerForURL';
import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin';
import { NavigationRoute } from 'workbox-routing/NavigationRoute';
import { precacheAndRoute } from 'workbox-precaching/precacheAndRoute';
import { registerRoute } from 'workbox-routing/registerRoute';
@bvaughn
bvaughn / LICENSE.md
Last active November 9, 2023 07:13
Advanced example for manually managing subscriptions in an async-safe way using hooks

The MIT License (MIT)

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

@franzejr
franzejr / introspection_query.graphql
Created October 18, 2018 14:01
GraphQL full Introspection query
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
@bryandh
bryandh / .Service Worker Setup.md
Last active January 25, 2023 16:21
Service Worker setup in Typescript

Service Worker Setup

/**
* TypeScript version of @istarkov's cancellable Promise wrapper.
*
* @see https://github.com/facebook/react/issues/5465#issuecomment-157888325
*/
const makeCancelable = <T>(promise: Promise<T>): { promise: Promise<T>; cancel(): void } => {
let hasCanceled = false;
const wrappedPromise = new Promise<T>((resolve, reject) => {
promise.then(
@luizcarraro
luizcarraro / open-external-link.js
Created July 27, 2017 11:37
ELECTRON: Open link in external default OS browser
@Rich-Harris
Rich-Harris / service-workers.md
Last active May 25, 2024 13:55
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.