Skip to content

Instantly share code, notes, and snippets.

View ahamez's full-sized avatar
🦉

Alexandre Hamez ahamez

🦉
View GitHub Profile
@ahamez
ahamez / c++17.cc
Created July 20, 2018 13:22
Some C++17
// g++-8 -std=c++17 -Wall -Wextra -fsanitize=address c++17.cc
#include <array>
#include <cstddef>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <tuple>
@ahamez
ahamez / hmac.cc
Created March 21, 2018 15:25
HMAC with OpenSSL
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <openssl/hmac.h>
int main()
{
// https://tools.ietf.org/html/rfc2104#section-3
@ahamez
ahamez / big_endian.java
Last active July 28, 2017 14:30
Read big endian in Java
// Convert 4 unsigned big endian bytes to int
int x = java.nio.ByteBuffer.wrap(bytes).getInt();
@ahamez
ahamez / create_structs_bench.exs
Created February 17, 2017 13:49
Benchmarks different struct creations
defmodule Struct do
defstruct [:a, :b, :c, :d, :e, :f, :g, :h]
end
defmodule CreateStruct do
def create1() do
struct(Struct, create1_fields())
end
@ahamez
ahamez / algorithms.ex
Last active November 25, 2016 07:03
Some algorithms for insertion into sorted lists
defmodule Algorithms do
@doc ~S"""
Insert `elt` into the already sorted `list`.
iex> Algorithms.insert_sort(1, [])
[1]
iex> Algorithms.insert_sort(1, [2,3])
[1,2,3]
@ahamez
ahamez / msm.cc
Created January 7, 2016 16:46
Some Boost.MSM usages
#include <iostream>
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/functor_row.hpp>
namespace msm = boost::msm;
namespace mpl = boost::mpl;
using namespace msm::front;
@ahamez
ahamez / simple-fsm.cc
Created December 20, 2015 07:21
Idea for simple FSM interface
struct s0
{
template <typename SM>
void
on_entry(SM&)
const
{}
template <typename SM>
void
@ahamez
ahamez / dd.cc
Created December 19, 2015 11:05
A dummy Decision Diagram with reference counting using shared_ptr and weak_ptr
#include <cassert>
#include <map>
#include <memory> // shared_ptr, weak_ptr
#include <unordered_map>
#include <utility> // pair
/*----------------------------------------------------------------------------*/
class Node
{
@ahamez
ahamez / display_sleep.cc
Created November 1, 2015 20:26
Programmatically put display to sleep
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
// clang++ -framework CoreFoundation -framework IOKIT display_sleep.cc
int
main()
{
const io_registry_entry_t r =
IORegistryEntryFromPath( kIOMasterPortDefault
@ahamez
ahamez / CMakeLists.txt
Created November 1, 2015 17:33
CMake configuration to compile paho
cmake_minimum_required (VERSION 2.8.9)
project(paho)
find_package(OpenSSL)
find_package(Threads)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR})