Skip to content

Instantly share code, notes, and snippets.

View EvanMu96's full-sized avatar
🐟
touch fish.go

Sen EvanMu96

🐟
touch fish.go
View GitHub Profile
@EvanMu96
EvanMu96 / myassert.h
Created January 18, 2021 07:52
runtime && compiletime c++ assertion
// 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 {
@EvanMu96
EvanMu96 / previous.py
Created October 26, 2020 02:55
remove all of the for loops
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:
@EvanMu96
EvanMu96 / sizeof.cpp
Created August 18, 2020 05:54
implement a sizeof function
// 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));
@EvanMu96
EvanMu96 / tmux-cheatsheet.markdown
Created August 13, 2020 07:54 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@EvanMu96
EvanMu96 / recovery.py
Created May 22, 2020 06:50
recovery the csv file destroy by microsoft excel
# 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)
@EvanMu96
EvanMu96 / example.cpp
Created May 8, 2020 09:18
basic lua binding header helper
#include "lunatic.h"
#include <lua-5.1/lua.hpp>
#include <stdio.h>
class LuaTest {
public:
LuaTest() {}
LuaTest(lua_State * L) {}
static const char className[];
@EvanMu96
EvanMu96 / ac.cpp
Last active January 26, 2022 08:11
Aho-Corasick String match algorithm
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int K = 26;
struct Vertex {
@EvanMu96
EvanMu96 / translate.cpp
Created February 11, 2020 16:42
translate inexpr into suffexpr
#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