Skip to content

Instantly share code, notes, and snippets.

View mfornet's full-sized avatar
🌎
on earth

Marcelo Fornet mfornet

🌎
on earth
View GitHub Profile
@mfornet
mfornet / bloom_filters.py
Last active February 19, 2019 08:58
What if bloom filters use counters instead of bitmasks?
"""
Exploring bloom filters using counters instead of bit masks.
"""
from random import sample, seed, randint
from hashlib import md5
from functools import partial
# TODO: Use more random & faster hash functions
def hash_md5(A, seed, mod):
l = list(md5(str(A + (seed << 10)).encode()).digest())
tot_val = 10000
tot_per_shard = 200
bad_ratio = .20
rounds = 5000
compromised_ratio = 1. / 3
assert tot_val % tot_per_shard == 0
bad = int(bad_ratio * tot_val)
good = tot_val - bad
We can't make this file beautiful and searchable because it's too large.
,id,date,user,problem,judgement,time,memory,size,lang,contest
0,375916,63,2017CNC045,A,Accepted,207.0,1000.0,0,C++11,1560
1,375917,91,2017CNC022,A,Accepted,144.0,1000.0,0,C++11,1560
2,375919,109,2017cnc2033,A,Accepted,138.0,1000.0,0,C++,1560
3,375920,111,2017CNC024,A,Accepted,194.0,1000.0,0,C++11,1560
4,375922,120,2017cnc2015,A,Accepted,134.0,1000.0,0,C++,1560
5,375923,126,2017CNC047,A,Accepted,142.0,1000.0,0,C++11,1560
6,375924,129,2017CNC100,A,Accepted,140.0,1000.0,0,C++11,1560
7,375925,132,2017CNC069,A,Accepted,144.0,1000.0,0,C++11,1560
8,375926,134,2017CNC021,A,Accepted,187.0,1000.0,0,C++,1560
@mfornet
mfornet / network-exploration.cpp
Last active April 16, 2020 05:01
Explore network growing in a synchronous setting
#include <vector>
#include <iostream>
#include <map>
#include <random>
#include <numeric>
using namespace std;
mt19937 rng(0);
@mfornet
mfornet / seats.py
Last active April 24, 2020 20:45
Seats required for n validators
def tPoS(tokens, seats):
lo, hi = 0, 1
def get_seats(value):
total = 0
for tok in tokens:
total += tok // value
return total
while get_seats(hi) >= seats:
@mfornet
mfornet / fork.rs
Created April 29, 2020 23:20
Forking Contract
use borsh::{BorshDeserialize, BorshSerialize};
use near_bindgen::{env, ext_contract, near_bindgen};
use serde::{Deserialize, Serialize};
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[ext_contract(ext)]
pub trait ExtCrossContract {
fn fork(&mut self);
@mfornet
mfornet / launch.json
Last active March 7, 2021 10:02
Debug configuration files for https://github.com/mfornet/acmx
{
"version": "0.2.0",
"configurations": [{
"name": "Launch with lldb",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/attic/sol",
"args": ["${fileDirname}"],
"cwd": "${workspaceFolder}",
"stdio": ["${fileDirname}/testcases/0.in"],
@mfornet
mfornet / remove_high_frequency.py
Created July 26, 2020 02:45
Discover the animal
# %%%
import PIL.Image
import numpy as np
import matplotlib.pyplot as plt
# %%
im = PIL.Image.open("panda.jpeg")
arr = np.array(im).mean(2)
"""
https://twitter.com/bitshiftmask/status/1323809212875608066?s=20
Let P(i, j) be the probability that if there are `i` devices, then after one
round `j` devices selected a unique number, so they are out. The expected
value of the number of rounds required so that each device selected a unique number is:
E(n) = p(n, n) * E(0) + p(n, n - 1) * E(1) + ... + p(n, 0) * E(n)
E(n) * (1 - p(n, 0)) = p(n, n) * E(0) + p(n, n - 1) * E(1) + ...
@mfornet
mfornet / near-borsh-io.md
Last active November 18, 2021 04:30
Borsh I/O in NEAR Smart Contracts

Borsh I/O in NEAR Smart Contracts

Manual encoding single parameter

pub fn set_status_borsh(&mut self, #[serializer(borsh)] message: Vec<u8>) {}

To call this function you need to pass arguments borsh serialized, and those bytes encoded as base64