Skip to content

Instantly share code, notes, and snippets.

@fiveoutofnine
fiveoutofnine / 1_example-glyphs.txt
Last active June 17, 2024 20:43
Quick snippets/tutorial on how to condense a font by selecting a subset of characters. First, create a `.txt` file with the characters (as unicode chars) you want included.
U+0039
U+003A
U+002F
U+0023
U+0050
U+0075
U+007A
U+006C
U+0065
U+0041
@tdelabro
tdelabro / no_std-guide.md
Last active February 16, 2025 11:50
How to easely port a crate to `no_std`?

What is Rust's standard library?

One of the Rust programming language promises is "zero-cost abstraction". Therefore the language itself is pretty conservative about what it incorporates. Types that are basics in other languages, such as string, or features, such as async, cannot be part of the language itself because they are costly abstractions. The user may not need them at all, or he may prefer other alternative implementations. To make those types and functions available nonetheless, they are available as part of the Rust standard library, known as std. Part of this library, known as the prelude is imported by default in each .rs file so you don't have to repeat yourself too much.

Why would you want a no_std version of your crate?

Most of the time having this standard library available is not a problem because you run your code on a pretty standard environment: your own computer or a Linux server somewhere in the cloud. However, somet

@rlkelly
rlkelly / object.cairo
Created August 30, 2022 05:27
The Hierarchy of an Object + Class
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.invoke import invoke
from starkware.cairo.common.registers import get_ap, get_label_location
struct Class:
member _ : felt*
member name : felt
member super : Class*
member size : felt
member ctor : codeoffset # constructor
@yorickdowne
yorickdowne / HallOfBlame.md
Last active April 26, 2025 13:16
Great and less great SSDs for Ethereum nodes

Overview

Syncing an Ethereum node is largely reliant on latency and IOPS, I/O Per Second, of the storage. Budget SSDs will struggle to an extent, and some won't be able to sync at all. IOPS can roughly be used as proxy of / predictor for latency. Measuring latency directly is arguably better.

This document aims to snapshot some known good and known bad models.

The drive lists are ordered by interface and then by capacity and alphabetically by vendor name, not by preference. The lists are not exhaustive at all. @mwpastore linked a filterable spreadsheet in comments that has a far greater variety of drives and their characteristics. Filter it by DRAM yes, NAND Type TLC, Form Factor M.2, and desired capacity.

For size, 4TB is a very conservative choice. The smaller 2TB drive should last an Ethereum full node until at least sometime 2026, with the [pre-merge history expiry](https://hackmd.io/@hBXHLw_9Qq2va4pRt

func _search_index_array{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
array_len : felt,
array : felt*,
index: felt,
index_match: felt,
match_callback: felt) -> (
index_match: felt):
alloc_locals
@fiveoutofnine
fiveoutofnine / HeapSort.sol
Created March 16, 2022 04:00
Solidity implementation of max-heapsort
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HeapSort {
function sort(uint256[] calldata _input) external pure returns (uint256[] memory) {
_buildMaxHeap(_input);
uint256 length = _input.length;
unchecked {
for (uint256 i = length - 1; i > 0; --i) {
@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
@agolajko
agolajko / suez_fp_trick.md
Last active August 8, 2022 22:26
Quick trick for better looping in Cairo

Returning fp for calling functions in Cairo loops

Getting loops to work in Starknet's Cairo can be complicated. Currently you need to fiddle around a lot with ap, fp and pc even for mundane computations. Further, when calling a function within a loop tempvar will be dereferenced causing the loop to fail. For example the following code will not run:

tempvar iterator=10
tempvar sum=0

loop_start:
 let (local a, local b)=div (10, 5)
@hrkrshnn
hrkrshnn / generic.org
Last active March 19, 2025 23:52
Some generic writeup about common gas optimizations, etc.

Upgrade to at least 0.8.4

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions 0.8.* over <0.8.0 are:

  • Safemath by default from 0.8.0 (can be more gas efficient than some library based safemath).
  • Low level inliner from 0.8.2, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For
@benschwarz
benschwarz / pg.md
Last active October 16, 2024 23:15
Awesome postgres