Skip to content

Instantly share code, notes, and snippets.

View make_vector.hpp
// make_vector.hpp
//
// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
// Distributed under the Boost Software License, Version 1.0. (See
// http://www.boost.org/LICENSE_1_0.txt)
#include <type_traits>
#include <vector>
namespace tcb {
View is_assignable.hpp
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 Aug 3, 2018 — forked from randrews/hoc4.lua
Toy calculator in Lua, version 4 - http://www.playwithlua.com/?p=73#more-73
View version1.lua
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
View overload.hpp
template <class ...Fs>
struct overload : Fs... {
template <class ...Ts>
overload(Ts&& ...ts) : Fs{std::forward<Ts>(ts)}...
{}
using Fs::operator()...;
};
template <class ...Ts>
@outro56
outro56 / call-graph.awk
Created Jun 21, 2018
Parse lua code and print call graph
View call-graph.awk
#!/usr/bin/awk -f
#
# call_graph.awk
#
# Usage:
# ./call_graph.awk my_program.lua | dot -Tpng > call_graph.png
#
# This is a script that generates a visual call graph for a Lua file.
# This script only shows calls made to functions defined within the
# input Lua file; that is, it excludes calls such as standard library
@outro56
outro56 / simple makefile.md
Last active Oct 16, 2017
Simple C++ Makefile
View simple makefile.md

Notes on the Makefile

  • The TODO at the top reminds me that I am using a different version of a library in development and it must be removed before deployment.
  • The TARGET is the main executable of the project, in this case bin/runner. Type make and this is what gets built.
  • I’m using g++ because it’s the same on Mac OS X and on the production Linux boxes.
  • If I uncomment the clang line, I get a failed link as the libraries are incompatible (or comment out the last line under $(TARGET):). But then I get the benefit of a clang static analyzer run help me make my code better, well worth it.
  • I use the fewest number of compiler CFLAGS when developing as possible, optimization happens later.
  • The SOURCES list is dynamic, I don’t want to manually have to maintain this list as I program. Anything in the src folder will be included in the compile as long as it has a SRCEXT extension.
  • The OBJECTS list is also dynamic and uses a Makefile trick to build the list based on available sources.
  • The LIB in this
View gist:31e588e5622dcf7931de0aee49baa7b2
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lol "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
View function-clone.lua
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)
View gist:3c111f72dd26c27ced47862c86e3cf65
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 / ObjectHandle.cs
Created Jan 22, 2016
allocate object in unmanaged heap
View ObjectHandle.cs
/*
// http://stackoverflow.com/questions/10800063/how-to-instance-a-c-sharp-class-in-unmanaged-memory-possible
// Program to allocate object in unmanaged heap
// Usage:
using(var handle = new ObjectHandle<MyClass>())
{
//do some work
}
*/
You can’t perform that action at this time.