Skip to content

Instantly share code, notes, and snippets.

View mpapierski's full-sized avatar

Michał Papierski mpapierski

View GitHub Profile
(module
(memory $memory 1)
(func $fib_recursive (export "fibonacci_rec") (param $N i64) (result i64)
(if
(i64.le_s (local.get $N) (i64.const 1))
(then (return (local.get $N)))
)
(return
(i64.add
@mpapierski
mpapierski / compare.py
Created September 8, 2023 17:22
compare execution results
import csv
import sys
# These tests are failing when gas costs are radically changed.
SKIPPED = [
(
"casper_engine_tests::test::contract_api::get_call_stack::payment",
"payment_bytes_to_stored_session_to_stored_contract_",
),
use num::traits::{Num, NumOps};
use std::cmp::Ordering;
fn binary_search<T, F>(lower_bound: T, upper_bound: T, f: F) -> Result<T, T>
where
T: Copy + PartialOrd + Num + NumOps,
F: Fn(T) -> Ordering,
{
let mut size = upper_bound;
let mut left = lower_bound;
@mpapierski
mpapierski / ceil_ln_lookup_table.rs
Last active March 8, 2023 16:44
Compute a lookup table for ceil(ln(x)) for [0..u64::MAX]
use num::traits::{Num, NumOps};
use std::cmp::Ordering;
fn binary_search<T, F>(lower_bound: T, upper_bound: T, f: F) -> Result<T, T>
where
T: Copy + PartialOrd + Num + NumOps,
F: Fn(T) -> Ordering,
{
let mut size = upper_bound;
let mut left = lower_bound;
@mpapierski
mpapierski / rip_dvd.sh
Created August 21, 2019 10:28
Semi-automatic DVD backup tool
#!/bin/bash
set -e
DEV="/dev/dvd"
ISO_OUTPUT="/mnt/vault/Movies/DVD Backup/"
echo -n "Trying to read DVD label... "
DVD_NAME="$(blkid -o value -s LABEL $DEV)"
@mpapierski
mpapierski / malicious_contract.rs
Last active July 9, 2019 11:25
malicious_contract
#![no_std]
#![feature(alloc, cell_update, allocator_api)]
#[macro_use]
extern crate alloc;
extern crate core;
extern crate cl_std;
use cl_std::contract_api;
FROM python:3.7.2
# Build the code
WORKDIR /code
COPY . /code
# Compile source code into 'legacy' .pyc
RUN python -m compileall -b . && \
find . -iname "*.py" -delete
#include <iostream>
#include "json.hpp"
#include "autoprop.hpp"
using namespace mpapierski;
using json = nlohmann::json;
class Person : public AutoProp<Person> {
public:
AUTOPROP_BEGIN(Person);
@contextmanager
def convert_to_pdf(filename):
"""Creates a PDF document based on input filename.
Returns a path to PDF file
"""
client = docker.from_env()
source = os.path.join('/tmp/{}'.format(os.path.basename(filename)))
#!/usr/bin/env python3
from collections.abc import Iterable
data = [1,2,[3,4,[5,6,[7,8,[9,10,[[[11],12],[13,14,15]]]]]]]
def flatten(data):
for value in data:
if isinstance(value, (Iterable,)):
# Call recursively to yield nested values from
yield from flatten(value)