Skip to content

Instantly share code, notes, and snippets.

View ecatmur's full-sized avatar
👻

Ed Catmur ecatmur

👻
  • Maven Securities
  • Chicago
View GitHub Profile
#include <boost/asio.hpp>
#include <boost/asio/experimental/promise.hpp>
#include <boost/beast/core/tcp_stream.hpp>
#include <boost/beast/websocket/stream.hpp>
boost::asio::awaitable<void> echo(boost::beast::websocket::stream<boost::beast::tcp_stream>& stream) {
for (;;) {
boost::beast::flat_buffer buf;
co_await stream.async_read(buf, boost::asio::use_awaitable);
co_await stream.async_write(buf.data(), boost::asio::use_awaitable);
@ecatmur
ecatmur / vcs_prompt.sh
Last active July 19, 2022 08:24
Minimal bash prompt with return status, command sequence and VCS status (svn, git, hg) using Latin-1 symbols. User, host, path and branch are in title bar.
RD=`tput bold; tput setaf 1`
GN=`tput bold; tput setaf 2`
YL=`tput bold; tput setaf 3`
BL=`tput bold; tput setaf 4`
MG=`tput bold; tput setaf 5`
CY=`tput bold; tput setaf 6`
NC=`tput sgr0`
VCS_PROMPT_CHAR_svn='§'
VCS_PROMPT_CHAR_git='±'
VCS_PROMPT_CHAR_hg='¿'
@ecatmur
ecatmur / README.md
Last active July 6, 2022 20:30
piecewise-construct-ub
$ g++ --version
g++ (GCC) 12.1.0
$ g++ -O2 -std=c++14 a.cpp main.cpp && ./a.out
a.out: main.cpp:5: int main(): Assertion `f() == (*c().target<F*>())()' failed.
Aborted
$ clang++ --version
clang version 14.0.5
@ecatmur
ecatmur / 00-godbolt.md
Last active July 4, 2022 22:38
Advanced metaprogramming for low-latency trading, Maven-style
#include <boost/assert/source_location.hpp>
#include <algorithm>
#include <source_location>
#if not _MSC_VER
template<unsigned M, unsigned N>
#endif
struct sloc_literal {
#if _MSC_VER
char const* file = nullptr;
@ecatmur
ecatmur / references.md
Last active June 16, 2022 15:04
Motivating examples for relocation
#include <type_traits>
template<class, auto, auto, auto>
class accessor;
template<class C, auto id, auto getter, auto setter>
class property : public decltype(
id.template operator()<accessor<C, id, getter, setter>>())::type {};
template<class C, auto id, auto getter, auto setter>
@ecatmur
ecatmur / README.md
Last active March 14, 2022 15:00
functional cast as direct initialization
#!/bin/bash
NOBLOB=0000000000000000000000000000000000000000
root=$(git rev-parse --show-toplevel) || exit
revs=()
for arg; do
if [[ $arg == *...* ]] ; then
revs+=($(git name-rev --name-only --always ${arg%...*})
@ecatmur
ecatmur / constexpr-allocation.cpp
Last active May 7, 2021 14:42
Constexpr string processing and dropping to runtime via std::array
#include <array>
#include <iostream>
#include <string>
#include <utility>
#if __cpp_lib_constexpr_string >= 201907L
using string = std::string;
#else
struct string {
using value_type = char;