Skip to content

Instantly share code, notes, and snippets.

View guerbai's full-sized avatar
🎯
Focusing

guerbai

🎯
Focusing
View GitHub Profile
@guerbai
guerbai / kindlehelper.py
Last active June 2, 2019 04:00
kindle标注行按书名整理
# -*- coding:utf-8 -*-
from collections import defaultdict
shinewords = open('cli.txt','r').read().decode('utf-8')
section = shinewords.strip().split("==========\r\n")
books = defaultdict(lambda : "")
for i in section:
try:
i = i.split('\n')
books[i[0]] += i[3]+'\n\n'
@guerbai
guerbai / total_rows.py
Last active June 2, 2019 04:04
获取python项目有效行数
# -*- coding: utf-8 -*-
import sys
import os
import os.path as path
def get_project_row_info(project, suffix):
res = {
'all_line': 0,
'annotation': 0,
@guerbai
guerbai / compress_pic.py
Last active June 2, 2019 03:59
网上下载图片并压缩
def __get_proper_size_pic_from_url(url, uplimit, workbench=tempfile.mkdtemp(), pic_name=str(time.time()*1000000)):
pic_loc = os.path.join(workbench, pic_name+'.'+url.split('.')[-1])
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(pic_loc, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
else:
logger.warning('download pic failed with url {0}'.format(url))
return
@guerbai
guerbai / cut_text.py
Last active June 2, 2019 03:59
获取包括汉字在内的字符串长度
# -*- coding: utf-8 -*-
# 一个汉字算两个字符
def _chars_fit_baohong_limit(element):
element_len = 0
for index, char in enumerate(unicode(element)):
if element_len >= BAOHONG_TEXT_LENGTH_LIMIT:
index -= 2
break
if u'\u4e00' <= char <= u'\u9fff': # 是汉字.
element_len += 2
@guerbai
guerbai / replaceChildText.js
Last active June 2, 2019 04:08
使用jquery替换chiild
$.prototype.replaceChildText = function (text) {
let textNodes = this.contents().filter(function() {
return this.nodeType === 3;
});
textNodes.each(function() {
if (this.nodeValue.trim() !== '') {
this.nodeValue = text
}
});
@guerbai
guerbai / guerbai-change-application.json
Last active June 2, 2019 04:09
poker karabiner配置
{
"title": "change application",
"rules": [
{
"description": "change application use poker",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "a",
@guerbai
guerbai / user_book_ratings.txt
Last active June 2, 2019 04:08
基础推荐算法演示数据
user_001,book_001,4
user_001,book_002,3
user_001,book_005,5
user_002,book_001,5
user_002,book_003,4
user_002,book_005,4
user_003,book_001,4
user_003,book_003,5
user_003,book_004,3
user_003,book_005,4
@guerbai
guerbai / start_redis.sh
Created June 2, 2019 04:12
shell判断一个应用未开启则开启
# 查放到.zshrc中
redis-server
result=`ps aux | grep 6379 | grep redis-server`
if [[ "$result" == "" ]]
then
redis-server &
fi
tomcat-server
result1=`ps aux | grep tomcat | grep /Library/Java/JavaVirtualMachines`
@guerbai
guerbai / utf8.py
Created June 2, 2019 04:13
python中文编码声明头
# -*- coding: utf-8 -*-
@guerbai
guerbai / jupyter_vim.js
Last active June 2, 2019 04:16
jupyter打开vim编辑模式 #Jupyter
function enable_vim() { document.querySelectorAll(".CodeMirror").forEach(function (e) { e.CodeMirror.setOption("vimMode", true); }); }
document.addEventListener('keydown', function(e) {
if (e.keyCode == 13 && e.metaKey || e.keyCode == 13 && e.shiftKey) {
for (var i = 0; i < 10; i++) setTimeout(enable_vim, 1000 * i);
}
});
enable_vim();