Skip to content

Instantly share code, notes, and snippets.

Avatar
🇷🇺

Maxim Timakov max-dark

🇷🇺
View GitHub Profile
View merge_sort.cxx
// https://en.wikipedia.org/wiki/Merge_sort
#include <iostream>
#include <iomanip>
#include <cstddef>
#include <cassert>
using std::size_t;
@max-dark
max-dark / graham.cxx
Created Nov 21, 2020
Convex hull / Graham scan
View graham.cxx
auto comparePoints(const QPointF& a, const QPointF& b)
{
return a.x() < b.x() || (a.x() == b.x() && a.y() < b.y());
}
auto convex_hull_graham(QPolygonF& points)
{
if (points.size() <= 1) return points;
QPolygonF result, up, down;
View buffer.cxx
#include "buffer.hxx"
#include <filesystem>
#include <fstream>
#include <ios>
namespace fs = std::filesystem;
namespace Scan
{
@max-dark
max-dark / numbereditor.cxx
Created Sep 25, 2020
Qt5 custom QDoubleSpinBox
View numbereditor.cxx
#include "numbereditor.hxx"
namespace Schematics::Ui::Widgets
{
NumberEditor::NumberEditor(QWidget *parent)
: QDoubleSpinBox(parent)
{
setSuffix(" mm");
setDecimals(1);
setAlignment(Qt::AlignRight);
@max-dark
max-dark / CMakeLists.txt
Created Sep 20, 2020
custom gfx text item
View CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(examples LANGUAGES CXX)
set(CMAKE_CXX_STANDART 14)
set(CMAKE_CXX_STANDART_REQUIRED ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
@max-dark
max-dark / fizz_buzz.cxx
Last active Jan 23, 2020
fizz buzz without "if"
View fizz_buzz.cxx
// task: https://en.wikipedia.org/wiki/Fizz_buzz
// compile: g++ -std=c++14 -Wall -Wpedantic -Werror fizz_buzz.cxx -o fizz_buzz
#include <iostream>
#include <string>
namespace
{
std::string solve(int num);
}
int main()
@max-dark
max-dark / block_pool.c
Last active Jan 21, 2020
simple on-array allocator
View block_pool.c
// task: create two queues that will be located in one array of a fixed size
// solution: create a pool of blocks in this array.
// http://www.cyberforum.ru/algorithms/thread2569313.html
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
// настройки типов
@max-dark
max-dark / signed_area.cxx
Last active Jan 7, 2020
signed triangle area / rotation direction
View signed_area.cxx
#include <iostream>
#include <iomanip>
struct point_t
{
using coord_t = int;
coord_t x;
coord_t y;
};
@max-dark
max-dark / visitor-example.cpp
Created Aug 11, 2017
Visitor pattern example
View visitor-example.cpp
// https://en.wikipedia.org/wiki/Visitor_pattern
#include <iostream>
#include <memory>
class A;
class B;
class C;
struct Visitor
{
View read_bin_cycle.c
#include <unistd.h>
//...
ssize_t buf_size = ...;
char * buffer = (char *) malloc(buf_size);
//....
ssize_t read_count = 0;
int file_in;
file_in = open(...);