Skip to content

Instantly share code, notes, and snippets.

@fiveoutofnine
fiveoutofnine / 1_example-glyphs.txt
Last active January 13, 2024 03:34
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 April 5, 2024 22:19
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 May 4, 2024 16:40
Great and less great SSDs for Ethereum nodes

Overview

Syncing an Ethereum node is largely reliant on IOPS, I/O Per Second. Budget SSDs will struggle to an extent, and some won't be able to sync at all.

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

For size, 4TB comes recommended as of mid 2024. The smaller 2TB drive should last an Ethereum full node until early 2025 or thereabouts, with crystal ball uncertainty.

High-level, QLC and DRAMless are far slower than "mainstream" SSDs. QLC has lower endurance as well. Any savings will be gone when the drive fails early and needs to be replaced.

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 April 21, 2024 01:51
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 December 15, 2020 04:20
Awesome postgres