Skip to content

Instantly share code, notes, and snippets.

View ahamez's full-sized avatar
🦉

Alexandre Hamez ahamez

🦉
View GitHub Profile
# ---------------------------------------------------------------------------------------------------
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.31.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
@ahamez
ahamez / rle.exs
Created February 4, 2021 13:01
RLE
# As an exercise after reading this tweet: https://twitter.com/Al_Grigor/status/1357028887209902088?s=20
str = String.split("aaaabbbcca", "", trim: true)
str
|> Enum.reduce([], fn
x, [{x, count} | rest] ->
[{x, count + 1} | rest]
x, acc ->
@ahamez
ahamez / timestamp.ex
Created September 15, 2020 15:47
Generate a timestamp in Elixir
defmodule Timestamp do
@moduledoc """
Generate a timestamp as an integer using current time.
"""
@spec make() :: integer()
def make() do
%{year: y, month: m, day: d, hour: hh, minute: mm, second: ss, microsecond: {us, _}} =
NaiveDateTime.utc_now()
@ahamez
ahamez / conformance.txt
Last active June 17, 2020 20:19
protobuf-elixir conformance
CONFORMANCE TEST BEGIN ====================================
ERROR, test=Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0: Should have failed to parse, but didn't. request=protobuf_payload: "\001DEADBEEF" requested_output_format: PROTOBUF message_type: "protobuf_test_messages.proto3.TestAllTypesProto3" test_category: BINARY_TEST, response=protobuf_payload: ""
ERROR, test=Required.Proto2.ProtobufInput.IllegalZeroFieldNum_Case_0: Should have failed to parse, but didn't. request=protobuf_payload: "\001DEADBEEF" requested_output_format: PROTOBUF message_type: "protobuf_test_messages.proto2.TestAllTypesProto2" test_category: BINARY_TEST, response=protobuf_payload: ""
ERROR, test=Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1: Should have failed to parse, but didn't. request=protobuf_payload: "\002\001\001" requested_output_format: PROTOBUF message_type: "protobuf_test_messages.proto3.TestAllTypesProto3" test_category: BINARY_TEST, response=protobuf_payload: ""
ERROR, test=Required.Proto2.Protobuf
# install aws cli first and configure it with credentials and default region
# the script will iterate over all regions of AWS
#! /bin/sh
for region in `aws ec2 describe-regions --output text | cut -f4`
do
echo -e "\nListing Instances in region:'$region'..."
# aws ec2 describe-instances --query "Reservations[*].Instances[*].{IP:PublicIpAddress,ID:InstanceId,Type:InstanceType,State:State.Name,Name:Tags[0].Value}" --output=table --region $region
@ahamez
ahamez / pointer_member.cc
Last active August 24, 2018 18:38
Pointer to member variable as template parameter
// clang++ -std=c++17 -Wall -Wextra pointer_member.cc
#include <iostream>
struct foo
{
int a;
int b;
};
@ahamez
ahamez / yocto_merge_manifest_licenses.cc
Created August 24, 2018 09:55
Merge FOSS licenses from Yoco MANIFEST files.
// clang++ -I. -std=c++17 -Wall -Wextra yocto_merge_manifest_licenses.cc
#include <fstream>
#include <iostream>
#include <regex>
#include <set>
#include <string>
#include <tuple>
#include <boost/algorithm/string/replace.hpp>
@ahamez
ahamez / double_portable_serialization.cc
Last active December 28, 2024 22:34
Portable serialization of floats using frexp and ldexpr. C++17
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>
// IEEE 754 does not specify endianess (https://en.wikipedia.org/wiki/Endianness#Floating_point).
// So, to have a portable representation, we can "decompose" the floating-point value using frexp().
@ahamez
ahamez / padding_ub.cc
Last active July 22, 2018 15:34
Padding and undefined behavior
// When compiled (macOS, 64 bits) with g++-8 -O3 -std=c++14 ub.cc -Wall -Wextra:
// 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// Notice the '1' coming from nowhere :-)
// Note that clang++ produces:
// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#include <cstdint>
@ahamez
ahamez / deduction_guide.cc
Created July 21, 2018 07:44
C++17 deduction guides
#include <functional>
#include <iostream>
#include <string>
#include <variant>
template <typename... Ts>
struct make_visitor
: Ts...
{
using Ts::operator()...;