Skip to content

Instantly share code, notes, and snippets.

View cjxgm's full-sized avatar
🦧
Recovering...

Giumo Clanjor (哆啦比猫/兰威举) cjxgm

🦧
Recovering...
View GitHub Profile
@cjxgm
cjxgm / aligned-union.hh
Last active February 12, 2019 09:00
a simple variant implementation similar to boost::variant, with nil value support, written in C++14.
#pragma once
#include <type_traits>
#include <utility> // for std::forward
#include "utils.hh"
#include "constraints.hh"
#include "const-helper.macro.hh"
namespace meta
{
template <class NIL, class ...MEMBERS>
@cjxgm
cjxgm / apmult.cc
Last active August 29, 2015 14:18
arbitary precision multiplication and power-raising
#include <iostream>
#include <deque>
#include <iterator>
namespace tue
{
// 10-based arbitary precision number
struct arbitary_precision
{
struct one {};
@cjxgm
cjxgm / list.c
Last active August 29, 2015 14:17
#include "list.h"
typedef struct node node_t;
struct node
{
node_t* next;
void* data;
};
struct list
@cjxgm
cjxgm / makefile
Last active August 29, 2015 14:16 — forked from o11c/Makefile
simplified unnoticable makefile forwarding
.PHONY: ${MAKECMDGOALS}
all $(filter-out all,${MAKECMDGOALS}): .forward
@# no op
.forward:
@${MAKE} --no-print-directory -C build ${MAKECMDGOALS} || true # known-issue: no error return value
@cjxgm
cjxgm / widow-queen
Last active August 29, 2015 14:16
Widow Queen (Gua Fu Wang) automated, ssh tunnel with empty, auto login by password, on OpenWRT
#!/bin/bash
DIR=/tmp
PREFIX=$DIR/widow
PIDFILE=$PREFIX.pid
IN=$PREFIX.in
OUT=$PREFIX.out
echo -e '\e[1;33mkilling ex widow queen...\e[0m'
empty -k $(< $PIDFILE)
@cjxgm
cjxgm / move-identity.cc
Created March 3, 2015 12:04
overload "+" for std::move
#include <utility>
#include <iostream>
using std::cout;
using std::endl;
// move-identity
template <class T> T&& operator+(T& x) { return std::move(x); }
struct foo
{
@cjxgm
cjxgm / random.cc
Last active August 29, 2015 14:12
generate random number
// modified from the example in http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
#include <random>
#include <iostream>
int main()
{
std::random_device rd; // this is very likely a "real" random number generator
std::mt19937 gen(rd()); // pseudo random number GENerator with seed from "rd"
std::uniform_int_distribution<> dis(0, 100); // DIStribute the result uniformly inside closed interval [0, 100]
@cjxgm
cjxgm / expected.asciidoc
Last active August 29, 2015 14:12
semantic highlighting test code

expect

@cjxgm
cjxgm / bitmask.hh
Last active August 29, 2015 14:12
type safe bitmask for c++14
#pragma once
#include "bitmask_decl.hh"
#include "bitmask_impl.hh"
@cjxgm
cjxgm / shared_pod.cc
Created December 23, 2014 04:05
shared_pod
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
#include <type_traits>
#include <memory>