Skip to content

Instantly share code, notes, and snippets.

Andrean Franc integricho

Block or report user

Report or block integricho

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@integricho
integricho / endianness.h
Created May 13, 2019 — forked from jtbr/endianness.h
cross-platform / cross-compiler standalone endianness conversion
View endianness.h
/**
* @file endianness.h
* @brief Convert Endianness of shorts, longs, long longs, regardless of architecture/OS
*
* Defines (without pulling in platform-specific network include headers):
* bswap16, bswap32, bswap64, ntoh16, hton16, ntoh32 hton32, ntoh64, hton64
*
* Should support linux / macos / solaris / windows.
* Supports GCC (on any platform, including embedded), MSVC2015, and clang,
* and should support intel, solaris, and ibm compilers as well.
@integricho
integricho / jump_table.h
Created May 17, 2018
Elegant jump table abstraction
View jump_table.h
struct not_found
{
};
template <typename TKey, typename TValue, TKey...>
struct JumpTable;
template <typename TKey, typename TValue>
struct JumpTable<TKey, TValue>
{
View jump_table_benchmark.cpp
#include <benchmark/benchmark.h>
#include <unordered_map>
struct EnumClassHash
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
@integricho
integricho / enum_check.h
Created Apr 24, 2018
Check if an integral type could be safely cast to an enum.
View enum_check.h
template <typename TEnumType, TEnumType... EValues>
struct EnumCheck;
template <typename TEnumType>
struct EnumCheck<TEnumType>
{
template <typename IntegralType>
static constexpr bool is_valid(IntegralType value)
{
@integricho
integricho / counter.h
Created Oct 10, 2017
Simple instance counter class
View counter.h
template <typename T>
class Counted
{
public:
Counted()
{
++m_count;
}
Counted(const Counted& rhs)
{
@integricho
integricho / gist:5b7a7d089b79395bbac9
Last active Aug 29, 2015
Helper decorator for Django unittests, used to make sure that the expected signals were fired the expected number of times.
View gist:5b7a7d089b79395bbac9
"""
Helper decorator for Django unittests, used to make sure that the expected
signals were fired the expected number of times.
Usage:
class MyTestCase(TestCase):
@assert_signal_fired({
'my_signal_func': (my_signal_func, 1),
'other_signal_func': (other_signal_func, 0)
@integricho
integricho / gist:6502772fd3c144c719a7
Created Jun 26, 2014
Django override_settings for apps with intermediary settings modules
View gist:6502772fd3c144c719a7
"""
Django provides it's own `django.test.utils.override_settings` function
to override settings temporarily in unittests, but in case an intermediary
module is used to accumulate all the app's settings, it won't have effect on
them. E.g. an app-level `settings.py` module, which uses `getattr` over Django's
settings module to collect all the params required.
This decorator works a bit different, it cannot be applied to the whole TestCase
class, but to specific test functions, although achieves the same result as the
one provided by Django. Namely, it will temporarily override in the app-level
settings module all the specified variables, then run the test function, and
@integricho
integricho / graph.py
Last active Dec 10, 2015
edX MIT 6.00x Problem Set 10 solution / approach 2
View graph.py
# 6.00 Problem Set 10
# Graph optimization
#
# A set of data structures to represent graphs
#
class Node(object):
def __init__(self, name):
@integricho
integricho / graph.py
Last active Apr 16, 2016
edX MIT 6.00x Problem Set 10 solution
View graph.py
# 6.00 Problem Set 10
# Graph optimization
#
# A set of data structures to represent graphs
#
class Node(object):
def __init__(self, name):
You can’t perform that action at this time.