Skip to content

Instantly share code, notes, and snippets.

View Th0rgal's full-sized avatar
🕶️

Thomas Marchand Th0rgal

🕶️
View GitHub Profile
@Th0rgal
Th0rgal / td1.ml
Last active September 19, 2021 16:32
TD 1 Ocaml
let rec h x y =
let rec h2 x y acc =
if x = y then acc
else if x < y then h2 (x - 1) (y - 2) (acc + x + y)
else h2 (x - 1) y (acc * y)
in
h2 x y 1
let f1 =
let rec f1rec x =
aiohttp @ file:///private/tmp/nix-build-python3.8-aiohttp-3.8.1.drv-0/aiohttp-3.8.1/dist/aiohttp-3.8.1-cp38-cp38-macosx_11_0_arm64.whl
aiosignal @ file:///private/tmp/nix-build-python3.8-aiosignal-1.2.0.drv-0/source/dist/aiosignal-1.2.0-py3-none-any.whl
async-timeout @ file:///private/tmp/nix-build-python3.8-async-timeout-4.0.1.drv-0/async-timeout-4.0.1/dist/async_timeout-4.0.1-py3-none-any.whl
attrs @ file:///private/tmp/nix-build-python3.8-attrs-21.2.0.drv-0/attrs-21.2.0/dist/attrs-21.2.0-py2.py3-none-any.whl
bitarray @ file:///private/tmp/nix-build-python3.8-bitarray-1.2.2.drv-0/bitarray-1.2.2/dist/bitarray-1.2.2-cp38-cp38-macosx_11_0_arm64.whl
certifi @ file:///private/tmp/nix-build-python3.8-certifi-2021.10.8.drv-0/source/dist/certifi-2021.10.8-py2.py3-none-any.whl
charset-normalizer @ file:///private/tmp/nix-build-python3.8-charset-normalizer-2.0.8.drv-0/source/dist/charset_normalizer-2.0.8-py3-none-any.whl
Cython @ file:///private/tmp/nix-build-python3.8-cython-0.29.24.drv-0/Cython-0.29.24/dist/Cython-
@Th0rgal
Th0rgal / shell.nix
Last active September 2, 2022 07:08
What binaries to install?
with import <nixpkgs> { };
let pythonPackages = python39Packages;
in pkgs.mkShell rec {
name = "impurePythonEnv";
venvDir = "./env";
buildInputs = [
# A Python interpreter including the 'venv' module is required to bootstrap
# the environment.
pythonPackages.python
func main():
[ap] = 1000; ap++
[ap] = 2000; ap++
[ap] = [ap - 2] + [ap - 1]; ap++
ret
end
@Th0rgal
Th0rgal / louis.cairo
Last active April 30, 2022 16:47
Demonstration of array usage in cairo
%builtins output
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.serialize import serialize_word
func print_array{output_ptr : felt*}(res_len : felt, res : felt*):
if res_len == 0:
return ()
end
@Th0rgal
Th0rgal / cairocheat.md
Last active May 26, 2022 17:40
Personal CheatSheet for programming on StarkNet

Checking transaction status

https://alpha4.starknet.io/feeder_gateway/get_transaction_receipt?transactionHash=

Using hints

Go to starkware/starknet/testing/starknet.py In the definition of deploy, you will see there the invocation of compile_starknet_files. Add the argument disable_hints_validation=True

@Th0rgal
Th0rgal / fold_left.cairo
Last active June 6, 2022 14:13
Trying functional programming in cairo. Thanks https://github.com/onlydustxyz/cairo-streams for the inspiration
%builtins output range_check
from starkware.cairo.common.registers import get_label_location
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.alloc import alloc
func main{output_ptr : felt*, range_check_ptr}():
alloc_locals
let (arr : felt*) = alloc()
%builtins output
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.alloc import alloc
func print_words{output_ptr : felt*}(res_len : felt, res : felt*):
if res_len == 0:
return ()
end
func reverse{syscall_ptr : felt*, range_check_ptr, pedersen_ptr : HashBuiltin*}(
arr_len : felt, arr : felt*
) -> (rev_arr_len : felt, rev_arr : felt*):
# if our array is empty (i.e. we reached the end of our recursion)
if arr_len == 0:
let (rev_arr) = alloc()
return (0, rev_arr)
end
@storage_var
func my_var(id : felt) -> (content : felt):
end
@view
func test_my_var{syscall_ptr : felt*, range_check_ptr, pedersen_ptr : HashBuiltin*}():
alloc_locals
my_var.write(7, 'hello')
let (local keccak_ptr_start : felt*) = alloc()
let keccak_ptr = keccak_ptr_start