Skip to content

Instantly share code, notes, and snippets.

View reconbot's full-sized avatar
🏴‍☠️
Building at @github

Francis Gulotta reconbot

🏴‍☠️
Building at @github
View GitHub Profile
@reconbot
reconbot / batchFetchExchange.ts
Last active February 13, 2024 11:19
A batching exchange for URQL that lets you opt out of batch queries adapted form @jakubriedl's POC This version works on non persisted queries.
// Adapted from https://gist.github.com/jakubriedl/812c2a7b26927a2249a4719555d9a0ca
import DataLoader from 'dataloader'
import { Exchange, Operation } from 'urql'
import { pipe, map } from 'wonka'
interface BatchRequest {
url: RequestInfo | string
options?: RequestInit
}
// label any email with archive-after/2-hours or archive-after/1-day (any number of days or hours) and it does!
// you can optionaly nest the labels eg `archive-after` and make `2-hours` inside the archive after - the script doesn't seem to care!
// Install steps
// create a new project here https://script.google.com/
// create a new file with this contents
// then create a trigger to run it every 10 minutes
// enjoy!
const LABEL_REGEX = /archive-after\/(\d+)-(day|hour)s?/
@reconbot
reconbot / graphql-playground.tsx
Created July 1, 2021 15:22
How to get graphql playground to work on nextjs
import dynamic from 'next/dynamic'
import Head from 'next/head'
const WS_URL = process.env.NEXT_PUBLIC_WS_API_ENDPOINT
const API_URL = process.env.NEXT_PUBLIC_API_ENDPOINT
// You might ask yourself, what is this business?
// And I might ask why on earth does Playground require window on module load breaking any hope
// of ssr even if we don't render it but only import it
const Playground = dynamic<any>(
@reconbot
reconbot / day1.go
Created December 4, 2023 17:42
a broken program for solving day 1
package main
import (
"bufio"
"os"
"regexp"
"strconv"
"strings"
)
@reconbot
reconbot / AsyncDisposableTransaction.test.ts
Last active November 6, 2023 14:38
An example of using Symbol.asyncDispose to easily cleanup remote resources when an execption occures.
import test, { describe } from 'node:test'
import { AsyncDisposableTransaction } from './AsyncDisposableTransaction'
import assert, { deepEqual, equal, rejects } from 'node:assert'
describe('AsyncDisposableTransaction', () => {
test('should rollback when not committed', async () => {
let rollbackCalled = false
await (async () => {
await using transaction = new AsyncDisposableTransaction()
transaction.rollback(() => {
esphome:
name: esphome-web-XXXXXX
friendly_name: XXXXX
esp8266:
board: esp01_1m
# Enable Home Assistant API
api:
encryption:
[
"Borrowing some flour",
"Waiting for the report to rise",
"Double checking the weights",
"Proofing the report",
"Was that one egg or two?",
"Toasting the oats",
"Loading the kneaded info",
"Reticulating splines",
"Mixing the customers and orders",
sensor:
- platform: cse7766
current:
name: "current"
accuracy_decimals: 1
voltage:
name: "voltage"
accuracy_decimals: 1
power:
name: "power"
@reconbot
reconbot / createComplexityPlugin.ts
Last active June 20, 2023 14:43
An Apollo Plugin for graphql-query-complexity
import { ComplexityEstimator, getComplexity } from 'graphql-query-complexity'
import { GraphQLError, GraphQLSchema, separateOperations } from 'graphql'
import { PluginDefinition } from 'apollo-server-core'
export const createComplexityPlugin = ({
schema,
maximumComplexity,
estimators,
onComplete,
createError = (max, actual) => { throw new GraphQLError(`Query too complex. Value of ${actual} is over the maximum ${max}.`) },
@reconbot
reconbot / hackerchat.rs
Created February 22, 2023 03:35
this time it doesn't crash - doesn't seem to read from the network though
use std::{net::{SocketAddr, Ipv4Addr}, sync::Arc};
use tokio::net::{UdpSocket}; //UdpFramed
use anyhow::{Context, Result};
// use tokio::time::sleep;
// use std::time::Duration;
use socket2::{Socket, Domain, Type, Protocol};
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::sync::mpsc::{self, Receiver, Sender};
use futures::try_join;