View xclipshow.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
View addressoffn.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
*/ |
View fib.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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] |
View boost_hex.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
View orphan.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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> |
View feedgen_bench.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 % |
View last_lines.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int pid = vfork(); | |
if (pid == 0) { | |
_exit(0); | |
} |
View redact_env.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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> |
OlderNewer