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)
#!/bin/bash
function gitclone() {
cd ~/workspace
path=$1
# remove http:// or https:// at the begining
path=${path#http://}
path=${path#https://}
@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
package main
import "log"
import "flag"
import "net/http"
import "fmt"
var dir = flag.String("d", ".", "file directory")
var port = flag.Int("p", 8088, "server port")
@liaoyw
liaoyw / cfs_quota.go
Last active September 17, 2017 04:42
package main
import (
"flag"
"time"
"sync/atomic"
"hash/adler32"
"fmt"
"os"
"runtime"
@liaoyw
liaoyw / restore-root-filesystem
Created July 12, 2017 05:35
restore accidently moved root files system
https://stackoverflow.com/a/11910583/5797497
Old thread, but got exactly the same stupid mistake. /lib64 was moved to /lib64.bak remotely and everything stopped working.
This was a x86_64 install, so ephemient's solution was not working:
# /lib64.bak/ld-linux.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64
/bin/mv: error while loading shared libraries: /bin/mv: wrong ELF class: ELFCLASS64
In that case, a different ld-linux had to be used:
# /lib64.bak/ld-linux-x86-64.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64
@liaoyw
liaoyw / close_fd.py
Last active February 16, 2017 08:59
close deleted file fd
# gdb -ex 'set print thread-events off' --batch -q -x ~/df.py
import os
import os.path
import sys
import gdb
pid = open('/var/run/docker.pid', 'r').read()
print 'attach to ' + pid
gdb.execute('attach ' + pid)
os.chdir('/proc/%s/fd'%pid)