Skip to content

Instantly share code, notes, and snippets.

View jspohr's full-sized avatar

Johannes Spohr jspohr

View GitHub Profile
@jspohr
jspohr / microsecs.c
Last active March 9, 2024 13:32
Avoid overflow when converting time to microseconds
// Taken from the Rust code base: https://github.com/rust-lang/rust/blob/3809bbf47c8557bd149b3e52ceb47434ca8378d5/src/libstd/sys_common/mod.rs#L124
// Computes (value*numer)/denom without overflow, as long as both
// (numer*denom) and the overall result fit into i64 (which is the case
// for our time conversions).
int64_t int64MulDiv(int64_t value, int64_t numer, int64_t denom) {
int64_t q = value / denom;
int64_t r = value % denom;
// Decompose value as (value/denom*denom + value%denom),
// substitute into (value*numer)/denom and simplify.
// r < denom, so (denom*numer) is the upper bound of (r*numer)
@jspohr
jspohr / handmadecon2015.xml
Last active December 8, 2015 10:43
HandmadeCon Interviews Podcast Feed
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>HandmadeCon</title>
<description>HandmadeCon 2015 Interviews</description>
<link>http://handmadecon.org/</link>
<language>en-us</language>
<itunes:category text="Technology">
<itunes:category text="Podcasting"/>