Skip to content

Instantly share code, notes, and snippets.

View durka's full-sized avatar

Alex Burka durka

View GitHub Profile
@durka
durka / munch.rs
Created July 22, 2015 21:42 — forked from anonymous/playground.rs
Simple TT muncher
// switch to nightly and uncomment these for debugging
//#![feature(trace_macros)]
//trace_macros!(true);
/// Trick the macro parser into outputting an item without checking its syntax
macro_rules! as_item( ($i:item) => ($i) );
macro_rules! foo(
// first rule: define the invocation syntax and call myself again with some
// easily parseable parameters (notice everything is bracketed)
@durka
durka / enumdiscr.rs
Last active September 11, 2015 23:50
//! ```cargo
//! [dependencies]
//! custom_derive = "*"
//! ```
#[macro_use] extern crate custom_derive;
macro_rules! DiscriminantEnum {
// public entry points

Justification of Send and Sync rules

T: Sync ⟺ &T: Send

Explanation

Consider a value a: T. Assume T: Sync. Then, to access a on multiple threads, it must be possible to send a reference to another thread, thus &T: Send. Therefore, T: Sync ⟹ &T: Send. Assume &T: Send. Sending &a: &T to another thread means a can be accessed concurrently, thus T: Sync is required. Therefore, &T: Send ⟹ T: Sync.

Proof

@insaneinside
insaneinside / draft.markdown
Created September 13, 2017 01:22
Whole-Crate Test-Case Reduction with C-Reduce

Whole-Crate Test-Case Reduction with C-Reduce

Sometimes, when working on a complex piece of software — or even a simple program or library with a non-trivial number of moving parts — you run into an issue and have absolutely no idea how to reduce your code to the minimum necessary in order to reproduce the error.

For the past several months I've been blocked by some trait-resolution errors in Symtern, my general-purpose interner crate. I knew the errors were somehow related to

#!/bin/bash
# assign env var, if set
HB="${HOMEBREW_PREFIX:=/usr/local}"
find -L "${HB}/opt" -name 'INSTALL_RECEIPT.json' -maxdepth 2 -print > /tmp/homebrew-installed.txt
printf '' > /tmp/homebrew-installed-w-options.txt
NAME=''
@ummjackson
ummjackson / fedistream.html
Last active January 25, 2024 16:20
fedistream - filter the Mastodon firehose with a single HTML file (work in progress!). Instructions: download the .zip, extract it and double-click the "fedistream.html" file to get started.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>fedistream</title>
<style>
html,
body {
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir,
@14427
14427 / hkt.rs
Last active February 7, 2024 10:18
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@killercup
killercup / pandoc.css
Created July 3, 2013 11:31
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}