Skip to content

Instantly share code, notes, and snippets.

{What is the capital of Bulgaria?, Sofia,[]}
{What is three times three minus 8, 1,[]}
{Who let the dogs out, who,[]}
@IvanIvanoff
IvanIvanoff / mutate.cpp
Created March 16, 2017 09:09
Mutate private data of a class though a pointer of a class with the same memory layout
// Example program
#include <iostream>
#include <string>
class X
{
int x; //private
int y; // private
public:
def handle_cast({:create, name}, names) do
if Map.has_key?(names, name) do
{:noreply, names}
else
{:ok, bucket} = KV.Bucket.start_link
{:noreply, Map.put(names, name, bucket)}
end
end
@IvanIvanoff
IvanIvanoff / numsystems.cpp
Created February 9, 2016 18:26
Converts from dec to other numeral systems
#include <iostream>
#include <assert.h>
const int NUM_SYSTEM = 2;
char arr[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W', 'X','Y', 'Z' };
char* DecToNumSystem(unsigned int num)
{
assert(NUM_SYSTEM > 1);
int size = std::floor(log(num) / log(NUM_SYSTEM)) + 1;
char* res = new char[size];
#pragma once
struct node;
class Queue
{
public:
Queue();
~Queue();
public:
#pragma once
struct node;
class Stack
{
public:
Stack();
~Stack();
public:
bool push(int);
bool pop();
@IvanIvanoff
IvanIvanoff / MemoryAllocator.h
Last active February 9, 2016 18:28
Custom memory allocator using explicit free lists. The allocator supports free header coalescence and splitting.
#pragma once
#ifndef __MEMORY_ALLOCATOR_H__
#define __MEMORY_ALLOCATOR_H__
/*! \file MemoryAllocator.h
\brief Header file for the memory allocator.
@author Ivan Aleksandrov Ivanov
@version 1.0
#include "MemoryAllocator.h"
#include <iostream>
#include <exception>
#include <new>
#include <assert.h>
#include <algorithm>
// ALWAYS a power of 2 !!!
const int ALIGNMENT = 8;
@IvanIvanoff
IvanIvanoff / TestMemoryAllocator.cpp
Last active November 23, 2021 15:04
Unit tests for the memory allocator using the Microsoft Unit Test Framework for C++
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../MemoryAllocator/MemoryAllocator.h"
#include "../MemoryAllocator/MemoryAllocator.cpp"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
BEGIN_TEST_MODULE_ATTRIBUTE()
TEST_MODULE_ATTRIBUTE(L"Project", L"UnitTests")
TEST_MODULE_ATTRIBUTE(L"Date", L"24/01/2016")
END_TEST_MODULE_ATTRIBUTE()
//IMHO using Class for this task is an overkill
//So I am using just one struct and a few functions to operate with it
//NOTE: The input must start with ( and the first digit of the root must be at position 1 !!!
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>