Skip to content

Instantly share code, notes, and snippets.

Avatar

William Chargin wchargin

View GitHub Profile
@wchargin
wchargin / README
Last active Oct 21, 2021
combo: simple parser combinator library for JavaScript
View README
This is `combo.js` as of SourceCred commit fb669962a030, modified to convert
Flow type annotations to comment syntax and to group ES6 exports to the end of
the file (for easier conversion to Node-style `module.exports`). The code of
`combo.js` up to this point in history was written entirely by me. Its tests
still pass.
@wchargin
wchargin / xmonad.hs
Last active Oct 18, 2021
xmonad 2021-10-18
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
@wchargin
wchargin / rarity.sql
Last active Sep 28, 2021
token rarity analysis
View rarity.sql
WITH project_id(project_id) AS (VALUES(163)),
token_bounds(min_id, max_id) AS (
SELECT
(1000000 * project_id) AS min_id,
(1000000 * (project_id + 1)) AS max_id
FROM project_id
),
project_tokens(token_id) AS (
SELECT token_id FROM tokens CROSS JOIN token_bounds
WHERE min_id <= token_id AND token_id < max_id
@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 };
}