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 Func> struct scope_exit | |
{ | |
Func cleanup; | |
scope_exit(Func &&f) : cleanup(std::forward<Func>(f)) {} | |
~scope_exit() { cleanup(); } | |
}; | |
template <typename Func> scope_exit<Func> make_scope_exit(Func &&f) | |
{ |
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 <stdexcept> | |
struct require_error : std::runtime_error { | |
using std::runtime_error::runtime_error; | |
}; | |
void require(bool b, char const *message) { | |
if (!b) { | |
throw require_error(message); | |
} |
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 <utility> | |
#ifndef SCOPE_EXIT_H_ | |
#define SCOPE_EXIT_H_ | |
// modeled slightly after Andrescu’s talk and article(s) | |
namespace std { | |
namespace experimental { | |
template <typename EF> struct scope_exit { | |
// construction |
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 <cxxabi.h> | |
#include <cstdlib> | |
#include <cstddef> | |
#include <iostream> | |
#include <memory> | |
struct clib_free { | |
template<typename T> |
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
cmake_minimum_required(VERSION 3.3) | |
project(lua VERSION 5.3.2 LANGUAGES C CXX) | |
set(LIB_SOURCE src/lapi.c src/lauxlib.c src/lbaselib.c src/lbitlib.c | |
src/lcode.c src/lcorolib.c src/lctype.c src/ldblib.c | |
src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c | |
src/linit.c src/liolib.c src/llex.c src/lmathlib.c src/lmem.c | |
src/loadlib.c src/lobject.c src/lopcodes.c src/loslib.c | |
src/lparser.c src/lstate.c src/lstring.c src/lstrlib.c | |
src/ltable.c src/ltablib.c src/ltm.c src/lundump.c |
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
" show command in bottom right corner | |
set showcmd | |
" show line numbers in gutter | |
set number | |
set relativenumber | |
" disable softwrap | |
set nowrap | |
set sidescroll=1 |
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
# based on http://blog.robertelder.org/bash-one-liner-compose-music/ | |
# with overflow, channels, timing, etc. bugs fixed | |
< /dev/urandom hexdump -v -e '/1 "%u\n"' | | |
gawk 'BEGIN { split("0,2,4,5,7,9,11,12",a,",")} | |
{ for (i = 0; i < 0.3125; i += 0.0000625) | |
printf("%02X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | | |
sed -e 's/.*\(..\)$/\1/g' | | |
xxd -r -p | | |
sox -traw -c 1 -r16000 -b8 -e signed-integer - -tcoreaudio |
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 <algorithm> | |
#include <functional> | |
#include <iomanip> | |
#include <iostream> | |
#include <iterator> | |
#include <map> | |
#include <memory> | |
#include <string> | |
#include <type_traits> | |
#include <utility> |
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 <algorithm> | |
#include <iostream> | |
#include <random> | |
std::vector<int> &factor(int n, std::vector<int> &prime_factors) { | |
auto i = 2; | |
while (n > 1) { | |
if (0 == n % i) { | |
prime_factors.push_back(i); | |
n /= 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
#include <iostream> | |
#include <future> | |
#include <vector> | |
#include <atomic> | |
#include <random> | |
#include <string> | |
const int n_tasks = 1000; | |
std::atomic<bool> flags[n_tasks] = {}; |