Skip to content

Instantly share code, notes, and snippets.

View danielhenrymantilla's full-sized avatar
🦀

Daniel Henry-Mantilla danielhenrymantilla

🦀
View GitHub Profile
@danielhenrymantilla
danielhenrymantilla / lib.rs
Created July 7, 2018 13:21
Rust: &self sugar vs other &identifier bindings
/* The following lib tests illustrate a lack of consistency in rust:
* the &identifier binding leads to 2 different behaviors based on whether
* - the identifier is the special 'self' first argument of a method,
* - or a simple variable / argument (called slf in the following tests)
*/
#![allow(dead_code, unused_variables, unused_parens)]
/* compiler ensures that check_ref::<T>(x) can only be called iff x: &T */
fn check_ref<T> (_: &T) {}
@danielhenrymantilla
danielhenrymantilla / hexdump_tool_by_yandros.c
Created July 30, 2018 12:41
Hexdump tool to "copy-paste" binaries into a shell. Useful for root-me.org VM challenges.
/* Hexdump tool to "copy-paste" binaries into a shell.
* Useful for root-me.org VM challenges.
* Compile with:
* $ cc -std=c99 -o slice slice.c
*
* By Yandros (https://www.root-me.org/Yandros)
*/
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
@danielhenrymantilla
danielhenrymantilla / death_letter.tex
Created October 12, 2018 14:27 — forked from aeris/death_letter.tex
Lettre de la mort GDPR
\documentclass[10pt]{lettre}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{eurosym}
\usepackage{enumitem}
\usepackage[frenchb]{babel}
\begin{document}
\begin{letter}{
@danielhenrymantilla
danielhenrymantilla / latest-stable-rustc.md
Created October 5, 2020 19:37 — forked from alexheretic/latest-stable-rustc.md
Latest stable rust as a MSRV policy

Latest stable rust as a minimum

Minimum supported rust version (MSRV) policy that indicates the most recent stable rust release is the minimum whenever a new crate version is published. It is not required to bump a crate's major version after a new stable compiler is released.

For example crate_foo version 0.1.2 published on 2018-12-28 has MSRV 1.31.1 as this compiler was published on 2018-12-20.

The advantages of this approach is simplicity in maintaining a crate's code.

Workarounds for older compiler versions

If you are unable to update your compiler, you may be unable to update crate dependencies following this policy.

@danielhenrymantilla
danielhenrymantilla / SimpleHTTPServerWithUpload.py
Created July 15, 2021 18:07 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@danielhenrymantilla
danielhenrymantilla / parse_quote_dbg.rs
Created September 17, 2021 15:14 — forked from jmg-duarte/parse_quote_dbg.rs
Yandros parse_quote! debug
// Credits: Yandros#4299
macro_rules! parse_quote {(
$($code:tt)*
) => ({
eprintln!("[{}:{}:{}] parse_quote! {{ {} }}", file!(), line!(), column!(), quote!( $($code)* ));
::syn::parse_quote!( $($code)* )
})}
macro_rules! parse_quote {(

Summary

Panics which happen inside a Drop impl currently unwind as long as the drop was not itself called during unwinding (which would otherwise abort immediated due to a double-panic). This design meeting proposes to change this behavior to always abort if a panic attempts to escape a drop, even if this drop was invoked as part of normal function execution (as opposed to unwinding).

The dicussion on this issue dates back to 2014 (rust-lang/rust#14875) where the decision was made to support unwinding in drops but leave the door open to potentially reversing this decision.

Background reading

rust-lang/rust#86027

@danielhenrymantilla
danielhenrymantilla / lib.rs
Created December 15, 2021 00:50
Poorman's alloc-instrumentation
struct MyAllocator;
#[global_allocator]
static A: MyAllocator = MyAllocator;
const _: () = {
use ::std::{
alloc::{
GlobalAlloc,
Layout,
@danielhenrymantilla
danielhenrymantilla / _question.md
Last active June 2, 2023 11:49
Soundness of "existential lifetime" erasure

[These posts have been extracted from this Discord conversation, so as not to require readers to use their Discord account to read it 😔]

Question

HI!

Question and idea about narrowing lifetime of mutable references.

In rust code when developing finite state machines, behaviour trees and other algorithms we often need to pass around Context on which these algorithms will work.

digraph __crate__ {
subgraph cluster_Mir_0_10 {
graph [fontname="Courier, monospace"];
node [fontname="Courier, monospace"];
edge [fontname="Courier, monospace"];
// label=<fn main() -&gt; ()<br align="left"/>let mut _1: std::string::String;<br align="left"/>let mut _2: DropGlue&lt;&amp;mut std::string::String&gt;;<br align="left"/>let mut _3: &amp;mut std::string::String;<br align="left"/>let mut _4: *mut std::string::String;<br align="left"/>let _5: ();<br align="left"/>debug _2 =&gt; _2;<br align="left"/>debug _1 =&gt; _1;<br align="left"/>>;
bb0__0_10 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">0</td></tr><tr><td align="left" balign="left">StorageLive(_1)<br/></td></tr><tr><td align="left">_1 = String::new()</td></tr></table>>];
bb1__0_10 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">1</td></tr><tr><td align="left" balign="left">Sto