Skip to content

Instantly share code, notes, and snippets.

Avatar

William Chargin wchargin

View GitHub Profile
@wchargin
wchargin / logWords.sol
Created Sep 17, 2021
log a long `bytes memory _message` one word at a time
View logWords.sol
for (uint256 _i = 0; _i < _message.length; _i += 32) {
bytes memory _slice = _message;
uint256 _len = _message.length - _i;
if (_len > 32) _len = 32;
uint256 _oldValue;
assembly {
_oldValue := mload(_slice)
_slice := add(_slice, _i)
mstore(_slice, _len)
}
@wchargin
wchargin / IntrinsicRectangles.sol
Last active Jul 27, 2021
SVG token with ownership and cosmetics embedded in token ID (100% untested)
View IntrinsicRectangles.sol
// SPDX-License-Identifier: GPL-v2-only
pragma solidity ^0.8.0;
// 160 bits for address; 96 bits for payload, split into 64 bits of
// cosmetics and 32 bits of nonce.
struct TokenId {
address owner;
Cosmetics cosmetics;
uint32 nonce;
}
@wchargin
wchargin / xmonad.hs
Last active Jul 13, 2021
xmonad.hs, 2021-07-12: now with `interrogateVolume`
View xmonad.hs
import XMonad
import XMonad.Config.Gnome (gnomeConfig)
import XMonad.Hooks.ManageHelpers (doCenterFloat)
import XMonad.Hooks.ManageDocks (manageDocks, avoidStruts)
import XMonad.Layout.NoBorders (noBorders)
import qualified XMonad.Layout.Dwindle as Dwindle
import XMonad.Actions.CycleWS (nextWS, prevWS, shiftToNext, shiftToPrev)
import XMonad.Util.EZConfig (additionalKeys)
import qualified XMonad.StackSet as W
View pebbles.py
def multiset(components):
return tuple(sorted(components))
START = multiset([3, 5, 7])
def next_states(state):
result = set()
for i in range(len(state)):
if state[i] == 0:
continue
View pebbles.py
def multiset(components):
return tuple(sorted(components))
START = multiset([3, 5, 7])
def next_states(state):
result = set()
for i in range(len(state)):
if state[i] == 0:
continue
View algobots_set_cover.py
import json
data = json.load(open("../allData.json"))
traits_by_token = {item["tokenID"]: sorted(set(item["traits"])) for item in data}
assert len(data) == len(traits_by_token), "Duplicate tokens"
tokens = sorted(traits_by_token)
token_indices = {token: i for (i, token) in enumerate(tokens)}
traits = sorted({t for item in data for t in item["traits"]})
trait_indices = {trait: i for (i, trait) in enumerate(traits)}
@wchargin
wchargin / lc.js
Created Apr 9, 2021
two simple lambda calculi
View lc.js
/*::
type Expr =
| { type: "VAR", name: string }
| { type: "LAM", param: string, body: Expr }
| { type: "APP", fn: Expr, arg: Expr }
*/
function vr(name) {
return { type: "VAR", name };
}
@wchargin
wchargin / test.py
Created Mar 30, 2021
calling `cm().__enter__()` on a `@contextlib.contextmanager`
View test.py
import contextlib
@contextlib.contextmanager
def cm():
print("fst")
yield
print("snd")
View hmm.py
def foo(**kwargs):
return kwargs
print(foo(ₓ=1))
print(foo(**{"ₓ": 1}))
@wchargin
wchargin / Cargo.toml
Last active Feb 28, 2021
crosswalk: Markdown-friendly cross-references robust to referent renames
View Cargo.toml
[dependencies]
pulldown-cmark = "0.8.0"