Skip to content

Instantly share code, notes, and snippets.

@SimonSapin
SimonSapin / nvs_postcard.rs
Created August 18, 2022 22:47
impl embedded_svc::storage::Storage for esp_idf_svc::nvs_storage::EspNvsStorage
use embedded_svc::storage::RawStorage;
use embedded_svc::storage::Storage;
use embedded_svc::storage::StorageBase;
use esp_idf_svc::nvs::EspDefaultNvs;
use esp_idf_svc::nvs_storage::EspNvsStorage;
use esp_idf_sys::EspError;
use std::sync::Arc;
pub fn default(namespace: &str) -> Result<PostcardStorage<EspNvsStorage>, EspError> {
let read_write = true;
@SimonSapin
SimonSapin / 0000-numeric-conversions.md
Created March 11, 2022 18:15
Rust pre-RFC: Add explicitly-named numeric conversion APIs
@SimonSapin
SimonSapin / pdfedit.py
Created December 21, 2020 10:51
Make a PDF file editable in LibreOffice, using Poppler and Inkscape
#!/usr/bin/env python3
"""
Make a PDF file editable in LibreOffice.
LibreOffice Draw can import and export PDF files, effectively making it a PDF editor.
However text in imported documents often looks broken, such as with
text rendered with a different font and overflowing into the next column.
What I suspect happens is that PDF files typically embed every font they use,
but LibreOffice’s internal document model does not support embedded fonts
#!/home/simon/.virtualenvs/weasyprint/bin/python
import weasyprint
import markdown
import os
here = os.path.dirname(__file__)
with open(os.path.join(here, "resume.md"), encoding="utf-8") as f:
html = markdown.markdown(f.read(), extensions=["def_list"])
doc = weasyprint.HTML(string=html)
<html>
<head>
<title>Cargo Build Timings — servo 0.0.1</title>
<meta charset="utf-8">
<style type="text/css">
html {
font-family: sans-serif;
}
@SimonSapin
SimonSapin / index.html
Created September 26, 2019 07:30
cargo-timing-20190926T070741Z.html for Servo
<html>
<head>
<title>Cargo Build Timings — servo 0.0.1</title>
<meta charset="utf-8">
<style type="text/css">
html {
font-family: sans-serif;
}
if address :is ["To"] ["servo@noreply.github.com"] {
if header :is ["X-GitHub-Reason"] ["manual", "author", "comment", "mention", "assign"] {
fileinto "Mozilla.Servo.mentions";
stop;
}
if header :matches ["Subject"] "Re: *" {
fileinto "Mozilla.Servo.replies";
stop;
}
fileinto "Mozilla.Servo";
@SimonSapin
SimonSapin / gist:b46b1fc78d2d9adae16e
Created January 26, 2015 01:42
Constant extra space merge
// https://twitter.com/mraleph/status/559477604659773440
// merge two sorted arrays in O(1) memory and O(n) time. nice excercise
// sort array of length k + m such that a[0] <= ... <= a[k-1] & a[k] <= ... <= a[k+m-1], in place in O(k+m) time
#![allow(unstable)]
// data.len() == k + m
fn merge(data: &mut [u8], k: usize) {
// M = data[..a] is merged
// A = data[a..b] is initially the first sub-array, of length k
@SimonSapin
SimonSapin / gist:76f900e23e01fd5e44ff
Last active August 29, 2015 14:10
Vertical text in Servo, 2014-12-01

https://medium.com/@slsoftworks/why-should-one-keep-an-eye-out-for-servo-6d53eb6f64ff

Servo is currently basically the only browser engine that supports native rendering of vertical texts

As much as I love hearing from people that Servo is awesome, this is not correct.

First, vertical text support in Servo is currently (2014-12-01) experimental (behind an off-by-default flag), in early stages of development, and very buggy. So saying that we support is is a bit of a stretch :)

Second, other browsers have it too, although I don’t know how complete or how buggy. Microsoft has had some form of it since IE 5 (!), WebKit/Blink have it prefixed, and Firefox has it in Nightly.

@SimonSapin
SimonSapin / urlparser.rs
Created December 4, 2013 20:23
WIP URL parser for Rust, by @jgraham
use std::str;
use std::iterator::{Iterator};
use std::str::{eq, eq_slice, ByteIterator};
use std::vec;
use std::ops;
use std::char;
struct IPv6Address {
data: [u16, ..8]
}