Skip to content

Instantly share code, notes, and snippets.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/math/Math.sol";
struct Accumulator {
uint concrete;
uint virtualRate;
uint virtualSince;
}
@frangio
frangio / custom-store.ts
Created June 4, 2022 00:50
A helper to build custom Svelte stores
import type { Subscriber } from 'svelte/store';
export function store<T>(start: () => T, stop?: () => void) {
const subscribers = new Set<Subscriber<T>>();
let value: T;
function notify() {
for (const fn of subscribers) {
fn(value);
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
contract MyTokenV1 is Initializable, ERC20Upgradeable {
function initialize() initializer public {
__ERC20_init("MyToken", "MTK");

0x09cd18d17c48a9e5f7919dbb8267cbc0f9c75e95a3c94f9c4f910edaf90c2db6

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
// Unlike the string type, ShortString is a value type that can be made immutable.
// It supports strings of at most 32 bytes and assumes they don't contain null bytes.
type ShortString is bytes32;
error StringTooLong(string s);
type GraphGenerator<T> = Iterable<[T, T?]>;
interface Edges<T> {
pred: T[];
succ: T[];
}
export function toposort<T, G extends GraphGenerator<T>>(graph: G): T[] {
const sorted = new Set<T>();
const nodes = new Map<T, Edges<T>>();
$ node -r time-require -r solc-0.6.8 -e ''
Start time: (2020-07-02 16:09:07 UTC) [treshold=1%]
# module time %
1 ./soljson.js (node_modules/solc-0.6.8/soljson.js) 2.2s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99%
2 solc-0.6.8 (node_modules/solc-0.6.8/index.js) 2.3s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100%
Total require(): 26
Total time: 2.3s
$ node -r time-require -r solc-0.6.9 -e ''
@frangio
frangio / async-router.js
Last active April 15, 2020 03:32
A way to use async/await in Express routes
const express = require('express');
const methods = require('methods');
function AsyncRouter(options) {
const router = express.Router(options);
Object.setPrototypeOf(router, AsyncRouter.prototype);
return router;
}
Object.setPrototypeOf(AsyncRouter.prototype, express.Router);
[Unit]
Description=Lock all consoles
Documentation=man:physlock(1)
Before=sleep.target
OnFailure=hibernate.target
[Service]
Type=forking
ExecStart=physlock -d
@frangio
frangio / rs
Last active February 8, 2024 19:56
ripsed: use ripgrep as a sed replacement. requires sponge from moreutils
#!/usr/bin/env bash
set -o errexit -o pipefail
if [ "$#" -eq 0 ]
then
echo "usage: rs PATTERN REPLACEMENT [PATH...]" > /dev/stderr
exit 1
fi