Skip to content

Instantly share code, notes, and snippets.

@falemagn
falemagn / access_member.hpp
Last active February 1, 2021 20:02
[c++] Get hold of any class' private members. Lawfully.
/* Inspired to the work of hliberacki: https://github.com/hliberacki/cpp-member-accessor
* But made it much shorter, and works even with C++98.
*
* Usage:
*
* class PrivateStuff
* {
* int dont_steal;
* };
*
@falemagn
falemagn / error_on_date.hpp
Last active June 27, 2019 12:50
Statically error out on a given date.
namespace error_on_date {
inline constexpr bool strequal(char const *a, char const *b) {
return *a == *b && (*a == '\0' || strequal(a + 1, b + 1));
}
}
#if defined(ERROR_ON_DATE$$USE_CLASS) && ERROR_ON_DATE$$USE_CLASS
namespace error_on_date {
struct date {
constexpr date(unsigned int year, unsigned int month, unsigned int day):
@falemagn
falemagn / MapIgnoreNulls.java
Last active July 12, 2018 19:52
[RxJava 2] Transformer that implements a map that ignores nulls and continues processing the observable output
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.functions.Function;
import java.util.Optional;
public class MapIgnoreNulls {
public static <T,R> ObservableTransformer<T,R> create(Function<? super T, ? extends R> mapper) {
return observable -> observable
.map(t -> Optional.ofNullable(mapper.apply(t)))
@falemagn
falemagn / getdevnodes.sh
Last active October 8, 2017 12:40
On Linux, get info about device nodes, given a device class and/or a device type and/or a vendor id and/or a product id
##################################################################################################
# Two bash functions to get info about device nodes in Linux. #
# Feel free to use and share, respecting the below license. :) #
# #
# Copyright © 2017 Fabio Alemagna #
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted #
# provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this list of #