Skip to content

Instantly share code, notes, and snippets.

View geneotech's full-sized avatar

Patryk Czachurski geneotech

View GitHub Profile
return {
default_server_start = {
port = 8412
},
server = {
server_name = "Algomieszkanko",
allow_nat_traversal = false
},
http_client = {
update_on_launch = false
import paho.mqtt.client as mqtt
import threading
ADDR="192.168.2.128"
TOPIC_NAME="BMS/P11"
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
print(client.subscribe(TOPIC_NAME))
import paho.mqtt.client as mqtt
import threading
ADDR="test.mosquitto.org"
TOPIC_NAME="flow_temp_pres"
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
print(client.subscribe(TOPIC_NAME))
To pokazuje jak se można odstrzelić całą nogę w tym języku.
Miałem takiego buga, że jak do jednego pliku,
nazwijmy go crash.cpp - nie wrzuciłem jednego includa - to miałem crasha w serializacja.cpp.
Co ciekawe, funkcje z crash.cpp w ogóle nie były wykorzystywane podczas testowania.
Więc mam se w kodzie takie generalne templatki do serializacji, write_bytes oraz read_bytes,
które z dowolnego obiektu robią ci wektor bajtów i vice versa,
ale możesz dla swojego złożonego typu zdefiniować w global scopie własne funkcje 
zwane write_object_bytes/read_object_bytes.
mkdir .deps ; cd .deps
cmake -DCMAKE_BUILD_TYPE=Release ../third-party -G Ninja
ninja
export CFLAGS='-O3 -flto -fuse-ld=lld'
export CXXFLAGS='-O3 -flto -fwhole-program-vtables -fuse-ld=lld'
export LDFLAGS='-flto -fwhole-program-vtables -fuse-ld=lld'
../
mkdir build ; cd build
cmake -DCMAKE_BUILD_TYPE=Release .. -G Ninja
ninja
#include <type_traits>
#include <iostream>
template <class A, class = void>
struct has_member : std::false_type {};
template <class A>
struct has_member<A, decltype(A::member, void())> : std::true_type {};
struct AA { static constexpr bool member = true; };
@geneotech
geneotech / thread_templates.h
Last active September 15, 2017 20:42
Thread templates
#pragma once
#include <future>
#include <optional>
template <class T>
bool is_ready(const std::future<T>& f) {
return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
}
template <class T>
@geneotech
geneotech / menu.cpp
Last active September 15, 2017 20:06
future considerations
// UPDATE: So, I've implemented a packaged_future template which makes it possible to use just a single variable:
// https://gist.github.com/geneotech/c9e8177b34dbace6b1fa23129977c9d1
// Original problem:
// UPDATE: Okay, so apparently, std::shared_future can get multiple times...
// But should I use std::shared_future even though just one thread queries it for value?
// Consider a main menu class which, on construction,
// is supposed to query a website for a news headline in order
struct A { int v; };
struct B { int v; };
struct C { int v; };
struct Ar { int& v; };
struct Br { int& v; };
struct Cr { int& v; };
void add_ref(A& a, B& b, C& c) {
a.v += c.v;
b.v += c.v;
@geneotech
geneotech / constexpr_if.cpp
Created May 24, 2017 19:02
Constexpr if for compilers without support of... constexpr if.
#include <type_traits>
#include <iostream>
using namespace std;
template <bool>
struct constexpr_if;
template <>
struct constexpr_if<true> {
struct elser {