Skip to content

Instantly share code, notes, and snippets.

View conectado's full-sized avatar

Gabi conectado

View GitHub Profile
@conectado
conectado / README.md
Last active July 7, 2025 16:20
Method call resolution in Rust for type parameters

The way method resolution works in Rust is specified in this section of the reference.

For a given type T where a method is being called, it follows these steps:

  1. Start with a candidate list containing only T (candidates := [T])
  2. Try to dereference (*) the last element of the list(last)
  3. If *last is valid, add it to the list (candidates := candidates : [last]) and go to the previous step. Else continue.
  4. AAttempt unsized coercion, meaning vaguely, converting a sized type to its unsized variant (e.g. [T; N] to [T])
  5. For each element t on candidates add &t and &mut t
  6. For each t in candidates:
@conectado
conectado / README.md
Last active July 2, 2025 20:53
Unexpected(for me) behavior in drop order

I was experimenting with the lifetime constraints for tokio channels, I wanted to understand how it enforces sane lifetimes for the type of the value sended.

So, my initial program was:

#[tokio::main]
async fn main() {
    let (tx, mut rx) = tokio::sync::mpsc::channel(100);
 let x = 1;
use anyhow::Context;
use bytecodec::{DecodeExt, EncodeExt as _};
use futures::{Future, FutureExt};
use std::{
collections::VecDeque,
net::{SocketAddr, ToSocketAddrs},
pin::Pin,
task::{ready, Poll, Waker},
time::{Duration, Instant},
};
To efficiently calculate a ^ b I found this algorithm https://en.wikipedia.org/wiki/Exponentiation_by_squaring
Luckily (for me) I don't think the reasoning behind the algorithm is very well explained so I had the chance to think it over and I think I came up with a good way to explain it.
The most important concept behind the algorithm is decomposing "b" in a sequence of multiplication by 2:
So, given the binary representation of a number we recognize 2 operations left-shift and "put a 1 in the lsb". For any binary representation the first can be done by multiplying by 2, the second can be done by summing 1.
With this operations, we proceed like in a calculator, we start with 1, this being your msb, then you shift it to the left and "enter 1" if there is one in the second msb or shift again, then you do it again for the third digit and so on until you get all the digits.
@conectado
conectado / pallet.rs
Created December 3, 2020 19:27
Result of benchmarking the same pallets with 2 different instances
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
pub struct WeightInfo;
impl pallet::WeightInfo for WeightInfo {
fn on_initialize_first(i: u32, ) -> Weight {

Keybase proof

I hereby claim:

  • I am conectado on github.
  • I am conectado (https://keybase.io/conectado) on keybase.
  • I have a public key ASC5R3Z3vZ2IYXcMA4Zot4wq2n2_yxNSh-JjBsb8Gc-6dQo

To claim this, I am signing this object:

body {
background-color: rgb(29,30,40);
}
.item-up {
background-color: rgb(189,215,238);
}
.item-down {
background-color: rgb(248,203,173);
<body>
<div class="grid-wrapper">
<div class="sub-grid-wrapper">
<div class="item-up">
</div>
<div class="item-up">
</div>
</div>
<div class="sub-grid-wrapper">
<div class="item-up">
@conectado
conectado / grid-responsiveness-example.markdown
Created June 30, 2018 04:40
Grid responsiveness example
body {
background-color: rgb(29,30,40);
}
.item {
background-color: #3f4d72;
color: #7c5c48;
font-size: xx-large;
text-align: center;
font-weight: bold;