Skip to content

Instantly share code, notes, and snippets.

View vladiant's full-sized avatar
🏠
Working from home

Vladislav Antonov vladiant

🏠
Working from home
View GitHub Profile
@vladiant
vladiant / type_erasure.cpp
Last active May 1, 2023 16:01
C+ Type erasure
#include <iostream>
#include <memory>
#include <vector>
// Breaking Dependencies - C++ Type Erasure - The Implementation Details - Klaus Iglberger CppCon 2022
// https://www.youtube.com/watch?v=qn6OqefuH08
struct Circle {
public:
explicit Circle(double rad) : radius{rad} {}
@vladiant
vladiant / variant_performance.cpp
Created March 16, 2023 18:17
"Clean" Code, Horrible Performance and the forgotten variant
// https://www.reddit.com/r/cpp/comments/11rzncu/clean_code_horrible_performance_and_the_forgotten/
// https://quick-bench.com/q/mW30pqwTvtWZ-aT6COu1oiUycYc
#include <cmath>
#include <cstdlib>
#include <cstddef>
#include <ctime>
#include <memory>
#include <variant>
#include <vector>
@vladiant
vladiant / shared_mem_example.cpp
Created October 9, 2022 19:29
Processes or Threads?
// https://lucisqr.substack.com/p/processes-or-threads
// https://github.com/Vitorian/MyPasteBin/blob/master/shared_mem_example.cpp
#include <atomic>
#include <fcntl.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
#include <sys/mman.h>
@vladiant
vladiant / client.cpp
Created June 23, 2022 19:36
C++ TCP Examples
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <iostream>
using namespace std;
// Defining Port, Note that port is same on which server is listening and on
// which we want to connect
@vladiant
vladiant / CMakeLists.txt
Created June 14, 2022 17:25
StoreRLValue
cmake_minimum_required(VERSION 3.10)
project(StoreRLValue)
add_executable(
${PROJECT_NAME}
main.cpp
)
set_target_properties(
@vladiant
vladiant / finally1.cpp
Created June 14, 2022 17:22
C++ Finally
#include <functional>
#include <iostream>
// https://www.youtube.com/watch?v=eG5suWcHI8M
// Lightning Talk: FINALLY - The Presentation You've All Been Waiting For - Louis Thomas - CppCon 2021
class Finally {
public:
std::function<void()> m_action;
#include <iostream>
#include <vector>
template <class T, class U, class V>
struct Foo {
T bar;
std::vector<U> baz;
V foobar;
};
@vladiant
vladiant / get_gists.py
Created March 21, 2022 20:44 — forked from leoloobeek/get_gists.py
Download all gists for a specific user
# first: mkdir user && cd user && cp /path/to/get_gists.py .
# python3 get_gists.py user
import requests
import sys
from subprocess import call
user = sys.argv[1]
r = requests.get('https://api.github.com/users/{0}/gists'.format(user))
@vladiant
vladiant / cpp03.cpp
Created March 21, 2022 20:42
Evolving a Nice Trick - Patrice Roy - CppCon 2021
#include <cmath>
class exact {};
class floating {};
template <class T> bool close_enough(T a, T b, exact) {
return a == b;
}
template <class T> bool close_enough(T a, T b, floating) {
return std::abs(a - b) <= static_cast<T>(0.000001);
}
struct false_type { enum { value = false }; };
@vladiant
vladiant / downloader.py
Created March 13, 2022 12:17
imgbox.com gallery downloader
import urllib.request
import requests
from bs4 import BeautifulSoup
with open("images.txt", "r") as fp:
lines = fp.readlines()
for url in lines:
r = requests.get(url=url.strip())
print(f"URL: {url.strip()}")