Skip to content

Instantly share code, notes, and snippets.

@m-ou-se
m-ou-se / make
Last active December 12, 2015 05:38
#!/bin/bash
if [ ! -f Makefile -a "$1" != "-C" ]; then
if [ -f build/Makefile ]; then
/usr/bin/make -C build "$@"
elif [ -f CMakeLists.txt ]; then
( mkdir build && cd build && cmake .. && make "$@" )
else
echo "No Makefile, build/Makefile or CMakeLists.txt found." >&2
exit 1
fi
@m-ou-se
m-ou-se / test.cpp
Created April 9, 2013 12:55
Ugly hacky code-duplication finder.
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
struct line {
std::string file;
size_t line_number;
@m-ou-se
m-ou-se / fun.cpp
Last active December 20, 2015 06:39
Parameter Pack Crazyness
query("hello");
// executes q("hello");
query("delete where x =", x);
// executes q("delete where x = % ", x);
query("delete where x =", x, "and a = 5");
// executes q("delete where x = % and a = 5", x);
query("delete where x =", x, "and a =", y);
@m-ou-se
m-ou-se / input.cpp
Last active December 23, 2015 06:08
C++ parser
int const * a = nullptr;
@m-ou-se
m-ou-se / grammar
Created September 17, 2013 09:05
C++ grammar
= translation_unit
declarations
* declarations
declaration
| primary_expression
primary_expression_literal
primary_expression_this
expression_in_parentheses
@m-ou-se
m-ou-se / input.cpp
Last active December 23, 2015 06:09
C++ parse log
int main() {}
@m-ou-se
m-ou-se / ratio_power.cpp
Last active December 27, 2015 07:39
std::ratio_power
template<typename R, int p>
struct ratio_power {
private:
using S = typename std::ratio_multiply<R, R>::type;
public:
using type = typename std::ratio_multiply<
typename ratio_power<R, p%2>::type,
typename ratio_power<S, p/2>::type
>::type;
constexpr static intmax_t num = type::num;
@m-ou-se
m-ou-se / peek.cpp
Created March 1, 2014 15:54
Peeking Idea
class input {
// ...
/// Read the next character, but put it back.
/**
* \warning peek() does not work like std::istream::peek().
* This function will actually take the next character from
* the stream, and the object returned by peek() will put it back
* when it is destroyed, unless take() was called on that object.
@m-ou-se
m-ou-se / 0 utf.hpp
Last active April 27, 2023 22:24
Utf-8/16 characters in C++
#include <array>
#include <iostream>
#include <stdexcept>
#include <string>
#include <cstdint>
/// An UTF-8 encoded character.
class utf8_char {
private:
@m-ou-se
m-ou-se / clock.scad
Last active December 11, 2016 12:48
3D model for my whiteboard clock
$fs=1;
$fa=1;
servo_l = 24;
servo_w = 13;
servo_h = 21;
bolt_hole_diameter = 4.5;
servo_axis_diameter = 4;