Skip to content

Instantly share code, notes, and snippets.

View nmmmnu's full-sized avatar

Nikolay Mihaylov nmmmnu

View GitHub Profile
@nmmmnu
nmmmnu / hook.sh
Last active November 13, 2018 14:54
LXC port forwarding hook
#!/bin/sh
redirect()
{
OP=$1
NETDEV=$2
S_ADDR=$3
S_PORT=$4
D_ADDR=$5
D_PORT=$6
@nmmmnu
nmmmnu / main.cc
Created September 26, 2018 07:36
Example C++ concepts with gcc 6.2 or greater
// gcc -O3 -std=c++17 -fconcepts
template<typename T>
concept bool EqualityComparable = requires(T a, T b) {
{ a == b } -> bool;
{ a != b } -> bool;
};
@nmmmnu
nmmmnu / dodecahedron.es
Created September 20, 2018 11:37
Platonic Solids
#define fip0 1.618
#define fim0 -1.618
#define fip1 0.618
#define fim1 -0.618
#define sqrtp1 0.7071
#define sqrtm1 -0.7071
rule tetrahedron {
{ x +1 y 0 z sqrtm1 } box
@nmmmnu
nmmmnu / main.cc
Last active August 30, 2018 12:31
#include "matrix.h"
#include <iostream>
int main(){
constexpr Matrix<int, 2> a{ 1, 2 };
constexpr Matrix<int, 2, 3> b{
1, 2,
3, 4,
@nmmmnu
nmmmnu / lsb.cc
Created July 24, 2018 12:07
Find least significant bit set in 0(1)
#include <cstdint>
namespace mybits{
constexpr uint8_t log2(uint64_t n){
constexpr uint8_t tab64[64] = {
0, 58, 1, 59, 47, 53, 2, 60,
39, 48, 27, 54, 33, 42, 3, 61,
51, 37, 40, 49, 18, 28, 20, 55,
30, 34, 11, 43, 14, 22, 4, 62,
@nmmmnu
nmmmnu / class_demo.cc
Last active June 8, 2018 11:11
Hand made polymorphism in C++11
#include <cstdio>
// ==========================================
template<class T>
struct VTableFor;
// ==========================================
struct Vehicle{
#ifndef MY_NARROW_H_
#define MY_NARROW_H_
#include <utility> // is_arithmetic
#include <typeinfo> // bad_cast
#include <limits> // numeric_limits
template<class T, class U>
constexpr T narrow(U const u){
static_assert(std::is_arithmetic<T>::value, "T must be integral");
#include <iosfwd>
#include <utility> // std::forward
template<typename T, class TAG>
class StrongTypedef{
private:
using ST = StrongTypedef;
T v;
<?
class BitcoindRPC{
private $url;
private $user;
private $pass;
function __construct($url, $user, $pass){
$this->url = $url;
$this->user = $user;
[nmmm@zenbook ~]$ ./a.out
0 | (null)
1 | 0.9
2 | 1.0
3 | 1.1
4 | 2.0
5 | (null)