Skip to content

Instantly share code, notes, and snippets.

View 2bbb's full-sized avatar

2bit 2bbb

View GitHub Profile
@2bbb
2bbb / polyfill.hpp
Created June 16, 2017 13:53
polyfill
namespace bbb {
template <typename type>
struct is_null_pointer : std::false_type {};
template <typename type>
using is_null_pointer_t : get_type<is_null_pointer<type>>;
template <>
struct is_null_pointer<std::nullptr_t> : std::true_type {};
template <typename ...>
@2bbb
2bbb / build.sh
Created July 26, 2017 17:03
variable_inliner
#!/bin/bash
clang++ -c -std=c++11 -stdlib=libc++ main.cpp
clang++ -c -std=c++11 -stdlib=libc++ sub.cpp
clang++ main.o sub.o -o main
@2bbb
2bbb / function_check.cpp
Created September 28, 2017 08:22
check function exist
#include <iostream>
int f(int x) {
std::cout << "true f" << std::endl;
return 0;
}
namespace bbb {
struct function_is_not_exist {};
function_is_not_exist f(...) { return {}; };
@2bbb
2bbb / brainfuck.exs
Last active October 26, 2017 17:26
brainfuck.exs
defmodule Brainfuck do
@seek_next ?>
@seek_prev ?<
@inc_head ?+
@dec_head ?-
@print_head ?.
@read_input ?,
@loop_begin ?[
@loop_end ?]
@2bbb
2bbb / sheep.scpt
Last active October 23, 2017 21:43
sleep sheep (羊の数を数えてくれるApple Script)
set i to 1
repeat while true
say {"羊が", i, "匹"} as string using "Kyoko"
set i to i + 1
delay 1
end repeat
@2bbb
2bbb / autodiff.hpp
Last active January 16, 2018 09:01
autodiff
#include <cmath>
namespace bbb {
namespace autodiff {
template <typename type>
struct dual {
inline static dual make(type x) { return dual(x); };
inline static dual scalar(type x) { return dual(x, 0.0); };
constexpr dual(type x, type dx = type(1.0)) noexcept
@2bbb
2bbb / build.sh
Created February 21, 2018 05:06
duplicate
#!/bin/bash
clang++ -Wall impl.cpp sub.cpp -o impl.a -std=c++11
./impl.a
@2bbb
2bbb / inline_variable.cpp
Created February 21, 2018 13:51
inline_variable
#include <iostream>
template <typename type, typename tag = type>
struct inline_variable {
static type &get(const type &initial_value) {
static type _{initial_value};
return _;
}
};
@2bbb
2bbb / infix_op.cpp
Last active February 24, 2018 07:00
infix_op
#include <utility>
namespace bbb {
namespace infix_op {
template <typename function_type>
struct infix_op {
inline infix_op() : f() {};
template <typename ... arguments>
inline infix_op(arguments ... args) : f(std::forward<arguments>(args) ...) {};
@2bbb
2bbb / polyfunction.cpp
Last active March 8, 2018 19:25
polyfunction
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <functional>
namespace bbb {
namespace {
template <bool b, typename type>
using enable_if_t = typename std::enable_if<b, type>::type;
};