Skip to content

Instantly share code, notes, and snippets.

View Pet3ris's full-sized avatar
🎯
Focusing

Peteris Erins Pet3ris

🎯
Focusing
View GitHub Profile
@brockelmore
brockelmore / pushable_array.sol
Created January 19, 2022 23:20
Pushable array datatype for solidity
// 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 {
@0xNonCents
0xNonCents / .cairo
Last active February 18, 2022 08:19
Cairo vector
# @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
/**
*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;
@anandabits
anandabits / GADT.swift
Created November 26, 2017 04:23
Emulating GADT in Swift
/*
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
*/
@rxwei
rxwei / GADT.swift
Last active December 14, 2023 04:22
GADT in Swift
/// 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
}
@blole
blole / openai-gym-mcts.py
Last active June 8, 2023 19:24
Monte Carlo tree search agent for https://gym.openai.com
#!/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
@UnkindPartition
UnkindPartition / parsec.scm
Created October 17, 2012 07:58
Simple parser combinators in Scheme
(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)))
@domenic
domenic / promises.md
Last active October 13, 2024 22:51
You're Missing the Point of Promises

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.

You're Missing the Point of Promises

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.
@nahurst
nahurst / latency.txt
Created September 13, 2012 01:34 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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