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 / _docker_wrapper
Last active December 23, 2017 16:47
wrapper for running commands in docker containers
#!/bin/bash
# usage: _docker_wrapper [--root] image command
user="--user=${UID}"
if [[ "$1" == "--root" ]]; then
user="--user=root"
shift
fi
@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 / 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
@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,
#!/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
@etam
etam / fix_perms
Last active August 2, 2016 10:32
#!/bin/bash
(($# == 0)) \
&& set "."
find "$@" -type d -exec chmod 755 {} +
find "$@" -type f -exec chmod 644 {} +