Skip to content

Instantly share code, notes, and snippets.

View paulyoung's full-sized avatar
💭
Type check and prove things

Paul Young paulyoung

💭
Type check and prove things
View GitHub Profile
@tfausak
tfausak / DerivingViaPlugin.hs
Last active August 23, 2021 14:13
Cursed Haskell: Deriving via plugin
-- https://downloads.haskell.org/~ghc/9.0.1/docs/html/users_guide/extending_ghc.html#compiler-plugins
-- https://downloads.haskell.org/~ghc/9.0.1/docs/html/libraries/ghc-9.0.1/GHC-Plugins.html
module DerivingViaPlugin where
import qualified Control.Monad as Monad
import qualified GHC.Data.Bag as G
import qualified GHC.Hs as G
import qualified GHC.Plugins as P
import qualified GHC.Types.Basic as G
$ sha256sum $(nix-build -E '(import (builtins.fetchGit { url = "[email protected]:dfinity/sdk"; ref = "refs/tags/0.7.0";} + "/distributed-canisters.nix") {})')/*/*.wasm
2664385b7ad001123d8cea1f7147fad005d012116139787d9054b2f3a62718ec /nix/store/0s2iplbgj08d32xdyjcwwyajhhg9fgzs-distributed-canisters/assetstorage/assetstorage.wasm
d6e9f851519a6dc419e3281448a84e4866fbb5011258868e2b5dda31d529bdcf /nix/store/0s2iplbgj08d32xdyjcwwyajhhg9fgzs-distributed-canisters/ui/ui.wasm
a609400f2576d1d6df72ce868b359fd08e1d68e58454ef17db2361d2f1c242a1 /nix/store/0s2iplbgj08d32xdyjcwwyajhhg9fgzs-distributed-canisters/wallet/wallet.wasm
$ sha256sum $(nix-build -E '(import (builtins.fetchGit { url = "[email protected]:dfinity/sdk"; ref = "refs/tags/0.7.1";} + "/distributed-canisters.nix") {})')/*/*.wasm
2664385b7ad001123d8cea1f7147fad005d012116139787d9054b2f3a62718ec /nix/store/0s2iplbgj08d32xdyjcwwyajhhg9fgzs-distributed-canisters/assetstorage/assetstorage.wasm
d6e9f851519a6dc419e3281448a84e4866fbb5011258868e2b5dda31d529bdcf /nix/s
import Blob "mo:base/Blob";
import Debug "mo:base/Debug";
import Text "mo:base/Text";
actor {
type HeaderField = (Text, Text);
type HttpRequest = {
method: Text;
url: Text;
@martinrue
martinrue / serve.js
Created March 18, 2021 16:49
Using esbuild's serve function for an SPA, equivalent to webpack's `devServer.historyApiFallback`.
const http = require("http");
const esbuild = require("esbuild");
const serve = async (servedir, listen) => {
// Start esbuild's local web server. Random port will be chosen by esbuild.
const { host, port } = await esbuild.serve({ servedir }, {});
// Create a second (proxy) server that will forward requests to esbuild.
const proxy = http.createServer((req, res) => {
// forwardRequest forwards an http request through to esbuid.
@mtgto
mtgto / serve.mjs
Last active August 25, 2023 03:10
Hot reload and do incremental builds with `esbuild`
/*
* Change from https://gist.github.com/unki2aut/4ac81c33be2e8f121e80a26eba1735d7
* - Use top level await (Node.js v14.8.0+)
* - To use top level await, you need to write a script as ES Modules
* - Set chokidar options to avoid duplicate building
* - Define NODE_ENV (For React)
* - Add API proxy setting by using proxy-middleware
*/
import chokidar from "chokidar";
import esbuild from "esbuild";
@puffnfresh
puffnfresh / FP.java
Last active April 27, 2021 01:03
Writing functions once, using Cubix. FP.java, FP.py and FP.js are generated by running Main.hs
public class FP
{
public static <A> A identity (A a)
{
return a;
}
public static <A, B> A constant (A a, B b)
{
return a;
}
@inamiy
inamiy / SwiftUI-emulating-React-Hooks.swift
Last active March 20, 2023 07:19
SwiftUI emulating React custom hooks (DynamicProperty composition) https://twitter.com/inamiy/status/1313343537132433409
import SwiftUI
struct ContentView: View {
@UseCounter
var counter: Int = 0
@UseCounterEffect(initialCount: 1, onUpdate: { count in
print("===> update: \(count)")
})
var counterEffect: Void
@hdgarrood
hdgarrood / Main.purs
Created May 20, 2020 15:41
Required and optional fields example
module Main where
import Prelude
import Effect (Effect)
import Data.Foldable (fold)
import TryPureScript (h1, h2, p, text, list, indent, link, render, code)
import Prim.Row (class Union, class Nub)
import Type.Row (type (+))
import Record as Record
@chriseidhof
chriseidhof / boilerplate.swift
Last active April 17, 2025 11:08
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@paf31
paf31 / DKT.hs
Last active April 30, 2021 06:59
Statically-typed values with dynamically-kinded types
{-# language FlexibleContexts #-}
{-# language TypeOperators #-}
module DKT where
import Control.Monad (guard)
import Control.Monad.Error.Class (throwError)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.State
import Control.Monad.Trans.Writer