Skip to content

Instantly share code, notes, and snippets.

Avatar

srdjan srdjan

View GitHub Profile
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 Nov 13, 2020
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 Nov 10, 2020
`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 Nov 21, 2020
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 Sep 9, 2020
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({
@lucj
lucj / k3s-multipass.sh
Created Dec 17, 2019
Setup a k3s kubernetes cluster using Multipass VMs
View k3s-multipass.sh
for node in node1 node2 node3;do
multipass launch -n $node
done
# Init cluster on node1
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
# Get node1's IP
IP=$(multipass info node1 | grep IPv4 | awk '{print $2}')
You can’t perform that action at this time.