Przejdź do głównej zawartości


Cleaning up #includes

Najnowsze posty

Tidy #includes

I propose that "good" includes should follow those rules:

Sending Firebase Messages from command line with curl

Google Firebase platform is set of services aimed at "cloudyfying" Android apps. One of those services is FCM, Firebase Cloud Messaging, and allows us to send short text or data messages to device or group of them.
Majority of tutorials show how to send this message from another Android device. This one will show how to send it from custom server, for simplicity using curl program. 
Steps needed:
Set up project in Firebase consoleCompile example app for this projectVerify sending works with web uiSend message using curl Set up project in Firebase consoleGo to Add projectEnter project name and click CreateOn the left menu select Grow / NotificationClick Android icon Enter package name. For this tutorial enter Register App, then Download google-services.json and save the fileFollow rest of instructions on website or in this tutorial Compile example appCheck out project firebase/quickstart-android

<chrono> introduction

This article will summarize presentation by Howard Hinnant which he gave during CppCon 2016. Howard gives comprehensive walk through c++11 chrono library.

TL;DR (Summary) C++11 introduced <chrono> library for handling time. Use it instead of <time.h> / <ctime> because it gives you better type safety and precision.
Library provides those concepts:
time points - moments in time (as in "noon, December 1st 2000", "2016-01-31 14:15:32")time durations - "length" (amount) of time that passes between two time points ("two hours", "2563 milliseconds")clocks - providers of time points (like wall clock, stopper) Query clock to get time points; calculate difference between two time points to get time duration. You can use time points/duration with <thread> library for sleep, wait_for/wait_until functions.
Use auto, because otherwise type names are quite verbose.
Time Durationstd::time_duration is a measure of how much time…

GDB - beyond basics


ctrl-f / ctrl-n are arrows left / right
shell psshell cat temporary_file.txtshell k…

C++11 random - introduction

#include <stdio.h>      /* printf, NULL */ #include <stdlib.h>     /* srand, rand */ #include <time.h>       /* time */ int main () { srand (time(NULL)); int num1 = rand()%10 + 1; int num2 = rand()%10 + 1; return 0; } Several things are wrong here:
It always gives uniform distribution (1 is as probable as 5). This is usually fine, but when not, you need a lot of additional work.Actually, it is not very uniform.If you want for some reason to reseed the generator (call srand(time(NULL)) again) shortly after first seeding, you may get repeated answersYou only get discreet numbers (integers)Random algorithm is not specified, so results are not portab…