Skip to content

Instantly share code, notes, and snippets.

@liaoyw
liaoyw / 01.bash_shortcuts_v2.md
Created February 6, 2023 16:19 — forked from tuxfight3r/01.bash_shortcuts_v2.md
Bash keyboard shortcuts

Bash Shortcuts

visual cheetsheet

Moving

command description
ctrl + a Goto BEGINNING of command line
@liaoyw
liaoyw / aes_cbc_pkcs5.go
Created February 20, 2021 08:06 — forked from hothero/aes_cbc_pkcs5.go
AES/CBC/PKCS5Padding implementation by Golang (can work with JAVA, C#, etc.)
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
)
@liaoyw
liaoyw / BTree.cpp
Created April 28, 2020 06:36 — forked from pervognsen/BTree.cpp
A B+-tree implementation with find, insert and delete in 176 lines of code.
enum { BMAX = 32, BMIN = BMAX / 2, BHEIGHT = 6 };
struct BNode {
uint32_t length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
};
};
@liaoyw
liaoyw / tcp_flags.txt
Created November 24, 2019 12:46 — forked from tuxfight3r/tcp_flags.txt
tcpdump - reading tcp flags
##TCP FLAGS##
Unskilled Attackers Pester Real Security Folks
==============================================
TCPDUMP FLAGS
Unskilled = URG = (Not Displayed in Flag Field, Displayed elsewhere)
Attackers = ACK = (Not Displayed in Flag Field, Displayed elsewhere)
Pester = PSH = [P] (Push Data)
Real = RST = [R] (Reset Connection)
Security = SYN = [S] (Start Connection)
@liaoyw
liaoyw / MonBuffers.java
Created August 10, 2018 07:38 — forked from t3rmin4t0r/MonBuffers.java
Monitoring direct memory in the JVM (from https://blogs.oracle.com/alanb/entry/monitoring_direct_buffers, adapted for JDK8)
import java.io.File;
import java.util.*;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.*;
import com.sun.tools.attach.VirtualMachine; // Attach API
@liaoyw
liaoyw / latency.markdown
Created October 9, 2016 01:10 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
import os
"""
as bash command: du -sb dir
+4906: add 4096bytes for the top dir
"""
def du_sb(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)])) + 4096;
def get_total_file_size(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)]) if os.path.isfile(f))