Skip to content

Instantly share code, notes, and snippets.

@ralexstokes
ralexstokes / sketch.clj
Last active March 11, 2020 21:52
Sketch of Clojure-like smart contract language
(require
[types]
[precompiles]
[registry]
[tools])
(defcontract BLSSignatureVerifier
(defn ^:public verify [message public-key signature)
(let [message-on-curve (precompiles/hash-to-curve message)]
(=
import colored
import random
import trio
host = "127.0.0.1"
port = 8080
def _mk_msg(_id):
return f"query from {_id}"
@ralexstokes
ralexstokes / asyncio_echo.py
Created June 20, 2019 18:34
asyncio echo server
import random
import asyncio
import colored
host = "127.0.0.1"
port = 8080
@ralexstokes
ralexstokes / basic_trio.py
Created June 20, 2019 18:33
basic trio example
import trio
async def child1(nursery):
print("from 1")
# will cancel the nursery
# raise Exception("there")
await trio.sleep(1)
@ralexstokes
ralexstokes / async.py
Created June 20, 2019 18:31
basic python async
import asyncio
async def count(delay):
# this will block everything :(
# time.sleep(2)
# will explode the other stuff
# raise Exception("hi")
@ralexstokes
ralexstokes / gist:37f6c3779038705c7795962fd0147c1d
Created March 31, 2019 03:26
change-sequence-of-epoch-processing.patch
From c47d7ce48eaadf0faf45ec53fc0e8adf0017db7b Mon Sep 17 00:00:00 2001
From: Alex Stokes <[email protected]>
Date: Wed, 20 Mar 2019 16:50:03 -0700
Subject: [PATCH] Reorder the per-epoch transition to occur at the start of the
state transition
---
.../beacon/state_machines/forks/serenity/state_transitions.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@ralexstokes
ralexstokes / gist:206d536fbfd7814ffbb748fcb6a8ff4d
Created February 17, 2019 22:07
some notes on `ethereum/go-ethereum` repo organization (12ca3b172)
here are the top-level directories in the geth repo at the above commmit.
(skipping some things relating to CI or repo management)
accounts - an account manager (e.g. perhaps wraps key manager and (tx) signer)
build - config/tools for building parts of this repo
cmd - the various binary commands exposed in the repo
common - series of utilities used across the codebase
consensus - defines various consensus algos, like PoW or PoA
console - bind console to geth node for CLI interaction
containers - dockerfiles
@ralexstokes
ralexstokes / toggle-grayscale.applescript
Last active February 8, 2019 17:05
Toggles grayscale mode on the display in macOS Mojave
on run {input, parameters}
tell application "System Preferences"
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.1
click checkbox "Use grayscale" of group 0 of window "Accessibility"
end tell
tell application "System Preferences" to if it is running then quit
return
@ralexstokes
ralexstokes / merkle.py
Created January 4, 2019 15:40
A sketch of the Merkleization logic used for the Eth1.0 deposit contract and the verification logic used in the Eth2.0 beacon chain.
import hashlib
def version_check():
import sys
assert sys.version_info.major >= 3
assert sys.version_info.minor >= 6
assert sys.version_info.micro >= 5
version_check() # using hashlib features from 3.6.5
@ralexstokes
ralexstokes / msg_hash.py
Created June 9, 2018 18:13
Port `msg_hash.se.py` to Python code.
from web3 import Web3
import rlp
from eth_tester import (
EthereumTester,
PyEVMBackend
)
from web3.providers.eth_tester import (
EthereumTesterProvider,
)