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 / 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?

// 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 / 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;
}
@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 / 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 / blurbcloud.py
Created September 12, 2015 07:19
super hacky script for taking a song off soundcloud and creating a new version where the computer incessantly reads user comments over the audio
import random
import urllib
import urllib2
import soundcloud
import subprocess
from pydub import AudioSegment
def get_track(client_id, sc_url):
client = soundcloud.Client(client_id=client_id)
track = client.get('/resolve', url=sc_url)
define([
'Audiolet'
], (
Audiolet
) => {
class Mixer extends AudioletGroup {
constructor(audiolet) {
super(audiolet, 1, 1);
@kn0ll
kn0ll / backbone.collectionlayout.js
Created June 26, 2013 15:39
simple backbone collection layout. extends backbone.layout.js. accepts an `ItemView` and a `collection` and appends a new `ItemView` to it's parent container for each model in the collection
Backbone.CollectionLayout = Backbone.Layout.extend({
initialize: function() {
Backbone.Layout.prototype.initialize.apply(this, arguments);
this.listenTo(this.collection, 'add', _.bind(this.modelAdded, this));
},
ItemView: Backbone.Layout,
modelAdded: function(model) {
@kn0ll
kn0ll / backbone.layout.js
Last active December 19, 2015 00:28
simple backbone layout manager (simple subview definitions, with listener cleanup)
Backbone.Layout = Backbone.View.extend({
initialize: function() {
this.viewReferences = {};
Backbone.View.prototype.initialize.apply(this, arguments);
},
setView: function(selector, view) {
var $foundViewNode = $(selector, this.$el),
previousView = this.viewReferences[selector];
@kn0ll
kn0ll / session.coffee
Created February 28, 2013 04:53
a session model for brainy
define [
'backbone',
'resources/user'
], (Backbone, User) ->
class extends Backbone.Model
idAttribute: '_id'
urlRoot: '/sessions'
defaults: