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 / bookmarklet.js
Created June 11, 2011 04:31
advanced bookmarklet template
javascript:(function() {
if(!window.your_bookmarklet) {
var doc = document,
js = doc.createElement('script');
js.type = 'text/javascript';
js.src = 'loader.js';
js.async = true;
@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?

@kn0ll
kn0ll / clutch.php
Last active October 3, 2022 13:08
an asynchronous http library for php.
<?php
namespace clutch;
class Request {
/**
* The url of the request
* @var string
*/
public $url;
// 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 / proxy.coffee
Last active November 19, 2018 10:12
a simple nodejs request proxy as connect middleware. developed as a cross domain ajax proxy.
###
a small connect middleware proxy for cross domain ajax
@path first match group will be forwarded
@host the host you want to proxy
connect_server.use proxy '^(/.+)', 'api.twitter.com'
connect_server.use proxy '^/gh(/.+)', 'api.github.com'
###
@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];