Skip to content

Instantly share code, notes, and snippets.

@gaoconghui
gaoconghui / go_build_by_docker
Created July 17, 2018 09:54
使用docker环境来build go
docker run --rm -it -v "$GOPATH":/go -w /go/build/path dockercore/golang-cross:1.10.2 sh -c '
for GOOS in darwin linux windows; do
for GOARCH in 386 amd64; do
echo "Building $GOOS-$GOARCH"
export GOOS=$GOOS
export GOARCH=$GOARCH
go build -o bin/ironcli-$GOOS-$GOARCH
done
done
'
@gaoconghui
gaoconghui / osd_pg.sh
Created June 27, 2018 07:05
ceph 查看osd的pg个数
ceph pg dump | awk '
/^pg_stat/ { col=1; while($col!="up") {col++}; col++ }
/^[0-9a-f]+\.[0-9a-f]+/ { match($0,/^[0-9a-f]+/); pool=substr($0, RSTART, RLENGTH); poollist[pool]=0;
up=$col; i=0; RSTART=0; RLENGTH=0; delete osds; while(match(up,/[0-9]+/)>0) { osds[++i]=substr(up,RSTART,RLENGTH); up = substr(up, RSTART+RLENGTH) }
for(i in osds) {array[osds[i],pool]++; osdlist[osds[i]];}
}
END {
printf("\n");
printf("pool :\t"); for (i in poollist) printf("%s\t",i); printf("| SUM \n");
for (i in poollist) printf("--------"); printf("----------------\n");
@gaoconghui
gaoconghui / change_commit_author.sh
Created June 20, 2018 06:29
批量修改commit中author和email的脚本
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@gaoconghui
gaoconghui / useful_util.py
Last active June 13, 2018 08:20
一些常用的方法
# -*- coding: utf-8 -*-
def ensure_unicode(s):
if not s:
return s
if isinstance(s, unicode):
return s
elif isinstance(s, str):
return s.decode('utf-8')
else:
@gaoconghui
gaoconghui / py_singleton.py
Created April 27, 2018 11:33
python metaclass实现的单例模式
class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls, *args, **kw):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kw)
return cls.instance
@gaoconghui
gaoconghui / to_dict_mixin.py
Created April 10, 2018 11:44
小的辅助类,提供一个能把复杂对象转为dict的方法
# -*- coding: utf-8 -*
"""
把一个复杂对象转为一个字典
"""
class ToDictMixin(object):
def to_dict(self):
return self._traverse_dict(self.__dict__)
@gaoconghui
gaoconghui / location.dat
Created March 29, 2018 12:24
地理位置识别
0,北京,province
1,北京,city,0
2,东城区,area,1
3,西城区,area,1
4,崇文区,area,1
5,宣武区,area,1
6,朝阳区,area,1
7,丰台区,area,1
8,石景山区,area,1
9,海淀区,area,1
@gaoconghui
gaoconghui / m3u8_downloader.py
Last active May 22, 2018 03:33
m3u8异步下载器
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
下载m3u8格式视频的小组件,使用python3 asyncio
使用ffmpeg合并ts成mp4
"""
import asyncio
import os
import shutil
@gaoconghui
gaoconghui / pdf_tripper.py
Last active January 20, 2023 16:29
删除pdf中指定的字(如水印 版权标记)
# -*- coding: utf-8 -*-
"""
给定一个pdf路径,以及一个列表,可修改pdf内容,删除所有符合条件的文字。
"""
from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.generic import TextStringObject, NameObject
from PyPDF2.pdf import ContentStream
from PyPDF2.utils import b_
@gaoconghui
gaoconghui / delay_queue.py
Last active January 5, 2018 03:29
延迟任务队列
# -*- coding: utf-8 -*-
import heapq
import time
class DelayJobQueue(object):
"""
延迟执行任务队列
q = DelayJobQueue()
q.add(task,at=time.time() + 10)
q.pop_ready() # None