Skip to content

Instantly share code, notes, and snippets.

View maru's full-sized avatar

Maru Berezin maru

View GitHub Profile
@maru
maru / alignment.c
Last active December 11, 2021 21:42
Calculate aligned size for a chunk
/*
Primitive data is said to be aligned if the memory address where it is stored is a multiple of the size of the primitive.
https://accu.org/conf-docs/PDFs_2008/Alexandrescu-memory-allocation.screen.pdf
*/
size_t alignment = 2; /* 2^aligment is the size of the chunk */
size_t adj = alignment - 1;
size_t sz = (requested_size + adj) & ~adj;
@maru
maru / double2int.c
Created September 9, 2016 15:53
Convert double to int without losing precision
double price = 18.90;
// DO :)
int cents = (int) (price * 10000.);
cents /= 100;
// cents is 1890
// DON'T!
cents = (int) (price * 100.);
// cents is 1889
@maru
maru / install-qtbrowser.sh
Last active August 27, 2016 06:30
Build qtbrowser in Linux with Qt5 webkit (shared or static library)
#!/bin/bash
# Build qtbrowser with Qt5 in Linux
# https://github.com/Metrological/qtbrowser
#
# Usage:
# ./install-qtbrowser.sh build-icu build-openssl build-qt build-qtbrowser
#
# Compile as a static library:
# ./install-qtbrowser.sh build-icu build-openssl build-qt build-qtbrowser static
#