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 / 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 / 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 [email protected] 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