Skip to content

Instantly share code, notes, and snippets.

@aliakseis
aliakseis / gist:03eec11f18706bc52e83b8d95e10ba86
Created July 28, 2018 12:21
C++ strings filtering example
#include <algorithm>
#include <iostream>
#include <iterator>
#include <streambuf>
template<char C>
class FilterBuf : public std::streambuf
{
char readBuf_;
const char* pExternBuf_;
@aliakseis
aliakseis / gist:897b06bedd5079b410a378c356430495
Created July 28, 2018 13:31
longest common subsequence
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <iterator>
#include <sstream>
/*
f(n) = f(n - 1) + f(n - 2)
Applying the equation farther, substituting f(n - 1) = f(n - 2) + f(n - 3):
f(n) = 2 * f(n - 2) + f(n - 3)
Substituting f(n - 2) = f(n - 3) + f(n - 4):
f(n) = 3 * f(n - 3) + 2 * f(n - 4)
Substituting f(n - 3) = f(n - 4) + f(n - 5):
f(n) = 5 * f(n - 4) + 3 * f(n - 5)
It can be seen that the coefficients are Fibonacci numbers by themselves!
@aliakseis
aliakseis / gist:08a87d109b469189e04cafb160d07fd5
Last active July 29, 2018 07:19
Binary indexed tree usage example
#include <vector>
#include <iostream>
class Counter
{
enum { MaxVal = 256 };
public:
void update(int idx, int val) {
while (idx <= MaxVal) {
tree[idx] += val;
@aliakseis
aliakseis / gist:daa77ddca8593e2308f231cdb8be8f8a
Created July 28, 2018 16:07
Pre C++ 11 email address validation
#include <algorithm>
#include <iostream>
#include <fstream>
#include <functional>
#include <sstream>
#include <string>
#include <cctype>
#include <cstdio>
using std::cout;
@aliakseis
aliakseis / gist:96788b572646583d0153fc4ed06568f0
Created September 26, 2018 14:27
Turning off Vcpkg for Microsoft Visual Studio 2017 Community edition
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.props:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- add this stuff -->
<PropertyGroup Label="Globals">
<VcpkgEnabled>false</VcpkgEnabled>
</PropertyGroup>
</Project>
@aliakseis
aliakseis / gist:74d622be798090ff05e78bfc72deae01
Created September 29, 2018 15:44
ISharedProperty helper
#pragma once
#include <ComSvcs.h>
#include <atlbase.h>
#include <comdef.h>
#include <comutil.h>
//////////////////////////////////////////////////////////////////////////
class CComUsageScope
@aliakseis
aliakseis / gist:55c84c6e4d5352acc6bb0b513bf0bd63
Created November 23, 2018 15:13
applying function to tuple elements
#include <iostream>
#include <tuple>
#include <type_traits>
auto some_function = [](auto&& x) { std::cout << x << std::endl; };
template<class Tuple, size_t... Indices>
constexpr void Apply_impl(Tuple& tpl, std::index_sequence<Indices...>)
{
template<typename T, typename V>
auto TryToFind(T& collection, const V& value) -> decltype(&collection.end()->second)
{
auto it = collection.find(value);
return (it != collection.end()) ? &it->second : nullptr;
}
@aliakseis
aliakseis / gist:7ba39985d5be32a7087657bbb74086a2
Last active February 14, 2019 17:29
cmd script for building Poco libraries
@echo off
setlocal enableextensions
rem %1 is either x86 or x64, %2 is either Win32 or x64
set POCO_INSTALL_PREFIX=d:\Poco
set POCO_SOURCE_PATH=D:\workspace\poco-poco-1.9.0-release
set OPENSSL_ROOT_DIR=D:\workspace\stuff\External\openssl.%1
for /f "tokens=*" %%a in (