Skip to content

Instantly share code, notes, and snippets.

Jōshin Steven Dee mrdomino

Block or report user

Report or block mrdomino

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mrdomino
mrdomino / lexical_cast.hpp
Created Aug 4, 2015
sstream-driven lexical cast
View lexical_cast.hpp
#pragma once
#include <sstream>
#include <string>
namespace detail {
template <typename T, typename U>
class LexicalCast {
public:
T operator()(U const& u) {
View exec-self.c
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char slash[] = "/";
int main(__attribute__((unused)) int argc, char* argv[]) {
char *self;
View make_unique_lock.h
#pragma once
#include <mutex>
#include <type_traits>
template <typename Mutex, typename... Args>
auto make_unique_lock(Mutex&& m, Args&&... args)
-> std::unique_lock<typename std::remove_reference<Mutex>::type> {
return std::unique_lock<typename std::remove_reference<Mutex>::type>(
std::forward<Mutex>(m), std::forward<Args>(args)...);
View hold-example.c++
#include "hold.h"
#include <cstdio>
#include <memory>
int main() {
Hold<std::shared_ptr<int>> hold;
std::weak_ptr<int> weak;
{
auto x = std::make_shared<int>(5);
View task_queue.c++
#include <cassert>
#include <future>
#include <list>
#include <queue>
#include <thread>
#include <vector>
class State {
public:
State(): started(false), pending_get_values(false), exiting(false) {}
@mrdomino
mrdomino / stkintro.c
Last active Jun 21, 2016
compile with -lsigsegv
View stkintro.c
#include <inttypes.h>
#include <setjmp.h>
#include <signal.h>
#include <sigsegv.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct bond {
uintptr_t dof;
View c++.c++
#include <cstdio>
#include <future>
#include <map>
#include <memory>
#include <string>
void do_thing(std::string a); // forces a copy
void do_thing_ref(std::string& a); // no copy, can mutate a
void do_thing_ptr(std::string* a); // no copy, can obviously mutate a
View jrp.c++
#include <cstdlib>
#include <atomic>
#include <exception>
#include <iostream>
#include <memory>
#include <mutex>
#include <utility>
class JrpException : public ::std::exception {};
View resetter.h
#include <utility>
template <typename T, typename U = T>
class ScopedRestore {
public:
explicit ScopedRestore(T* it):
ref_(*it), old_val_(*it) {}
~ScopedRestore() noexcept(noexcept(this->ref_ = std::move(this->old_val_))) {
using std::move;
ref_ = move(old_val_);
View elias_unary.c
#include <hammer/glue.h>
#include <hammer/hammer.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
HParser* parser;
HBenchmarkResults* results;
You can’t perform that action at this time.