Skip to content

Instantly share code, notes, and snippets.

Doug Beardsley mightybyte

View GitHub Profile
@mightybyte
mightybyte / Counters.hs
Last active Jun 27, 2020
Reflex/React Comparison (look at the revision history)
View Counters.hs
{-# LANGUAGE OverloadedStrings #-}
import Reflex.Dom
counter = el "div" $ do
click <- button "Click"
clicks <- foldDyn (\() n -> n + 1) 0 click
el "p" $ display clicks
return clicks
main = mainWidget $ do
@mightybyte
mightybyte / default.nix
Created Feb 28, 2020
Generic Haskell Nix Template
View default.nix
{ compiler ? "ghc844"
, rev ? "497e6f1705107a7d60e400e3b6dd6df5ca8bcdba"
, sha256 ? "1gwdxpx5ix3k6j5q3704xchw4cfzmmr2sd6gsqmsln9yrmjzg9p4"
, pkgs ?
import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256; }) {
config.allowBroken = false;
config.allowUnfree = true;
}
@mightybyte
mightybyte / rotate-and-drain.yaml
Last active Jan 29, 2020
Pact command template for a safe rotate-and-drain operation
View rotate-and-drain.yaml
code: |-
(use coin)
(let* ((acct:string "rotest")
(bal:decimal (coin.get-balance acct))
)
(coin.rotate acct (read-keyset "ks"))
(coin.transfer acct "croesus" bal)
)
data:
ks:
@mightybyte
mightybyte / safe-transfer-example.yaml
Created Jan 12, 2020
Example template for safe transactions on Kadena
View safe-transfer-example.yaml
code: |-
(coin.transfer-create "alice" "bob" (read-keyset "ks") 100.1)
(coin.transfer "bob" "alice" 0.1)
data:
ks:
keys: [0ba113d8a84c307ebc2ace5090f117d921c43d9d3011e9cb9e030cb8ea5502eb]
pred: "keys-all"
publicMeta:
chainId: "0"
sender: alice
@mightybyte
mightybyte / hashing.pact
Created Sep 14, 2019
Playing around with hashing
View hashing.pact
(module hash MODULE_ADMIN
"A smart contract to greet the world."
(defcap MODULE_ADMIN () true)
(defun revcat (a b)
(+ b a)
)
(defun phash:string (str:string)
(let* ((h (hash str))
@mightybyte
mightybyte / default.nix
Created Jun 29, 2019
A default.nix template for nixifying Haskell projects
View default.nix
{ compiler ? "ghc844"
, rev ? "497e6f1705107a7d60e400e3b6dd6df5ca8bcdba"
, sha256 ? "1gwdxpx5ix3k6j5q3704xchw4cfzmmr2sd6gsqmsln9yrmjzg9p4"
, pkgs ?
import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256; }) {
config.allowBroken = false;
config.allowUnfree = true;
}
@mightybyte
mightybyte / hello-fv.pact
Created Jun 5, 2019
Hello world with formal verification
View hello-fv.pact
;;
;; "Hello, world!" smart contract/module
;;
;; Define the module.
(module hello-world MODULE_ADMIN
"A smart contract to greet the world."
; no-op module admin for example purposes.
; in a real contract this could enforce a keyset, or
@mightybyte
mightybyte / type-error.pact
Created Jun 3, 2019
Type error mentioned on Discord
View type-error.pact
; Simplified example of a token implementation.
; When I run `(typecheck "my-token")` I get the error:
; > Typecheck my-token: Unable to resolve all types
(module my-token GOVERNANCE
(defschema accounts-schema
balance:integer
guard:guard
)
@mightybyte
mightybyte / verification.pact
Created Apr 15, 2019
Pact formal verification example
View verification.pact
;;
;; A little example showing off the merits of formal
;; verification and why it pays off.
;;
;; Keysets cannot be created in code, thus we read them in
;; from the load message data.
(define-keyset 'admin-keyset (read-keyset "admin-keyset"))
;; Define the module.
@mightybyte
mightybyte / pact-web-share.pact
Created Mar 19, 2019
Pact shared with pact-web.
View pact-web-share.pact
;;
;; A little example showing off the merits of formal
;; verification and why it pays off.
;;
;;---------------------------------
;;
;; Create an 'admin-keyset' and add some key, for loading this contract!
;;
;; Make sure the message is signed with this added key as well.
You can’t perform that action at this time.