Skip to content

Instantly share code, notes, and snippets.

View durka's full-sized avatar

Alex Burka durka

View GitHub Profile
@durka
durka / index.html
Created March 4, 2020 04:15 — forked from darwin/index.html
Welcome to comix!
<!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)">
@durka
durka / main.rs
Last active July 21, 2018 20:26 — forked from Yatekii/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 February 21, 2018 23:39 — forked from anonymous/playground.rs
How to get around lockstep iteration restrictions
#![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
};
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 October 30, 2017 20:31 — forked from anonymous/playground.rs
Hygiene-based ident generator
#![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
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 | | }
@durka
durka / playground.rs
Created June 20, 2017 23:38 — forked from anonymous/playground.rs
gensym macro
/// 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 00:52 — forked from anonymous/playground.rs
Twixt construct from Nickle
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 March 23, 2017 18:26 — forked from barafael/main.rs
Confused about error handling
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 15:52 — forked from anonymous/a

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.