start new:
tmux
start new with session name:
tmux new -s myname
// run time assert | |
#if ASSERTIONS_ENABLED | |
#define debugBreak() asm {int 3} | |
#define ASSERT(expr) \ | |
if (expr) {} \ | |
else \ | |
{ \ | |
reportAssertionFailure(#expr, \ | |
__FILE__, __LINE__); \ |
class BIT | |
{ | |
private: | |
vector<int> tree; | |
int n; | |
public: | |
BIT(int n): n(n), tree(n+1){} | |
static constexpr int lowbit(int x) {return x & (-x);} | |
void update(int x, int d) | |
{ |
#include <iostream> | |
#include <algorithm> | |
#include <memory> | |
#include <vector> | |
using namespace std; | |
// 一种特殊的二叉搜索树 线段树 | |
// 线段树的树叶节点是真实插入的元素 其余的节点都表示一个区间和 | |
class SegmentTreeNode { |
def ascending(a, b): return a - b | |
def descending(a, b): return -ascending(a, b) | |
# selection sort | |
def sorted(xs, compare = ascending): | |
return [] if not xs else __select(xs, compare) | |
def __select(xs, compare): | |
selected = xs[0] | |
for elem in xs[1:]: | |
if compare(elem, selected) < 0: |
// reference | |
// https://cs-fundamentals.com/tech-interview/c/implement-sizeof-operator-in-c.php | |
#include <cstdio> | |
#define MY_SIZEOF(object) (char*)(&object + 1) - (char*)(&object) | |
int main() | |
{ | |
double x; | |
int arr[10]; | |
printf("double var size: %d\n", MY_SIZEOF(x)); | |
printf("double type size: %d\n", sizeof(double)); |
# scrip to recovery a csv file ruined by Excel | |
# usage python recovery.py [filename.csv] | |
import re | |
import sys | |
def recovery(line, n_f_lines): | |
n_line = re.sub(r"\n", "ENTER", line) | |
n_line = re.sub(r"\s+", ",", n_line) | |
n_line = re.sub("ENTER", "\n", n_line) | |
n_f_lines.append(n_line) |
#include "lunatic.h" | |
#include <lua-5.1/lua.hpp> | |
#include <stdio.h> | |
class LuaTest { | |
public: | |
LuaTest() {} | |
LuaTest(lua_State * L) {} | |
static const char className[]; |
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
const int K = 26; | |
struct Vertex { |
#include <iostream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
// the operation only contains add and substract | |
enum operation {ADD, SUB}; | |
//for leaf node(digit), the value only exist in left val |