Skip to content

Instantly share code, notes, and snippets.

View kn0ll's full-sized avatar
🏠
Working from home

Nic Luciano kn0ll

🏠
Working from home
View GitHub Profile
@kn0ll
kn0ll / useHass.ts
Last active December 21, 2019 10:27
home assistant react hooks
import constate from "constate";
import * as React from "react";
import {
Connection,
subscribeEntities,
HassEntities,
AuthData,
Auth,
createConnection
} from "home-assistant-js-websocket";
@kn0ll
kn0ll / QueryRenderer.tsx
Last active July 23, 2020 20:46
attempts to abstract / manage handling apollo network logic. a strongly typed pattern matching type thing for Apollo
import * as React from 'react';
import { QueryResult } from 'react-apollo';
import { ApolloError } from 'apollo-client';
export enum QueryRendererState {
LOADING,
EXPECTED_ERROR,
UNEXPECTED_ERROR,
READY,
}
@kn0ll
kn0ll / useTransport.ts
Last active November 22, 2020 07:16
react hook for declarative use of TimingObject
// thank you https://github.com/chrisguttandin/timing-object
import { useEffect, useMemo, useRef, useState } from "react";
import { TimingObject, ITimingObject } from "timing-object";
interface TransportParams {
state: "paused" | "started" | "stopped";
bpm: number;
}
// just a quick and dirty port, didn't really think it out much. just made this to help me conceptualize RTC
// (i was not happy with my findings)
import { useCallback, useMemo, useRef, useState } from "react";
const WebRTCDemo: React.FC = () => {
const connection = useRef<
Partial<{
localConnection: RTCPeerConnection;
sendChannel: RTCDataChannel;
@kn0ll
kn0ll / question1.md
Last active December 8, 2022 04:17
conversations with an advanced chatbot

do you know about "fp-ts"?

Yes, I am familiar with the "fp-ts" library. It is a library for TypeScript and JavaScript that provides various tools for working with functional programming in these languages. Some of the features of fp-ts include a wide range of type-safe data structures, support for common functional patterns, and utilities for working with type classes and other functional concepts.

Why do monads in "fp-ts" include a "tag" property?

In the context of the fp-ts library, the "tag" property of a monad is a way of identifying the specific type of the monad. This can be useful for type checking and for ensuring that the correct methods are being called on the monad. For example, the Option monad in fp-ts has a tag value of Some or None, which indicates whether the Option has a value or not. This allows the fp-ts library to provide type-safe methods for working with Option values, such as map, chain, and getOrElse.

why can't they use the "in" operator to narrow the types instead of a tag?