Skip to content

Instantly share code, notes, and snippets.

@Redchards
Redchards / Variant.hxx
Last active August 29, 2015 14:17
Simple and unfinished Variant class
#ifndef VARIANT
#define VARIANT
// Quick implementation of variant type, somewhat like boost::variant.
// Why not using boost then ? Boost is a big dependency, using it on such a tiny code
// would not be wise.
// NOTE : Is uint64 wise here ? I just chose it for security purpose
// Maybe using constexpr here would be wise. I don't want it to sound like a template metaprogramming showoff
@Redchards
Redchards / Variant.hxx
Created March 30, 2015 21:40
Simple variant type
#ifndef VARIANT
#define VARIANT
// Quick implementation of variant type, somewhat like boost::variant.
// Why not using boost then ? Boost is a big dependency, using it on such a tiny code
// would not be wise.
// NOTE : Is uint64 wise here ? I just chose it for security purpose
// Maybe using constexpr here would be wise. I don't want it to sound like a template metaprogramming showoff
x=[1000:9999];
v=zeros(1,9000);
v=v+floor(x./1000).^4;
v=v+(floor(x./100)-floor(x./1000)*10).^4;
v=v+(floor(x./10)-floor(x./100)*10).^4;
v=v+(x-floor(x./10)*10).^4;
v(find(v==x))
@Redchards
Redchards / ConstMath.hxx
Created August 19, 2015 15:53
Some simple constexpr math function (C++11)
/* This algorithm is based on a very popular algorithm among C programmers, used to calculate power of
a number. I used a tail recursivity, as I wanted it to be C++11 compliant, and thus I had no
unconstrained constexpr, thus no loops.
The algorithm is based on this simple observation :
for instance, we want to compute 6^7. We have that 6^7 = 6*(6^3*6^3) = 6*(6*(6^2)*6*(6^2))
We can see that there's some pattern in the expression. To see things more clearly, we can rewrite
the expression as follow:
6^7 = 6*6^2*(6^2)*(6^2)
Actually, the algorithm is doing the opposite order of the decomposition. That make sens as
we are starting from the base. To summarize the algorithm way of functionning, I would say the following :
@Redchards
Redchards / BitExtract.hxx
Last active August 29, 2015 14:27
Little tidbit that a friend asked me to write some time ago, in order for him to understand bitwise operations
#include <iostream>
#include <cstdint>
int64_t number = 0;
int64_t index = 0;
int main()
{
while(true)
{
@Redchards
Redchards / NumberSerie.hxx
Last active October 9, 2015 10:03
Simple number serie generation using C++ metaprogramming
template<size_t last>
void printNumbers()
{
std::cout << last << std::endl;
}
template<size_t head1, size_t head2, size_t... tail>
void printNumbers()
{
std::cout << head1 << std::endl;
@Redchards
Redchards / hello.cxx
Last active September 8, 2016 15:51
Unecessarly obfuscated "Hello World" code in C++. Compile with LLVM/clang, and now with g++ ! (woohooo!)
#include "hello.hxx"
using namespace Dante;
int main()
{
AlphaMan Benzaie;
Benzaie.KILLECVERYTINGBHLAAAAH();
}
@Redchards
Redchards / float_analysis.py
Created August 23, 2015 21:47
A bunch of helper functions to quickly extract information about floating point value. Used mainly for learning. Not production ready by any mean !
import struct
# I do not support Decimal type in this toy code
# This piece of code should just work on python2 and python3
# In general, it will work for single precision, IEEE754 compliant floating point numbers
# Dirty function to avoid having to type the condition in each function
def throwOnNonFloat(num):
if not(type(num) is float):
raise ValueError(str(num) + " is not a floating point number !")
@Redchards
Redchards / 01.hs
Last active September 1, 2015 02:12
Learning haskell with http://learnyouahaskell.com. Keeping it for posterity. Nothing very interesting.
module Test where
-- NOTE : I just write every type as training purpose
-- List used for testing purpose
-- Main testing list
mahList :: [Integer]
mahList = [1, 2, 3, 4, 65, 8779 , 11, 64, 15 , 48]
-- List used for rmDup, asit contains a lot of duplicates
@Redchards
Redchards / Logger.hxx
Created August 30, 2015 23:24
First attempt to create a policy-based exentsible and fast logging system I did some time ago. It failed, but gave a strong basis for another try (see github repository)
#ifndef COMMON_CORE_UTILITY_LOGGER
#define COMMON_CORE_UTILITY_LOGGER
#include <iostream>
/* This logger library attempts to be simple, but as extensible as possible, and as
* easy to use as possible. Performance is also taken in account, even if it's not
* the main reason for writing this.
* The ultimate goal is to achieve a clean interface, as easy to use as possible