This file contains hidden or 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
/* futex_demo.c | |
Usage: futex_demo [nloops] | |
(Default: 5) | |
Demonstrate the use of futexes in a program where parent and child | |
use a pair of futexes located inside a shared anonymous mapping to | |
synchronize access to a shared resource: the terminal. The two | |
processes each write 'num-loops' messages to the terminal and employ | |
a synchronization protocol that ensures that they alternate in |
This file contains hidden or 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 <[email protected]> |
This file contains hidden or 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); | |
} |
This file contains hidden or 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) |
This file contains hidden or 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 % |
This file contains hidden or 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 <[email protected]> | |
*/ | |
#include <unistd.h> |
This file contains hidden or 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; |
This file contains hidden or 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] |
This file contains hidden or 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; |
This file contains hidden or 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 | |
*/ |