Skip to content

Instantly share code, notes, and snippets.

View madsmtm's full-sized avatar

Mads Marquart madsmtm

  • Copenhagen, Denmark
  • 13:20 (UTC +02:00)
View GitHub Profile
@madsmtm
madsmtm / Cargo.toml
Created March 28, 2025 08:26
Minimal `cc-rs` `#![no_std]` example
[package]
name = "example"
version = "0.1.0"
edition = "2021"
publish = false
[build-dependencies]
cc = "1.2.17"
[lib]

#Rust2019 Are We GUI Yet?

By Dustin Bensing (@pythoneer). Originally posted 2019-01-13 here (Archived link).

The Rust 2018 journey has been great so far. 2018 was a year filled with great feature additions to the core language along with improvements to the ecosystem. The year 2018 also saw the release of the first fully fleshed out Rust edition 🎉. And as 2018 has come to its end, we are once more encouraged to Blog about the things we'd like to see in 2019.

I have many things I'd like to see in the new year and to bring it home its mostly the same thing I've read in other posts on Reddit and/or blog posts:

I will finish what you started

@madsmtm
madsmtm / method_call_expression_pseudo_code.rs
Created December 1, 2023 05:23
Pseudo-code for Rust method-call expressions
/// Pseudo-code for how [method-call expressions] work.
///
/// [method-call expressions]: https://doc.rust-lang.org/reference/expressions/method-call-expr.html
fn lookup_method(mut T: Type, method_name: &str) -> Method {
// The first step is to build a list of candidate receiver types.
let mut candidate_receiver_types = vec![T];
// Obtain these by repeatedly dereferencing the receiver expression's
// type, adding each type encountered to the list,
while let Some(U) = <T as Deref>::Target {
@madsmtm
madsmtm / incomplete-facebook-schema.graphql
Last active September 5, 2019 14:50
A very incomplete description of Facebook's GraphQL schema (from 2017)
schema {
Query: Query
Mutation: Mutation
}
type Query() {
viewer: Viewer!
entities_named: SearchableEntitiesQuery!
}
@madsmtm
madsmtm / postgresql-on-delete-performance.sql
Created April 25, 2019 13:20
PostgreSQL ON DELETE performance analysis - SET NULL vs. SET DEFAULT vs. CASCADE
-- Initialize tables
DROP TABLE IF EXISTS table1, table2;
CREATE TABLE table1 (col integer PRIMARY KEY);
CREATE TABLE table2 (
col integer REFERENCES table1(col)
ON DELETE SET DEFAULT -- Experiment with different ON DELETE clauses
);
-- Optionally create an index
CREATE INDEX ON table2(col);
@madsmtm
madsmtm / flask_automatic_jsonify.py
Created March 26, 2019 09:01
Automatic JSON serialization for Flask
# Credit to:
# - http://derrickgilland.com/posts/automatic-json-serialization-in-flask-views/
# - https://blog.miguelgrinberg.com/post/customizing-the-flask-response-class
from flask import Response, Flask, jsonify
class AutoJSON(Response):
@classmethod
def force_type(cls, response, environ=None):
"""Override to convert list & dict returns to json."""
@madsmtm
madsmtm / messenger-colors.md
Created February 28, 2019 22:37
Facebook Messenger thread colors
Internal ID Color Label Gradient
205488546921017 #ff7ca8 Candy #ff8fb2 #a797ff #00e5ff
370940413392601 #1adb5b Citrus #ffd200 #6edf00 #00dfbb
164535220883264 #f01d6a Berry #005fff #9200ff #ff2e19
930060997172551 #ff9c19 Mango #ffdc2d #ff9616 #ff4f00
417639218648241 #0edcde Aqua #19c9ff #00e6d2 #0ee6b7
196241301102133 #0084ff Default Blue N/A
1928399724138152 #44bec7 Teal Blue N/A
174636906462322 #ffc300 Yellow N/A
@madsmtm
madsmtm / httpbin_sansio_get.py
Last active December 9, 2018 23:42
Rudimentary, Sans-IO `https://httpbin.org/get`, with a syncronous implementation on the side
import json
import h11
from urllib.parse import urlencode
class Get:
"""Sans-IO implementation of `/get`"""
def __init__(self, params):
self.params = params
@madsmtm
madsmtm / h11_sync_client.py
Last active December 9, 2018 23:41
`h11` example client as a class
# This file is adapted from h11's example client
# See https://github.com/python-hyper/h11/blob/master/examples/basic-client.py
import socket
import ssl
import h11
class Client:
def __init__(self, host):
self.conn = h11.Connection(our_role=h11.CLIENT)
@madsmtm
madsmtm / graphene-pytest.py
Created December 9, 2018 13:41
Graphene pytest fixtures
from pytest import fixture
from graphene.test import Client
@fixture(scope="session")
def _schema():
raise NotImplementedError(
"You must implement this fixture yourself."
"It should return an instance of `graphene.Schema`"
)