Skip to content

Instantly share code, notes, and snippets.

View LunaticMuch's full-sized avatar
💢
I am distilling the world into a model

Stefano LunaticMuch

💢
I am distilling the world into a model
View GitHub Profile
@LunaticMuch
LunaticMuch / shopify.json
Created January 11, 2024 16:04
Shopify Introspection
{
"data": {
"__schema": {
"queryType": {
"name": "QueryRoot"
},
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null,
@LunaticMuch
LunaticMuch / graphql-parents.js
Created January 10, 2024 07:40
find parents in a graphql query
import _ from "lodash";
export function addParent(schema) {
function extractFields(type) {
// no need to inspect circular types any further
if (type.type === "[Circular]") return [type];
// same with scalars and enums
if (_.includes(["SCALAR", "ENUM"], type.kind && type.kind)) return [];
if (
@LunaticMuch
LunaticMuch / sidebar.js
Created December 22, 2023 14:38
Sidebar nested model
[
{
label: 'page 1',
slug: 'page-1'
},
{
label: 'page 2',
slug: 'page-2'
},
{
@LunaticMuch
LunaticMuch / schema.graphql
Created October 2, 2023 19:52
Demo schema for deprecated
type Author {
firstName: String @deprecated
id: Int! @deprecated(reason: "Thrown away")
lastName: String
posts: [Post!]!
}
type Comment {
comment: String!
id: Int!
@LunaticMuch
LunaticMuch / introspected_simplified_schema.json
Last active April 23, 2023 08:22
Introspected Simplified Schema
{
types: {
'TYPE::Author': {
kind: 'OBJECT',
name: 'Author',
description: 'A blog author',
interfaces: [],
fields: {
id: {
name: 'id',
@LunaticMuch
LunaticMuch / userjwtJose.js
Created February 4, 2023 12:11
Token generation with jose
import {SignJWT, jwtVerify, type JWTPayload} from 'jose';
export async function sign(payload: Token, secret: string): Promise<string> {
const iat = Math.floor(Date.now() / 1000);
const exp = iat + 60* 60; // one hour
return new SignJWT({...payload})
.setProtectedHeader({alg: 'HS256', typ: 'JWT'})
.setExpirationTime(exp)
.setIssuedAt(iat)
# The origin of this script is https://gist.github.com/iambchan/273219729eb88155e11672c4ccac72b3
# as linked in the blog post https://building.kickstarter.com/how-to-konmari-your-git-repo-474907a29d2e
# I applied two changes: a fix for cursor loop and add multiple dates for the PR for better reporting
require 'http'
require 'date'
REPOSITORY_OWNER = ""
REPOSITORY_NAME = ""
REFS_PREFIX = "refs/heads/"
@LunaticMuch
LunaticMuch / metarweatherdecoder.swift
Created February 13, 2022 20:34
Decode metar weather string
import Foundation
extension String {
func index(from: Int) -> Index {
return self.index(startIndex, offsetBy: from)
}
func substring(from: Int) -> String {
let fromIndex = index(from: from)
return String(self[fromIndex...])