This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /:?\ @ _` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |