Skip to content

Instantly share code, notes, and snippets.

View hustlijian's full-sized avatar
🎯
Focusing

Li Jian hustlijian

🎯
Focusing
View GitHub Profile
@hustlijian
hustlijian / get_mac.cpp
Created December 22, 2020 11:59
get mac by cpp
#include <stdio.h> //printf
#include <string.h> //strncpy
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h> //ifreq
#include <unistd.h> //close
int main()
{
int fd;
#!/bin/bash
###
### my-script — does one thing well
###
### Usage:
### my-script <input> <output>
###
### Options:
### <input> Input file to read.
### <output> Output file to write. Use '-' for stdout.
@hustlijian
hustlijian / ycm_extra_conf.py for libevent
Created February 28, 2020 07:18
YCM config to FindCorrespondingSourceFile from upper directory (eg:libevent)
def FindCorrespondingSourceFile( filename ):
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
return replacement_file
name = os.path.basename(replacement_file)
upper_file = os.path.normpath(os.path.join(os.path.dirname(replacement_file), "../", name))
if os.path.exists( upper_file):
@hustlijian
hustlijian / bash-parameter
Created March 23, 2019 08:49
bash handle input aprameter
while [ "$1" != "" ]; do
case $1 in
-s ) shift
SERVER=$1 ;;
-d ) shift
DATE=$1 ;;
--paramter|p ) shift
PARAMETER=$1;;
-h|help ) usage # function call
exit ;;
// curl -X POST -H "Content-Type: application/octet-stream" --data-binary '@filename' http://127.0.0.1:5050/upload
// curl -F "uploadfile=@test.txt" http://127.0.0.1:5050/upload2
// go run main.go
package main
import (
"fmt"
"io"
"net/http"
"os"
@hustlijian
hustlijian / monitor
Created June 4, 2018 08:33
monitor and restart
#!/bin/bash
# 重试运行的命令
echo $@
MAX_REBOOT_TIMES=100 # 最大重启次数
reboot_times=0
while true ; do
$@
@hustlijian
hustlijian / latency.txt
Created September 16, 2017 03:36 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@hustlijian
hustlijian / performance.py
Created February 4, 2015 05:23
linux 性能信息收集(阿里)(linux server performance info collect script)
#!/usr/bin/python
#
# site: http://outofmemory.cn/code-snippet/35902/python-collect-server-performance-info
# introduction: collect linux server performance info
#
#########################################
# Function: sample linux performance indices
# Usage: python sampler.py
# Author: CMS DEV TEAM
# Company: Aliyun Inc.
@hustlijian
hustlijian / Makefile
Created August 27, 2014 13:46
simple c++ makefile
CXXFLAGS=-Wall -g
CC=g++
LDFLAGS=-L/usr/lib
LDLIBS=-lm
all: main
main: main.o expression.o
clean:
@hustlijian
hustlijian / Makefile
Created March 20, 2014 13:10
text query class of <c++ primer>: input a file, and query the word occur lines
CC = g++
CFLAGS = -g -Wall
DIR_BIN = .
INCS_HEAD := .
LIB_PATH := #-L /usr/lib
LIBS := #-lpthread