Skip to content

Instantly share code, notes, and snippets.

View HappyCerberus's full-sized avatar
📘
Moar books...

RNDr. Simon Toth HappyCerberus

📘
Moar books...
View GitHub Profile
@HappyCerberus
HappyCerberus / main_task.cc
Created November 30, 2021 09:05
[Article] C++20 Practical Coroutines - main_task
struct main_task {
struct main_promise {
using handle_t = std::coroutine_handle<main_promise>;
main_task get_return_object() {
return main_task{handle_t::from_promise(*this)};
}
std::suspend_never initial_suspend() noexcept { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void unhandled_exception() { std::terminate(); }
void return_value(int ret) { ret_ = ret; }
==================
WARNING: ThreadSanitizer: data race (pid=9616)
Read of size 8 at 0x556bf9a5ab58 by thread T4:
#0 git_pool__system_page_size external/libgit2/src/pool.c:28 (demo+0x6a932)
#1 git_pool_init external/libgit2/src/pool.c:47 (demo+0x6aa4f)
#2 git_sortedcache_new external/libgit2/src/sortedcache.c:28 (demo+0x98769)
#3 git_refdb_backend_fs external/libgit2/src/refdb_fs.c:2152 (demo+0x754b2)
#4 git_refdb_open external/libgit2/src/refdb.c:49 (demo+0x6d201)
#5 git_repository_refdb__weakptr external/libgit2/src/repository.c:1152 (demo+0x9252e)
#6 git_reference_lookup_resolved external/libgit2/src/refs.c:237 (demo+0x7bf5e)
# googleapis
http_archive(
name = "com_google_googleapis",
sha256 = "0744d1a1834ab350126b12ebe2b4bb1c8feb5883bd1ba0a6e876cb741d569994",
strip_prefix = "googleapis-bcc476396e799806d3355e87246c6becf6250a70",
urls = ["https://github.com/googleapis/googleapis/archive/bcc476396e799806d3355e87246c6becf6250a70.tar.gz"],
)
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
#include <cmath>
#include <iostream>
using namespace std;
template <int value> struct Test { int test() { return value; } };
template <> struct Test<0> { int test() { return 0; } };
int main()
{
Test<static_cast<int>(floor(0.5))> a;
@HappyCerberus
HappyCerberus / FastLineReader.cpp
Created March 31, 2015 11:53
Fast line-by-line file parser
#include "FastLineReader.h"
// POSIX
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
@HappyCerberus
HappyCerberus / static.cpp
Created November 6, 2012 15:10
Flat inheritance
#include <iostream>
using namespace std;
struct A
{
int p_value;
void print() { cout << "Value = \"" << p_value << "\"." << endl; }
};
template < typename T >
simon@lenovo:~/repos/teaching/examples/PB161> ./a.out
dry run 499994165
Accumulate runtime 28169000 - 499994165
Manual sum runtime 44949000 - 499994165
simon@lenovo:~/repos/teaching/examples/PB161> ./a.out
dry run 499996968
Accumulate runtime 32467000 - 499996968
Manual sum runtime 44659000 - 499996968
simon@lenovo:~/repos/teaching/examples/PB161> ./a.out
dry run 500024233
@HappyCerberus
HappyCerberus / main.cpp
Created October 23, 2012 16:51
BMP image format writing helper
#include <vector>
#include <cstdint>
#include <iostream>
using namespace std;
class BitmapWriter
{
public:
struct RGB { unsigned char red; unsigned char green; unsigned char blue;
@HappyCerberus
HappyCerberus / main.cpp
Created October 22, 2012 01:11
Tree data structure - first part of implementation
#include "node.h"
#include "nodeiter.h"
#include <iostream>
#include <memory>
#include <list>
using namespace std;
int main()
{
g++ -std=c++11 -pedantic -Wall -Wextra -ggdb3 -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD -lpthread main.cpp node.cpp