Skip to content

Instantly share code, notes, and snippets.

View ned14's full-sized avatar
💭
Happy happy happy!

Niall Douglas ned14

💭
Happy happy happy!
View GitHub Profile
/*
Linux ext4:
743004324000
778425979000 (+4.76%)
Win8.1 NTFS:
17565970224000
17890031536128 (+1.8%)
*/
@ned14
ned14 / v1.cpp
Created February 3, 2016 08:29
AFIO v1 style of C++ bitfields
#include <stdio.h>
#define BOOST_AFIO_DECLARE_CLASS_ENUM_AS_BITFIELD(type) \
inline constexpr type operator&(type a, type b) \
{ \
return static_cast<type>(static_cast<size_t>(a) & static_cast<size_t>(b)); \
} \
inline constexpr type operator&=(type a, type b) \
{ \
return static_cast<type>(static_cast<size_t>(a) & static_cast<size_t>(b)); \
@ned14
ned14 / v2.cpp
Created February 3, 2016 08:30
AFIO v2 style of C++ bitfields
#include <stdio.h>
#define BOOST_CXX14_CONSTEXPR constexpr
//! Constexpr bitwise flags support
template<class Derived, class T = unsigned> class bitwise_flags
{
T _value;
public:
//! The underlying type
@ned14
ned14 / v2_gen2.cpp
Created February 4, 2016 15:09
Improved enum bitfield thanks to feedback from Boost dev list
#include <stdio.h>
#include <type_traits>
#define BOOST_CXX14_CONSTEXPR constexpr
template<class Enum> struct bitfield : public Enum
{
using enum_type = typename Enum::enum_type;
using underlying_type = std::underlying_type_t<enum_type>;
private:
@ned14
ned14 / mailinabox.sh
Last active April 30, 2016 21:43
mailinabox on lxc
cd /root
aptitude install curl git
git clone https://github.com/ned14/mailinabox.git
cd mailinabox
DISABLE_FIREWALL=1 setup/start.sh
(Use usual@nedprod.com for the email and mail.nedprod.com for the server)
cd /home/user-data/ssl/nedprod.com
nano private_key.pem
(Use nedprod.com cert private key)
chmod og-rwx private_key.pem
@ned14
ned14 / pegasus_mail_to_mbox.py
Created December 30, 2016 02:13
Converts old, corrupted Pegasus Mail mail stores into portable mboxo or maildir stores suitable for import into almost any other mail client
#!/usr/bin/python3
# Converts Pegasus Mail v4.x .PMM files into Unix mbox files using lots
# of heuristics to repair any corruption in the Pegasus mail store
# (the "Unix mbox" feature of Pegasus produces malformed Unix mbox files)
# (C) 2016 Niall Douglas http://www.nedprod.com/
# File created: Dec 2016
#
# Best used with python 3.6, anything older has a less able email and
# mailbox python modules
@ned14
ned14 / upd.sh
Created April 11, 2017 12:32
Update all boostish libraries when configured as siblings
cd boost-lite
git checkout master
git checkout include/revision.hpp
git pull
git submodule update --init
mkdir -p build_posix
cd build_posix
cmake ..
cd ../..
@ned14
ned14 / PoorCachedIoPerformance.cpp
Last active September 5, 2017 20:51
Demos the poor cached i/o performance on Windows
/* Demos the poor cached i/o performance on Windows
Windows x64 with NTFS:
memcpy: 91.7057ns per 1Kb
Write: 1258.34ns per 1Kb
Read: 1318ns per 1Kb
Linux x64 with ext4:

Normal markdown code blocks with syntax highlighting:

template <class T> class foo;

The harder way which permits inline hyperlinking:

template <class T> class foo;

Note the link and syntax highlighting!

+++ title = "result<R, S>" weight = 20 +++

Header file result.hpp

namespace outcome_v2_xxx
{
namespace policy
{