Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / test.md
Last active Jul 27, 2021
Zig in 30 minutes
View test.md

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

View testman.js
/*
* Very simple test runner for nodejs:
*
* Supports:
*
* before, after, beforeAll, afterAll
* fixture object passed to each test, that before/after/beforeAll/afterAll can modify
* -[t]est option on command line to pick tests to run
* -[l]inear option on command to disable parallel
* built in fixture logger, captures log lines, adds line numbers/file names/timestamps
@Horusiath
Horusiath / Program.fs
Last active Nov 18, 2020
A simple Reliable Causal Broadcast implementation using F# and Akka.NET
View Program.fs
module Program =
type InMemoryDb(replica: ReplicaId) =
let snapshot = ref null
let mutable events : Map<uint64,obj> = Map.empty
interface Db with
member _.SaveSnapshot state = async { snapshot := (box state) }
member _.LoadSnapshot<'s>() = async {
match !snapshot with
View ExplicitViewStates.tsx
import React from "react";
type NoData = {
_type: "NO_DATA";
};
type Data<T> = {
_type: "DATA";
data: T;
};
@paf31
paf31 / DKT.hs
Last active Apr 30, 2021
Statically-typed values with dynamically-kinded types
View DKT.hs
{-# 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
@OliverJAsh
OliverJAsh / foo.md
Last active Jul 23, 2021
`Option` vs non-`Option`
View foo.md

Option vs non-Option

Option<T> non-Option (T | undefined)
accessing property userOption.map(user => user.age) userNullish?.age
calling a method userOption.map(user => user.fn()) userNullish?.fn()
providing fallback ageOption.getOrElse(0) ageNullish ?? 0
filter ageOption.filter(checkIsOddNumber) `ageNull
@eiriktsarpalis
eiriktsarpalis / Maybe.cs
Last active Apr 6, 2020
Encoding a Maybe monad in C# using Eff, https://github.com/nessos/Eff
View Maybe.cs
namespace Maybe
{
public struct Maybe<T>
{
public bool HasValue { get; }
public T Value { get; }
private Maybe(T value)
{
HasValue = true;
@tomhicks
tomhicks / plink-plonk.js
Last active Jul 21, 2021
Listen to your web pages
View plink-plonk.js
@paulrberg
paulrberg / ApolloReactManager.js
Last active Jan 21, 2020
Use Apollo Client with Hooks and web3-react
View ApolloReactManager.js
import React, { useMemo } from "react";
import { ApolloClient } from "apollo-client";
import { ApolloProvider } from "@apollo/react-hooks";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { useWeb3React } from "@web3-react/core";
const CHAIN_IDS_TO_NAMES = {
1: "mainnet",
@slorber
slorber / react-navigation-tree.jsx
Last active Jan 6, 2021
react-navigation-tree.jsx
View react-navigation-tree.jsx
const App = createAppContainer(
createStack({
LoggedSwitch: createSwitch({
// When user is authenticated
LoggedIn: createStack({
// The logged in root is generally a tab or drawer navigator
LoggedInRoot: createTabsOrDrawer({