Skip to content

Instantly share code, notes, and snippets.

View tsaarni's full-sized avatar

Tero Saarni tsaarni

  • Ericsson
  • Finland
  • 04:18 (UTC +03:00)
View GitHub Profile
@tsaarni
tsaarni / strapdown.cgi
Last active August 29, 2017 19:41
Configure Apache to render markdown files automatically
#!/bin/bash
#
# To make apache render files ending with .md with strapdown.js
# markdown renderer (http://strapdownjs.com/), add following lines
# to /etc/apache2/httpd.conf:
#
# Action markdown /cgi-bin/strapdown.cgi
# AddHandler markdown .md
# DirectoryIndex index.html index.md
#
@tsaarni
tsaarni / stack-backtrace.cpp
Last active August 20, 2023 23:33
How to print stack backtrace in gcc
/*
## Compile
g++ -Wall -std=c++11 -rdynamic -g stack-backtrace.cpp -lbacktrace -o stack-backtrace && ./stack-backtrace
clang++ -Wall -std=c++11 -rdynamic -g stack-backtrace.cpp -lbacktrace -o stack-backtrace && ./stack-backtrace
## Output
Backtrace:
@tsaarni
tsaarni / bug-infinite-recursion-accidental-automatic-typecast.cpp
Last active August 29, 2015 14:24
Unintentional typecast that causes infinite recursive loop
// clang++ -Wall -std=c++11 -O0 -o test test.cpp && ./test
// g++ -Wall -std=c++11 -O0 -o test test.cpp && ./test
#include <iostream>
#include <vector>
#include <cstdio>
namespace Ns
{
@tsaarni
tsaarni / 00-elk-stack-sshd-log-analysis.md
Last active July 5, 2018 14:04
Using ELK stack (Elasticsearch + Logstash + Kibana) for offline SSHD log analysis

Using ELK stack for offline SSHD log analysis

To start Elasticsearch + Logstash + Kibana execute:

docker-compose up

The container images will be downloaded from docker hub at first run.

Next, import the log file data to logstash

// clang++ -Wall -std=c++11 -O0 -o scope-exit scope-exit.cpp && ./scope-exit
// g++ -Wall -std=c++11 -O0 -o scope-exit scope-exit.cpp && ./scope-exit
#include <iostream>
template <typename F>
struct ScopeExit
{
ScopeExit(F f) : f(f) {}
~ScopeExit() { f(); }
#include <boost/exception/diagnostic_information.hpp>
struct MyException : virtual boost::exception, virtual std::exception
{
virtual const char* what() const throw() { return boost::diagnostic_information_what(*this); }
};
@tsaarni
tsaarni / 00-asio-handler-member-function.md
Last active August 13, 2021 17:39
boost::asio with handler callback as member function, guarded by weak_ptr

Using member function as boost::asio handler

This example demonstrates how to implement boost::asio handler callback as a member functions in a safe way, even while the ASIO timer or socket object is itself also contained in the same object.

Problem

When deleting the object containing both the handler method and ASIO

@tsaarni
tsaarni / 00-PROFANITY-IN-DOCKER-README.md
Last active April 26, 2016 12:02
Run profanity inside docker

Profanity inside Docker container

Building the container image

Clone this repository:

git clone https://gist.github.com/0c6f5f31f874d39e0860c48fd4b575e8.git docker-profanity
cd docker-profanity

and then run following command to build the image:

@tsaarni
tsaarni / openssl-notes.txt
Created October 22, 2016 08:50
Generate self-signed certs with different key types
*** RSA
# Generate self-signed certificate with RSA 4096 key-pair
openssl req -x509 -nodes -days 3650 -newkey rsa:4096 -keyout rsakey.pem -out rsacert.pem
# print private and public key
openssl rsa -in rsakey.pem -text -noout
# print certificate
openssl x509 -in rsacert.pem -text -noout