Skip to content

Instantly share code, notes, and snippets.

View wegry's full-sized avatar

Zach Wegrzyniak wegry

  • Boston
  • 21:29 (UTC -05:00)
View GitHub Profile
@wegry
wegry / dayjs-codec.mts
Created July 11, 2024 18:42
Codec to parse create dayjs instances from strings
import * as t from 'io-ts'
import dayjs, { Dayjs } from 'dayjs'
import { pipe } from 'fp-ts/lib/function'
import { chain } from 'fp-ts/lib/Either'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
export const isoDate = new t.Type<Dayjs, string, unknown>(
'isoDate',
(u): u is Dayjs => dayjs.isDayjs(u),
<head>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"
type="application/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"
type="application/javascript"
></script>
<script>
{
"version": "0.0.13",
"browserslist": [
"last 2 chrome versions",
"last 2 firefox versions",
"last 1 safari versions"
],
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.30",
"@fortawesome/free-solid-svg-icons": "^5.14.0",
@wegry
wegry / machine.js
Last active January 5, 2021 15:27
Generated by XState Viz: https://xstate.js.org/viz
// To see it in action https://xstate.js.org/viz/
// Since this snippet isn't functioning on its own, turn off some rules
/* eslint-disable new-cap, @typescript-eslint/ban-ts-comment */
// @ts-nocheck
Machine({
id: 'starting',
initial: 'starting',
states: {
build: {
@wegry
wegry / sass-ast.sh
Created March 13, 2020 20:44
Use sast-parse to get AST from SASS file
npx -p sast sast-parse ../../color-contrast-matrix/src/App.scss -f=yaml -WP
@wegry
wegry / result.out.js
Last active July 10, 2019 13:24
Typescript Result Types
"use strict";
// Typescript 3.5.2
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = __importDefault(require("lodash"));
function Err(value) {
return {
kind: 'error',
@wegry
wegry / debounce.js
Created February 21, 2019 11:04
Minature debounce borrowed and tweaked from vue-js-tips
// https://github.com/vuejs-tips/tiny-debounce/blob/master/index.js
function debounce(fn, delay) {
let timeoutID = null;
return (...args) => {
clearTimeout(timeoutID);
timeoutID = setTimeout(() => {
fn(...args)
}, delay);
}
}
@wegry
wegry / server.rs
Last active August 4, 2019 22:56
Basic Rust 2018 Static File Server
use colored::*;
use futures::{future, Future};
use hyper::header::{HeaderName, HeaderValue};
use hyper::service::service_fn;
use hyper::{Body, Request, Response, Server};
use hyper::{Method, StatusCode};
use lazy_static::lazy_static;
use maplit::btreemap;
use std::collections::BTreeMap;
use std::path::Path;
@wegry
wegry / Tsv.fs
Created November 16, 2018 09:49
Write TSV relatively regularly
module Csv
// Transliterated from https://stackoverflow.com/a/4685745/1924257
module private Internals =
let quote = "\""
let escapedQuote = "\\\""
let delimiter = "\t"
let escapedCharacters = ['\t'; '\n'] |> Set.ofList
@wegry
wegry / JsonNetExtension.fs
Created November 13, 2018 09:59
Use Option<T> instead of null with Json.NET and F#
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
/// F# options-converter
type OptionConverter() =
inherit JsonConverter()
override __.CanConvert t = t.IsGenericType && typedefof<option<_>>.Equals(t.GetGenericTypeDefinition())
override __.WriteJson(writer, value, serializer) =