Skip to content

Instantly share code, notes, and snippets.

View daniel-j-h's full-sized avatar
🤗

Daniel J. H. daniel-j-h

🤗
View GitHub Profile
@daniel-j-h
daniel-j-h / notes.md
Last active August 29, 2015 14:04
ceph/ceph @27f6dbb: mapping all objects to a single pg

Forcing Ceph into mapping all objects to a single PG

Motivation

Recently I was wondering how Ceph (i.e. Rados in particular) maps object to Placement Groups (PGs).

It basically works like the following:

pg = hash(object)

osd = crush(pg)

@daniel-j-h
daniel-j-h / insert_preimages.py
Created July 30, 2014 13:00
Preimage Attack on RADOS
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# I used this in order to insert the preimages into a local ceph cluster,
# started in my ceph dev directory via src/vstart.sh. Adapt paths if needed.
import sys, os
srcdir = '/home/daniel/cn-work/ceph-dev/src'
pool = 'collisions'
@daniel-j-h
daniel-j-h / check_distribution.py
Last active August 29, 2015 14:04
Ceph: assert uniform object to placement group distribution using a Chi-Squared Hypothesis Test
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys, json
from collections import defaultdict
from scipy.stats import chisquare
# usage: ceph pg dump_json | ./check_distribution.py
if __name__ == '__main__':
@daniel-j-h
daniel-j-h / thread_guard.hpp
Created August 5, 2014 17:37
Thread Guards: The first one takes ownership over the thread, the second one only ensures exception-safe join.
#include <thread>
#include <utility>
#include <stdexcept>
// takes ownership of the thread
class scoped_thread {
public:
explicit scoped_thread(std::thread t_) : t(std::move(t_)) {
if(!t.joinable()) throw std::logic_error{"no thread"};
@daniel-j-h
daniel-j-h / spinlock.hpp
Created August 5, 2014 17:55
Spinlock: It spins and locks!
#include <atomic>
class spinlock_mutex {
public:
spinlock_mutex() : flag(ATOMIC_FLAG_INIT) {}
void lock() { while(flag.test_and_set(std::memory_order_acquire)); }
void unlock() { flag.clear(std::memory_order_release); }
private:
@daniel-j-h
daniel-j-h / adapter.cc
Last active January 4, 2017 14:42
Adapter Pattern for templated base class using private inheritance
// Suppose we have a templated framework and we want to adapt its interface -> use the adapter pattern.
// Our templated framework with awkward get_t and set_t member functions:
template <typename T>
class Framework {
public:
Framework(T t = {}) : t_{std::move(t)} { }
T get_t() const { return t_; }
@daniel-j-h
daniel-j-h / core.hy
Last active August 29, 2015 14:12
Hy: python+clojure (see: hylang.org)
#!/usr/bin/env hy
(import [operator [eq]]
[itertools [chain count]]
[functools [partial reduce]])
(defn map-indexed [f coll]
(map f (count) coll))
@daniel-j-h
daniel-j-h / ksit-2015-2-11.md
Last active August 29, 2015 14:14
Geospatial Analysis, KSIT workshop on 2015-2-11
@daniel-j-h
daniel-j-h / CompileTimeType.cc
Last active August 29, 2015 14:17
CompileTimeType: force compiler to show you inferred types
// See: EMC++, Item 4
template<typename>
class CompileTimeType;
int main() {
int x;
CompileTimeType<decltype(x)> x_Type;
@daniel-j-h
daniel-j-h / SimpleRecord.cc
Last active August 29, 2015 14:17
SimpleRecord: unscoped enum tuple accessor trick
#include <iostream>
#include <string>
#include <tuple>
// See: EMC++, Item 10
namespace {
using Person = std::tuple<std::string, std::string, int>;
enum { FirstName, LastName, Age };
}