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
@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 / 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 / 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 / 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)); \
/*
Linux ext4:
743004324000
778425979000 (+4.76%)
Win8.1 NTFS:
17565970224000
17890031536128 (+1.8%)
*/
#include <vector>
#include <future>
#include <filesystem>
using std::future;
namespace filesystem = std::experimental::filesystem;
class data_store
{
public:
//! Disposition flags
// Set a dispatcher as current for this thread
afio::current_dispatcher_guard h(afio::make_dispatcher().get());
// Config a write gather
std::vector<asio::const_buffer> buffers;
buffers.push_back(asio::const_buffer("He", 2));
buffers.push_back(asio::const_buffer("ll", 2));
buffers.push_back(asio::const_buffer("o ", 2));
buffers.push_back(asio::const_buffer("Wo", 2));
// Set a dispatcher as current for this thread
afio::current_dispatcher_guard h(afio::make_dispatcher().get());
// Config a write gather
std::vector<asio::const_buffer> buffers;
buffers.push_back(asio::const_buffer("He", 2));
buffers.push_back(asio::const_buffer("ll", 2));
buffers.push_back(asio::const_buffer("o ", 2));
buffers.push_back(asio::const_buffer("Wo", 2));
@ned14
ned14 / hamming_test.cpp
Last active April 6, 2020 20:28
More generalised C++ hamming code testing
/* hamming_test.cpp
Test generic hamming coding routines (SECDEC). These can fix 1 bit errors and detect two bit errors.
(C) 2015 Niall Douglas http://www.nedprod.com
g++ -std=c++11 -o hamming_test -O3 -fverbose-asm -Wa,-adhln hamming_test.cpp -march=ivybridge > hamming_test.S
On my 3.9Ghz Ivy Bridge Intel 3770K:
For no intrinsics:
Calculating 4Kb: 12.06Mb/sec
@ned14
ned14 / gist:9817276cc3769fe6f621
Last active August 29, 2015 14:13
Test generic hamming coding routines (SECDEC). These can fix 1 bit errors and detect two bit errors.
/* hamming_test.cpp
Test generic hamming coding routines (SECDEC). These can fix 1 bit errors and detect two bit errors.
(C) 2015 Niall Douglas http://www.nedprod.com
On my 3.9Ghz Ivy Bridge Intel 3770K:
For no intrinsics:
Calculating 4Kb: 12.06Mb/sec
Fixing 4Kb: 14.98Mb/sec