Skip to content

Instantly share code, notes, and snippets.

View etam's full-sized avatar

Adam Mizerski etam

View GitHub Profile
@etam
etam / monitor.cpp
Last active August 29, 2015 13:56
C++14 monitor class with multiple readers, single writers access control
/*
Based on Herb Sutter's monitor implementation presented on
https://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Herb-Sutter-Concurrency-and-Parallelism at 40:30,
which is, I hope, public domain.
*/
#include <utility>
#include <shared_mutex>
@etam
etam / baseless_polymorphism.cpp
Created May 17, 2014 11:10
baseless polymorphism in C++11
// http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
#include <iostream>
#include <memory>
#include <string>
#include <vector>
// ===== library ====
class Document
@etam
etam / make_unique_as.cpp
Created September 1, 2015 08:32
Make unique with cast
#include <iostream>
#include <memory>
#include <type_traits>
class Base
{
public:
virtual void foo() const = 0;
};
@etam
etam / optionalToVector.cpp
Last active November 6, 2015 13:54
functional style stdex::optional to std::vector conversion
#include <experimental/optional>
#include <experimental/type_traits>
#include <type_traits>
#include <utility>
#include <vector>
namespace stdex = std::experimental;
template <
typename Optional,
@etam
etam / abspath
Last active March 30, 2016 07:58
relpath
#!/usr/bin/env python3
import argparse
import os.path
import sys
def parse_args(argv):
parser = argparse.ArgumentParser()
parser.add_argument('path')
@etam
etam / btrfs-resolve-hardlinks
Last active March 30, 2016 08:09
btrfs resolve hardlinks
#!/bin/bash
while (( $# > 0 )); do
objcopy --only-keep-debug "$1" "${1}.debug"
strip -g "$1"
objcopy --add-gnu-debuglink="${1}.debug" "$1"
shift
done
#!/bin/bash
if (( $# != 1 )); then
echo "Usage: $(basename "$0") /tmp/path/to/socket"
exit 1
fi
if [[ ! -S "$1" ]]; then
echo "$1 is not a socket"
exit 2
#!/bin/bash
die() {
echo "$1" >&2
exit 1
}
(( $# > 1 )) \
&& die "too many arguments"
#!/bin/sh
docker images -q --filter dangling=true | xargs -r docker rmi