Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Burka durka

View GitHub Profile
@durka
durka / index.html
Created Mar 4, 2020 — forked from darwin/index.html
Welcome to comix!
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:1200px; -webkit-transform:rotate(0deg)">
<scene id="scene1">
<drawing t="translate(0,31)">
View main.rs
let (device, factory) =
if let Ok((d, f)) = panic::catch_unwind(|| { gfx_device_gl::create(epoxy::get_proc_addr) }) {
(d, f)
} else {
return "ERROR";
};
@durka
durka / playground.rs
Created Feb 21, 2018 — forked from anonymous/playground.rs
How to get around lockstep iteration restrictions
View playground.rs
#![feature(trace_macros)] trace_macros!(true);
macro_rules! doc_items {
(@distribute $docs:tt $($item:item)*) => {
$(doc_items!(@output $docs $item);)*
};
(@output [$($doc:expr),*] $item:item) => {
$(#[doc=$doc])*
$item
};
View playground.rs
macro_rules! siaf {
(|$($parm:ident),* $(,)*| $body:expr) => {{
/* ensure no captures */ let closure: fn($($parm: _),*)->_ = |$($parm),*| $body;
(closure)($($parm),*)
}}
}
fn compute_g(a: i32, b: i32, c: i32) -> i32 {
let d = siaf!(|a, b| a + c);
let (e, f) = siaf!(|d| (d - 1, d + 1));
@durka
durka / playground.rs
Created Oct 30, 2017 — forked from anonymous/playground.rs
Hygiene-based ident generator
View playground.rs
#![feature(trace_macros)] trace_macros!(true);
/// Given N tokens, recurses N times to generate N unique identifiers
/// then calls you back at the given macro
macro_rules! idents {
// finished recursing, do the callback
(@rec [] -> $ids:tt $mac:ident!($($params:tt)*)) => {
$mac!($($params)* $ids)
};
// consume one token and generate one identifier
View error.rs
warning: unreachable pattern
--> src/routes.rs:66:1
|
66 | / handle_login! {
67 | | #[get("/<date>/<flow>/<idx>")]
68 | | pub fn episode/episode_login(user: User, users: State<ActiveUsers>, date: Datestamp, flow: Option<FlowType>, idx: u32) -> Template {
69 | | let flow = flow.ok_or(ErrorKind::BadParam("invalid flow type"))?;
... |
132 | | }
133 | | }
View playground.rs
/// This auxiliary macro generates an ident for each argument passed to it,
/// and then calls another macro back with the generated idents.
macro_rules! gensym {
// base case: we send all the collected idents back to the other macro
(@go $callback:ident ($($args:tt)*) ($($i:ident)*)) => {
$callback!($($args)* $($i)*)
};
// recursion: here, we add in a new ident named "x" (but distinct from every other "x")
(@go $callback:ident $args:tt ($($i:ident)*) $head:tt $($tail:tt)*) => {
@durka
durka / twixt.rs
Last active May 4, 2017 — forked from anonymous/playground.rs
Twixt construct from Nickle
View twixt.rs
macro_rules! twixt {
(($cond:expr; $after:expr) { $($body:tt)* } else { $($els:tt)* }) => {{
if $cond {
struct Doop;
impl Drop for Doop { fn drop(&mut self) { $after; } }
let _d = Doop;
$($body)*
} else {
$($els)*
}
@durka
durka / main.rs
Last active Mar 23, 2017 — forked from barafael/main.rs
Confused about error handling
View main.rs
use std::process::Command;
fn main() {
println!("{}", git_name().unwrap_or("".to_string()));
}
pub fn git_name() -> Option<String> {
if let Ok(output) = Command::new("git")
.arg("config")
@durka
durka / a.md
Last active May 2, 2016 — forked from anonymous/a
View a.md

Proofs of Send and Sync laws

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.