This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSE | |
pragma solidity >=0.8.0 <0.9.0; | |
// NOT TESTED - USE AT YOUR OWN RISK | |
// Supports 32 byte word types. Could be easily extended to multiword types by | |
// passing in the size of the elements as well though | |
struct PushableArray { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @title The beginnings of Vector in Cairo | |
# @author 0xNonCents | |
# @notice Please let me know if this will save on gas compared to a @storage array | |
# MIT License | |
%builtins pedersen range_check | |
from starkware.cairo.common.alloc import alloc | |
from starkware.cairo.common.hash import hash2 | |
from starkware.cairo.common.cairo_builtins import HashBuiltin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*Submitted for verification at Etherscan.io on 2021-10-31 | |
*/ | |
// File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol | |
// OpenZeppelin Contracts v4.3.2 (utils/Strings.sol) | |
pragma solidity ^0.8.0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
If you're willing to write a little bit of boilerplate you can have type-safe GADT in Swift today. | |
This is accomplished using a wrapper struct with a phantom type parameter that wraps a private enum value. | |
Static factory methods on the struct wrap each case returning a value with the phantom type bound as necessary. | |
An extension is created for each phantom type binding providng a `switch` method that requires each case | |
with a matching type to be covered and uses `fatalError` for cases where values will never be created. | |
New members are added in extensions that bind the phantom type and make use of the `switch` method. | |
The example below is drawn from https://en.m.wikibooks.org/wiki/Haskell/GADT | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A type equality guarantee is capable of safely casting one value to a | |
/// different type. It can only be created when `S` and `T` are statically known | |
/// to be equal. | |
struct TypeEqualityGuarantee<S, T> { | |
private init() {} | |
/// Safely cast a value to the other type. | |
func cast(_ value: T) -> S { | |
return value as! S | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import os | |
import gym | |
import sys | |
import random | |
import itertools | |
from time import time | |
from copy import copy | |
from math import sqrt, log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (return v) (lambda (s ks kf) (ks v s))) | |
(define fail (lambda (s ks kf) (kf))) | |
; >>= | |
(define (bind a f) | |
(lambda (s ks kf) | |
(a s | |
(lambda (av s1) ((f av) s1 ks kf)) | |
kf))) |
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers Time Light Distance Approximate Light Distance | |
-------------------------- ---- -------------- -------------------------- | |
L1 cache reference 0.5 ns 0.15 m Diagonal across your smartphone | |
Branch mispredict 5 ns 1.5 m Height of Natalie Portman | |
L2 cache reference 7 ns 2.1 m Height of Shaq | |
Mutex lock/unlock 25 ns 7.5 m Height of a school flag pole | |
Main memory reference 100 ns 30 m Half a Manhattan city block (North/South) | |
Compress 1K bytes with Zippy 3,000 ns 900 m Width of Central Park | |
Send 1K bytes over 1 Gbps network 10,000 ns 3,000 m Width of Manhattan | |
Read 4K randomly from SSD* 150,000 ns 45,000 m NYC to Hempstead on Long Island |
NewerOlder