Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / hello.proto
Last active July 21, 2017 13:09
A hello protobuf 3 message.
syntax = 'proto3';
package hello;
message Hello {
string text = 1; // text message
uint64 user_id = 2; // user identity
@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 / 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 / dynamic-function-call.c
Created August 7, 2017 14:31
Check dynamic function call analyze.
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <sys/utsname.h>
typedef void (*func) (void);
void darwin_show_sys(){
@justdoit0823
justdoit0823 / install_python36.sh
Created August 8, 2017 09:53
How to install Python3.6 on centos
# install ius
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
# install Python3.6
yum -y install python36u
@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 / hello_tornado_app.py
Created August 13, 2017 06:09
A hello world tornado app server.
import sys
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
@justdoit0823
justdoit0823 / supervisor.conf
Last active December 11, 2017 12:23
A simple supervisor example configuration file.
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0777
[supervisord]
logfile = /tmp/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
@justdoit0823
justdoit0823 / date.sh
Last active February 28, 2018 06:24
Use `date` command in terminal
# print unix timestamp
date +%s
# print datetime represented by unix timestamp
date -r (macOS)
date --date='@1502693336' (Linux)
date +%s --date='2018-11-12' (Linux)
@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);
}