Skip to content

Instantly share code, notes, and snippets.

#include "overload.hpp"
#include <iostream>
#include <string>
#include <variant>
int main() {
using namespace cmuoh;
std::variant<int, float, std::string> intFloatString { "Hello" };
std::visit(overload {
#ifndef CMUOH_MAKE_VECTOR_HPP_
#define CMUOH_MAKE_VECTOR_HPP_
#include "make_vector_details.hpp"
namespace cmuoh {
template <typename T = void, typename... Args,
typename V = detail::vec_type_helper_t<T, Args...>,
typename std::enable_if<
@outro56
outro56 / pimpl.hpp
Last active September 15, 2020 21:23
Compilation firewalls: pimpl + fast_pimpl
#ifndef CMUOH_PIMPL_HPP
#define CMUOH_PIMPL_HPP
#include <memory>
#include <cstddef>
// See also: https://herbsutter.com/gotw/_100/
// NOTES:
// - put all private nonvirtual members (data + functions) into T impl
// - when using an impl in a class, all constructors (default/copy/move) and
@outro56
outro56 / dockerx.zsh
Created August 25, 2020 01:55
run docker contains with default arguments
dockerx() {
if [ "$#" -eq "0" ]; then
echo "Usage: dockerx IMAGE [OPTIONS]"
return 1
else
img=$1
shift
# remove invalid characters from the container name
name=`echo "$img" | tr /:?\ @ _`
template<typename T, typename U>
using assign_expression = decltype(std::declval<T&>() = std::declval<U&>());
template<typename T, typename U>
constexpr bool is_assignable = is_detected<assign_expression, T, U>;
@outro56
outro56 / version1.lua
Last active August 3, 2018 04:12 — forked from randrews/hoc4.lua
Toy calculator in Lua, version 4 - http://www.playwithlua.com/?p=73#more-73
function eval(num1, operator, num2)
if operator == '+' then
return num1 + num2
elseif operator == '-' then
return num1 - num2
elseif operator == '*' then
return num1 * num2
elseif operator == '/' then
return num1 / num2
else
local function clone_function(fn)
local dumped = string.dump(fn)
local cloned = loadstring(dumped)
local i = 1
while true do
local name = debug.getupvalue(fn, i)
if not name then
break
end
debug.upvaluejoin(cloned, i, fn, i)
@outro56
outro56 / gist:3c111f72dd26c27ced47862c86e3cf65
Created August 5, 2016 15:47
Kill all docker containers
stop all containers:
docker kill $(docker ps -q)
remove all containers
docker rm $(docker ps -a -q)
remove all docker images
docker rmi $(docker images -q)
@outro56
outro56 / MemoryMapppedIOExtensions.cs
Created January 22, 2016 23:02
quickly read bytes from a memory mapped file
// Copied from
// http://stackoverflow.com/questions/7956167/how-can-i-quickly-read-bytes-from-a-memory-mapped-file-in-net
public static MemoryMapppedIOExtensions
{
public unsafe byte[] ReadBytesFast(this MemoryMappedViewAccessor view, int offset, int num)
{
try
{
byte[] arr = new byte[num];
@outro56
outro56 / gist:dc35f057fe8c2643e378
Created November 25, 2015 03:19
Bittwiddling hacks
1. Check if a number is even or odd
An integer number N is even if its least significant bit is 0 otherwise it is odd
N AND 1
2. Divide by 2
Given an integer number N you can divide it by 2 by shifting all the bits to the right with one position.
N >> 1