Skip to content

Instantly share code, notes, and snippets.

liaoyw liaoyw

Block or report user

Report or block liaoyw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@liaoyw
liaoyw / tcp_flags.txt
Created Nov 24, 2019 — forked from tuxfight3r/tcp_flags.txt
tcpdump - reading tcp flags
View tcp_flags.txt
##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)
View gitclone
#!/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 Aug 10, 2018 — forked from t3rmin4t0r/MonBuffers.java
Monitoring direct memory in the JVM (from https://blogs.oracle.com/alanb/entry/monitoring_direct_buffers, adapted for JDK8)
View MonBuffers.java
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
View fileserver.go
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")
View cfs_quota.go
package main
import (
"flag"
"time"
"sync/atomic"
"hash/adler32"
"fmt"
"os"
"runtime"
@liaoyw
liaoyw / restore-root-filesystem
Created Jul 12, 2017
restore accidently moved root files system
View restore-root-filesystem
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 Feb 16, 2017
close deleted file fd
View close_fd.py
# 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)
View branch_in_ps1.sh
git_branch() {
gb=$(git branch 2>/dev/null | grep '^*' | tr -d '* ')
[[ ! -z $gb ]] && echo "($gb)"
}
export PS1="\\W\$(git_branch) $"
@liaoyw
liaoyw / latency.markdown
Created Oct 9, 2016 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know
View latency.markdown

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
View ping_time.sh
ping cn.bing.com | while read pong; do echo "$(date): $pong"; done
You can’t perform that action at this time.