Skip to content

Instantly share code, notes, and snippets.

Avatar

Georg Sauthoff gsauthof

View GitHub Profile
@gsauthof
gsauthof / xclipshow.cpp
Created Jan 27, 2016
Simplified, shortened version of http://unix.stackexchange.com/a/163115/1131, a clipboard dump tool
View xclipshow.cpp
// source: http://unix.stackexchange.com/a/163115/1131
// GS, 2016-01-27, simplify the code a little bit
#include <QApplication>
#include <QTimer>
#include <QClipboard>
#include <QMimeData>
#include <QDebug>
#include <string>
#include <iostream>
@gsauthof
gsauthof / addressoffn.cc
Last active Jul 2, 2016
Address of function example
View addressoffn.cc
/*
Illustrate how the & operator can be omitted when getting a function pointer.
In reply to: https://www.youtube.com/watch?v=z-kUhwANrIw
2016, Georg Sauthoff
*/
@gsauthof
gsauthof / fib.c
Created Jul 25, 2016
Syntactic variation of a Fibonacci example
View fib.c
// in reply to http://verse.systems/blog/post/2016-07-18-Software-Engineering-Teaching/
unsigned fibonacci(unsigned n) {
unsigned a = 0, b = 1;
unsigned sum = 0;
for ( ; n > 0; --n) {
unsigned t = b;
b += a;
a = t;
sum += a;
View sig_overlay.tex
% curl -L -o signature.png \
% 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/Beethoven_Signature.svg/150px-Beethoven_Signature.svg.png'
% compile twice: pdflatex sig_overlay.tex
\documentclass{article}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=150mm,yshift=-80mm]
@gsauthof
gsauthof / boost_hex.cc
Last active Oct 3, 2016
comparison of boost hex algorithm and printf conversion specifier
View boost_hex.cc
// re: http://stackoverflow.com/questions/28489153/how-to-portably-compute-a-sha1-hash-in-c/39833022#39833022
#include <boost/uuid/sha1.hpp>
#include <boost/detail/endian.hpp>
#include <boost/algorithm/hex.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <boost/endian/conversion.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
@gsauthof
gsauthof / orphan.c
Created Nov 27, 2016
Illustrating how orphaned children aren't necessarily adopted 2 by PID 1
View orphan.c
/* For illustrating how orphaned children aren't necessarily adopted
by PID 1.
See also: http://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits/36945270#36945270
2016, Georg Sauthoff <mail@georg.so>
*/
#include <unistd.h>
@gsauthof
gsauthof / feedgen_bench.py
Last active Feb 12, 2017
Costs of ordered attributes in generated feeds
View feedgen_bench.py
# in reply to: https://groups.google.com/d/msg/django-developers/6mm42rrQXww/Yee5KJjVBQAJ
# (pull request: write feeds with ordered attributes)
# cf. https://github.com/django/django/pull/8044
#
# Results:
# - generating one feed: ~ 0.01 s (current Laptop, i7, SSD)
# - sorting + OrderedDict() in SimpleXMLGenerator::startElement(): + ~ 27 %
# - sorting + OrderedDict() iff there are attributes: + ~ 18 %
# - replacing {} with [] for attributes in feedgenerator: + ~ 7 %
@gsauthof
gsauthof / last_lines.py
Created Oct 31, 2017
asyncssh compatible file-like object for capturing the most recent lines
View last_lines.py
class Last_Lines:
def __init__(self, n, binary=True):
self.n = n
self.binary = binary
self.lines = []
# asyncssh calls fstat() on fileno() and checks if it is a regular file
# thus we open any regular file to fake it ...
self.dev_null = open('/etc/resolv.conf')
def write(self, s):
lines = s.splitlines(True)
View vfork.c
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int pid = vfork();
if (pid == 0) {
_exit(0);
}
@gsauthof
gsauthof / redact_env.c
Created Jul 27, 2019
Redact environment variable under Linux
View redact_env.c
/* Demonstrate how to overwrite the original value of
an environment variable in the original environment vector
that is easily observable from other processes
(with sufficient permissions, i.e. same user or root).
*/
/** {{{ MIT No Attribution
Copyright 2019 Georg Sauthoff <mail@georg.so>