Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / netcat_examples.md
Last active April 15, 2023 20:23
A collection of examples about using netcat.

Netcat Examples

Establish TCP Connection

  • Connect to network host over TCP connection
@justdoit0823
justdoit0823 / http_message_versus_entity.md
Last active January 6, 2018 12:16
A comparision between http message and entity.

Message

HTTP messages consist of requests from client to server and responses from server to client.

HTTP-message   = Request | Response     ; HTTP/1.1 messages
generic-message = start-line
@justdoit0823
justdoit0823 / show_libraries_referenced_by_executables.md
Created November 23, 2017 13:02
List all libraries used by executables on linux.

Command

  • ldd
lddb executable_file

In some circumstances, some versions of ldd may attempt to obtain the dependency information by directly executing the program.

@justdoit0823
justdoit0823 / inspect_multithread.sh
Last active February 27, 2018 09:31
How to debug multithread program under linux system?
# get processes with related threads
ps -eLf |grep "process name"
# list all opened file descriptors in a process PID and under which thread
lsof -aKp PID
# trace syscalls in a process's main thread or other thread PID
strace -p PID
@justdoit0823
justdoit0823 / inspect-descriptor.c
Last active September 16, 2017 04:27
Inspect the internal implementations of descriptor in CPython.
#include "Python.h"
PyTypeObject * create_type(const char * name){
PyObject * args, * dict, * value;
PyTypeObject * type;
args = PyTuple_New(3);
PyTuple_SetItem(args, 0, PyUnicode_FromString(name));
@justdoit0823
justdoit0823 / beijing_public_telephone.js
Created August 28, 2017 09:40
crawl beijing public telephone.
var tables = document.getElementsByTagName('table');
for(var i=0; i < tables.length; i ++) {
for(var j=0; j < tables[i].childNodes[0].childNodes.length; j++){
if(j == 0) {
console.log('====' + tables[i].childNodes[0].childNodes[j].innerText + '=====');
}
else {
console.log(tables[i].childNodes[0].childNodes[j].childNodes[0].innerText, tables[i].childNodes[0].childNodes[j].childNodes[1].innerText);
}
@justdoit0823
justdoit0823 / load_csv_into_mysql.sql
Created August 10, 2017 06:16
How to load csv file into MySQL table
load data infile 'src.csv' into table dest_table FIELDS TERMINATED BY ',' ENCLOSED BY '"';
@justdoit0823
justdoit0823 / file-lock-in-child-process.md
Last active August 28, 2017 11:25
how file lock is handled in child process.
  • File Record lock

As well as being removed by an explicit F_UNLCK, record locks are automatically released when the process terminates or if it closes any file descriptor referring to a file on which locks are held. This is bad: it means that a process can lose the locks on a file like /etc/passwd or /etc/mtab when for some reason a library function decides to open, read and close it.

Record locks are not inherited by a child created via fork(2), but are preserved across an execve(2).

Because of the buffering performed by the stdio(3) library, the use of record locking with routines in that package should be avoided; use read(2) and write(2) instead.

@justdoit0823
justdoit0823 / emacs-startup.el
Created July 28, 2017 07:55
Autoload protobuf model when open proto file.
(defun load-protobuf ()
"Load protobuf."
(add-to-list 'load-path "~/.emacs.d/el-get/protobuf-mode")
(require 'protobuf-mode)
(add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
(add-hook 'protobuf-mode-hook (lambda () (auto-complete-mode)))
)
@justdoit0823
justdoit0823 / hll-in-postgresql.sql
Created July 18, 2017 04:38
How hll works in postgresql
drop table if exists s_user_table;
create table s_user_table (
id int,
user_id int
);
drop table if exists s_user_cnt_table;
create table s_user_cnt_table (