Skip to content

Instantly share code, notes, and snippets.

@scraimer
scraimer / x11vnc-stack-smashing-detected-solution.mk
Last active June 2, 2021 05:57 — forked from mangoliou/x11vnc-stack-smashing-detected-solution.mk
x11vnc `stack smashing detected` - disable detection, as a non-root user
# On my system, I don't have root access. So here's how I built it
# as a non-root user, without `sudo` or the ability to
# install packages, although many packages were already installed.
#
# In particular, I had to download and build LibVNCServer,
# and configure x11vnc to use it the one I had built
mkdir -p ~/bin/x11vnc
cd ~/bin/x11vnc
@scraimer
scraimer / conan.gradle
Created December 3, 2020 07:50
I was looking for conan.gradle, found a broken one, and fixed it to work for libraries, instead of applications. Didn't work in the end, though :-(
// From https://gist.github.com/CAMOBAP795/ed9aa6a7549787b5eea4b2048b896747
// with some changes
//
// Originally discovered here: https://github.com/conan-io/docs/issues/1259
import groovy.text.SimpleTemplateEngine
import java.nio.file.Paths
class ConanPluginExtension {
String conanfile = "src/main/cpp/conanfile.txt"
@scraimer
scraimer / example_base64_decode_using_BIO.cpp
Created October 17, 2018 09:05
Use OpenSSL BIO chain to read a base64-encoded file and write the decoded binary to a file
#include <string>
#include <cstring>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/bio.h>
//#include <openssl/bytestring.h>
#include <openssl/crypto.h>
@scraimer
scraimer / copy_using_back_inserter_between_different_typed_vectors.cpp
Last active June 14, 2017 05:54
Using std::copy and std::back_inserter to copy between vectors of different types
/*
* By adding a converting constructor to `person` (that converts from `thingy` to `person`)
* we can allow the std::back_inserter to work when copying from vector<thingy> to vector<person>
*
* This allows a one-liner that calls `push_back` over and over.
*
* Note: The repeated calls to `push_back` might have a performance cost.
* The alternative is to do it in two lines:
*
* people.reserve(N);
@scraimer
scraimer / get_member_value_when_present.cpp
Last active June 14, 2017 05:15
Get member if present, or default value if not
/*
* Goal: To have a class template that can recieve a template parameter of a class that either
has a member (e.g. _time) or doesn't have a member.
The class template has a function (e.g. get_time) which should return the value (e.g. _time),
or a default value (e.g. 22)
So far, I've got a class template 'getter_maker_t' that depending on its arguments can
will either create a class that returns the value, or returns a class that returns the default value.
@scraimer
scraimer / accumulate_array_example.cpp
Created February 12, 2017 08:29
Showing that std::acuumulate is just as good as a for loop on
#include <numeric>
#include <iterator>
int vals[5] = {1, 2, 3, 4, 5};
int main()
{
// Force the array into a const (just because I don't want to iterate on modifiable cells
auto const & b = vals;
int sum = std::accumulate(std::begin(b), std::end(b), 0);
@scraimer
scraimer / search-integer-parameter-pack.v3.cpp
Created January 31, 2017 07:27
Find index of integer in template parameter pack in C++14
// Forward declaration, so that helper knows about constexpr_find_in_int_parameter_pack
template <int V1, int... V_rest> struct constexpr_find_in_int_parameter_pack;
// Don't read this first, read the constexpr_find_in_int_parameter_pack first.
//
// Back? Good. This class *purely* to allow specializing the empty case using helper<>.
//
// The helper class allows us to separate the unpacking of the parameter pack (that is handled by
// constexpr_find_in_int_parameter_pack) from the stop condition (that is handled by the helper class). I
// couldn't figure out how to do both without in a single class.
// The flat_fix_parser I designed is good:
// Pro:
// * compile-time checking of fields
// * compact in memory, so less cache-thrashing
// Con:
// * doesn't support multiple copies of the same tag
// * fixed size in memory means there's no ability to handle unlimited number of tags
//
// To fix this, I want a more extensible design. Convert the FIX message into its hierarcy.
// For example, a V message that only has a repeating group of 269s within a 267:
#include <stdint.h>
/*
Problem Space:
--------------
FIXT1.1 is a protocol where FIX data is sent in fields separated by a 0x01.
In each field, the format is "tag=value", where "tag" is a number
from 1 upwards.
@scraimer
scraimer / benchmark_copy_latency_from_uint8_to_uint16.cpp
Last active March 1, 2016 05:49
A StackOverflow question was complaining about copying an array of uint8 to an array of uint16 as a "bottleneck". That sounded like a latency problem, and while I was looking into it, I finally got to write down the magic anti-optimizer functions that Chandler Carruth mentioned in his CppCon talk, for preventing code/data from being optimized away.
#include <cstdint>
#include <chrono>
#include <iostream>
/* The following two functions are from a talk by Chandler Carruth:
*
* CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"
*
* [https://www.youtube.com/watch?v=nXaxk27zwlk]
*/