Skip to content

Instantly share code, notes, and snippets.

View jpret's full-sized avatar

Jan Gabriel Pretorius jpret

View GitHub Profile
@jpret
jpret / main.cpp
Created November 11, 2021 15:52
Testing threads in c++
#include <chrono>
#include <iostream>
#include <memory>
#include <thread>
#include <vector>
// remember to add -pthread to the compile options.
// Run example: https://godbolt.org/z/Efnzxq9a1
int main() {
@jpret
jpret / package.sh
Last active November 8, 2021 14:29
Use jpackage to create an installer for Java application (which uses Maven)
# Java Package Example (jpex) project directory
# jpackage_example
# + src
# + main
# + java
# Main (This is the main class file for this example)
# + test
# // After a mvn package the target folder is available
# + target
# pom.xml
@jpret
jpret / main.cpp
Created September 2, 2021 08:15
Docker C++ Example
#include <iostream>
int main (int argc, char *argv[]) {
std::cout << "Hello World\n" << std::endl;
return EXIT_SUCCESS;
}
@jpret
jpret / swagger-spec.yaml
Created August 30, 2021 13:07
Swagger - XML Element with Attributes + Content Example
swagger: "2.0"
info:
description: "XML Element with Attributes + Content Example"
title: "Example"
version: "42"
paths:
/foo:
get:
tags:
- "foo"
@jpret
jpret / Remote Host Identification Fix.md
Last active August 11, 2021 08:44
Remote Host Identification Fix

Remote Host Identification Fix

Example warning when a remote ssh server's identification has changed:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
@jpret
jpret / main.cpp
Last active July 2, 2021 13:15
Finding duplicate values in std::map at compile time - alternative using std::array
#include <array>
#include <cassert>
#include <cstdlib>
template<typename A, typename B>
constexpr bool compare_equal(A a, B b) {
return a == b;
}
@jpret
jpret / CMakeLists.txt
Last active June 28, 2021 09:11
Create static member in case of several shared libraries
cmake_minimum_required(VERSION 2.8)
project(foo)
# Change the default to hidden, then you need to explicitly set it
# Thus, normally, you shouldn't have the problem
add_compile_options(-fvisibility=hidden) # only for testing the EXPORT define
# Create the shared library
add_library(mylib SHARED mylib.cpp)
@jpret
jpret / gist:fa2e0925180060cc013c2ddeca946fef
Created June 21, 2021 11:21
Fix Git LFS smudge error commands
# Fixing the git lfs smudge filter error
# when cloning
GIT_SSL_NO_VERIFY=true git clone ssh://some_repo.git
# Also set the config
git config http.sslVerify false
@jpret
jpret / CMakeLists.txt
Created June 7, 2021 09:30
Constexpr string literals in anonymous namespace -> fix
cmake_minimum_required(VERSION 3.17)
project(foo)
set(CMAKE_CXX_STANDARD 11)
add_executable(example main.cpp bar.cpp)
/* Build output:
[ 66%] Building CXX object CMakeFiles/example.dir/main.cpp.o
@jpret
jpret / main.cpp
Created April 13, 2021 08:36
Observer design pattern example in C++
#include <iostream>
#include <memory>
#include <vector>
#include <set>
// Observer from Observer design pattern
template<typename T>
class Observer {
public:
virtual void Notification(const T &event) = 0;