Skip to content

Instantly share code, notes, and snippets.

@remyroez
remyroez / sugars.lua
Created February 25, 2020 11:21
lua syntax sugar for basic values(number, function, coroutine)
-- https://stackoverflow.com/questions/33988610/weird-behavior-of-syntax-sugarcolon-in-lua
local debug = require 'debug'
debug.setmetatable(0, { __index = math })
debug.setmetatable(function() end, { __index = coroutine })
debug.setmetatable(coroutine.create(function() end), { __index = coroutine })
local table = require 'table'
table.new = function (self, t)
t = t or self
@remyroez
remyroez / maid64-integral-multiplication.lua
Last active March 3, 2018 15:40
maid64 integral multiplication
local maid64 = require 'maid64'
function resize(width, height)
local w, h = love.graphics.getDimensions()
width = math.max(maid64.sizeX, math.floor((width or w) / maid64.sizeX) * maid64.sizeX)
height = math.max(maid64.sizeY, math.floor((height or h) / maid64.sizeY) * maid64.sizeY)
maid64.resize(width, height)
if maid64.overscan then
maid64.x = (w - (maid64.scaler * maid64.sizeX)) / 2
else
@remyroez
remyroez / lisp.cpp
Last active August 4, 2017 16:44
[WIP] LISP-like
#include <iostream>
#include <variant>
#include <any>
#include <string>
#include <type_traits>
#include <functional>
#include <limits>
#include <unordered_map>
#include <stack>
@remyroez
remyroez / ecs.cpp
Last active July 7, 2017 17:05
簡易 Entity Component System 雛形
#include <iostream>
#include <tuple>
#include <vector>
#include <unordered_map>
#include <string>
#include <cassert>
#include <functional>
#include <typeinfo>
#include <deque>
@remyroez
remyroez / floating_point_constant.cpp
Created November 18, 2016 02:34
Floating point Constant
#include <iostream>
#include <type_traits>
template <auto *V>
struct floating_point_constant {
static constexpr auto value = *V;
static_assert(std::is_floating_point_v<decltype(value)>);
using value_type = decltype(value);
@remyroez
remyroez / no-return.cpp
Created November 17, 2016 08:40
戻り値がない場合の挙動
#include <iostream>
int foo() { return 123; }
int bar() { foo(); }
int main()
{
std::cout << bar() << std::endl;
}
@remyroez
remyroez / non-virtual-destructor.cpp
Created November 17, 2016 05:01
基底クラスにおいてデストラクタが非仮想の場合、派生クラスのデストラクタが呼ばれる場合、呼ばれない場合
#include <iostream>
#include <memory>
class foo {
public:
foo() { std::cout << __func__ << std::endl; }
~foo() { std::cout << __func__ << std::endl; }
};
class bar : public foo {
@remyroez
remyroez / invoke.cpp
Last active November 17, 2016 04:11
invoke test
#include <iostream>
#include <functional>
#include <type_traits>
// impl ----------
template <typename T, typename F = decltype(+std::declval<T>())>
class fn {
public:
using type = std::remove_pointer_t<F>;
@remyroez
remyroez / auto_constant.cpp
Created November 16, 2016 08:58
auto_constant
#include <iostream>
// impl ----------
template <auto V>
struct auto_constant {
static constexpr auto value = V;
using value_type = decltype(value);
using type = auto_constant;
@remyroez
remyroez / state-machine.cpp
Created November 16, 2016 07:50
State Machine
#include <iostream>
#include <functional>
#include <memory>
// impl ----------
struct state {
using pointer = std::shared_ptr<state>;
virtual pointer operator()() = 0;
};