Skip to content

Instantly share code, notes, and snippets.

View poseidon4o's full-sized avatar

Lyubomir poseidon4o

View GitHub Profile
#define _CRT_SECURE_NO_WARNINGS
#include <sys/types.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <iostream>
#include <ostream>
#include <ratio>
#include <semaphore>
#include <sstream>
#include <iostream>
/**
* @brief Compute the length of a string (number of bytes before \0)
*
*/
int getStrlen(const char *str) {
// library function:
// return strlen(str);
int length = 0;
#include <chrono>
#include <functional>
template <typename Key, typename Value>
struct TimedMap {
using clock = std::chrono::steady_clock;
using time_point = clock::time_point;
using callback = std::function<void (const Key &key, const Value &value)>;
TimedMap(int concurrencyLimit);
#include <mutex>
#include <vector>
#include <thread>
#include <condition_variable>
/// Size of the render target in console characters
const int WIDTH = 100;
const int HEIGHT = 30;
/// Render target, render threads write next frame here
/// 1 extra in width for terminating '\0'
#if _WIN64
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <unordered_map>
struct NamedArguments {
enum class Name {
start, step, stop
};
struct BaseArg {
Name name;
void printNumbers(/*TODO:*/) {
/*TODO:*/
for (int c = start; c < stop; c += step) {
std::cout << c << ' ';
}
std::cout << std::endl;
}
#include <cctype>
#include <cstring>
#include <iostream>
typedef int (*Validator)(int);
bool isValidRegistration(char reg[9]) {
const Validator validators[9] = {isupper, isupper, isdigit, isdigit, isdigit, isdigit, isupper, isupper };
const int len = strlen(reg);
const Validator *check = len == 8 ? validators : validators + 1;
#include <iostream>
typedef unsigned char pixel[3];
typedef pixel** Image;
/// Typedef for fully const pixel array to avoid long type
typedef const pixel * const* const ConstImage;
/// 2D matrix of booleans, used to mark pixels as visited
typedef bool** BoolMatrix;
#include <iostream>
template <typename T>
struct ScopedPointer {
private:
T *ptr;
public:
ScopedPointer(const ScopedPointer &) = delete;
ScopedPointer &operator=(const ScopedPointer &) = delete;