Skip to content

Instantly share code, notes, and snippets.

View andr1972's full-sized avatar

Andrzej Borucki andr1972

View GitHub Profile
@andr1972
andr1972 / a.txt
Created June 10, 2024 16:37
Diff_example
int my_other_func(diffdata_t *dd1, long off1, long lim1)
{
if (my_test_cmp(dd1,off1,lim1)>0) return 1;
if (my_test_cmp(dd1,off1,lim1)<0.5) return -1;
return 0;
}
int my_test_cmp(diffdata_t *dd1, long lim1, diffdata_t *dd2)
{
@andr1972
andr1972 / findbit.cpp
Last active August 31, 2022 17:44
Find first set bit from position and to position
/* Is useful for searching empty slot */
#include <cstring>
#include <cstdio>
#include <cassert>
#include <chrono>
#include <cstdlib>
#include <exception>
using namespace std;
@andr1972
andr1972 / trimSample.cpp
Created August 23, 2022 12:22
Trim line in C++
#include <iostream>
using namespace std;
string trimLeft(const string& str)
{
const auto strBegin = str.find_first_not_of(" \t");
return str.substr(strBegin, str.length() - strBegin);
}
@andr1972
andr1972 / readlines.cpp
Created August 23, 2022 12:14
Read lines from text stream to vector in C++
//https://stackoverflow.com/questions/73446872/read-last-empty-line-of-a-text-file-in-c/73458476#73458476
/*
* it distinguishes between lastline with and wihout \n
* getline().good() returns true if after line is newline char.
* Push to vector last not good(), thus I must check if file is not empty (peek())
* */
#include <iostream>
#include <fstream>
#include <vector>
/****************************************************************************
**
** Created by Andrzej Borucki on 2022-08-20
**
** This file is part of the EdiQ project
** see file LICENSE of https://github.com/ideorg/EdiQ
**
****************************************************************************/
#include "Popup.h"
@andr1972
andr1972 / dialog.cpp
Created April 9, 2022 12:46
Start creating Qt compoenent
#include "dialog.h"
#include <QVBoxLayout>
#include <qxviewer.h>
#include <QLineEdit>
#include <QPushButton>
Dialog::Dialog()
{
QVBoxLayout *mainLayout = new QVBoxLayout;
@andr1972
andr1972 / CMakeLists.txt
Last active March 5, 2022 08:38
MInimal example of confiusion std::remove with remove from stdio.h
cmake_minimum_required(VERSION 3.7)
project(minimal_std)
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_ROOT_DIR /usr/include/wx-3.0)
find_package(wxWidgets COMPONENTS core base net REQUIRED)
include(${wxWidgets_USE_FILE})
add_definitions("-Werror=return-type -H")
@andr1972
andr1972 / BitOutput.cpp
Created June 29, 2019 15:04
Streams for Arithmetic encoder
#include <stdexcept>
#include "BitOutput.h"
BitOutput::BitOutput() :
currentByte(0),
numBitsFilled(0)
{}
void BitOutput::write(int b) {
if (b != 0 && b != 1)
throw std::domain_error("Argument must be 0 or 1");
@andr1972
andr1972 / FenwickFrequencyTable.cpp
Created June 29, 2019 13:13
FenwickFrequencyTable
#include <stdexcept>
#include "FenwickFrequencyTable.h"
FenwickFrequencyTable::FenwickFrequencyTable(const std::vector<uint32_t>& freqs) {
if (freqs.size() > UINT32_MAX - 1)
throw std::length_error("Too many symbols");
uint32_t size = static_cast<uint32_t>(freqs.size());
if (size < 1)
throw std::invalid_argument("At least 1 symbol needed");
@andr1972
andr1972 / codeeditor.cpp
Created March 9, 2019 19:08
No rule to make target 'debug/codeeditor.moc
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QTextBlock>
#include <QFileDialog>
#include <QFontDatabase>
#include <QMenu>
#include <QPainter>
#include <QPalette>
#include <QRegExp>