diff --git a/content/blog/gitbundle.md b/content/blog/gitbundle.md new file mode 100644 index 0000000..cb19275 --- /dev/null +++ b/content/blog/gitbundle.md @@ -0,0 +1,33 @@ +--- +title: "Git Bundle" +date: 2020-03-20T16:22:01-04:00 +draft: false +tags: ["Git"] +--- + +If you have a large software repository, sometimes you only want to share part of it with a group. You can accomplish this by using `git bundle` + +## Creating the Bundle + +To bundle all the commits from the development branch to the current head, + +```bash +git bundle create repo.bundle development..HEAD feature_branch +``` + +This will place these commits into a branch called `feature_branch` in `repo.bundle`. + +## Fetching from bundle + +On the other side, we need to make sure that we have all the commits up to the `development` branch synchronized. Then we can fetch the commits from the bundle: + +```bash +git fetch /path/to/repo.bundle feature_branch:feature_branch +``` + +The left side of the colon is what you want to grab from the bundle, the right side is the branch to put the commits to. + +```bash +git checkout feature_branch +``` + diff --git a/content/blog/gitpatch.md b/content/blog/gitpatch.md new file mode 100644 index 0000000..eed9382 --- /dev/null +++ b/content/blog/gitpatch.md @@ -0,0 +1,27 @@ +--- +title: "Git Patch" +date: 2020-03-20T16:22:57-04:00 +draft: false +tags: ["Git"] +--- + +The Linux kernel community make use of patches in git to share code changes with one another. Patches are only nicely formatted differences between your current codebase and what you compare it to. If you want to share a subsetted git tree, then [git bundle](/blog/gitbundle) would be the way to go. + +## Creating the patch + +If you want to create a patch based off the difference between your current branch and master, run the following: + +```bash +git format-patch master --stdout > feature_branch.patch +``` + +You can then email the patch to the team. + +## Applying the patch + +To apply go into a new branch and apply the patch file. + +```bash +git checkout -b feature_branch +git apply /path/to/feature_branch.patch +``` \ No newline at end of file diff --git a/content/blog/qtcpsocket.md b/content/blog/qtcpsocket.md new file mode 100644 index 0000000..dff06a0 --- /dev/null +++ b/content/blog/qtcpsocket.md @@ -0,0 +1,66 @@ +--- +title: "QTcpSocket" +date: 2020-03-20T16:21:07-04:00 +draft: false +tags: ["C++", "Qt"] +--- + +There are two ways that I can think of for checking if a TCP socket times out in Qt. You can either use `waitForConnected` or a `QTimer`. The Qt 5.14 documentation noted that the `waitForConnected` call may randomly fail in Windows. + +Here is some shared code for both examples + +```c++ +QTcpSocket *socket = new QTcpSocket(this); +quint16 listenPort = 4444; +int timeout = 1000; // Units: milliseconds +QHostAddress destination("192.168.0.2"); +``` + + + +## `waitForDisconnected` + +Let's say that we have a `QTcpScoket` pointer named `socket`. + +```c++ +socket->connectToHost(destination, listenPort); +if (!socket->waitForConnected(timeout)) { + qDebug("Connection Timed Out."); +} +``` + +Notes: + +- `waitForConnected` is a blocking call +- This does not account for the host lookup call. + +## `QTimer` + +This method requires a little more setup. Let's assume we have a class named `Test` that inherits `QObject`. + +```c++ +// .... +socket->connectToHost(destination, listenPort); +timeoutTimer = new QTimer(this); +timeoutTimer->setInterval(timeout); +timeoutTimer->setSingleShot(true); +connect(timeoutTimer, &QTimer::timeout, this, &Test::timeout); +timeoutTimer->start(); +// .... + +void Test::timeout(void) { + qDebug("Connected Timed Out."); + socket->disconnectFromHost(); +} +``` + +Notes: + +- This method acts asynchronously + +In order for the the timeout function to not always hit, we need to make sure we stop the timer when data is received or a TCP error occurs + +```c++ +timeoutTimer->stop(); +``` +