This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import datetime | |
# json格式化时自定义动作 | |
class CJsonEncoder(json.JSONEncoder): | |
def default(self,obj): | |
if isinstance(obj,datetime.datetime): | |
return obj.strftime('%Y-%m-%d %H:%M:%S') | |
elif isinstance(obj,datetime.date): | |
return obj.strftime('%Y-%m-%d') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使用匿名函数进行排序,其中k就是list中的元素,也就是一个dict | |
newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) | |
#使用itemgetter | |
from operator import itemgetter | |
# reverse=True表示降序 | |
newlist = sorted(list_to_be_sorted, key=itemgetter('name'),reverse=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getQueryString = function (name, url) { | |
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); | |
var search; | |
if (url === undefined) { | |
url = decodeURI(location.href); | |
} | |
var index = url.indexOf("?"); | |
search = url.substring(index); | |
var r = search.substr(1).match(reg); | |
if (r != null)return unescape(r[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form class='form-horizontal group-border-dashed' action="{{info['subUrl']}}" method='POST' id='broadcastForm' onSubmit='return false'> | |
<div class="form-group"> | |
<label class="col-sm-3 control-label">人数</label> | |
<small>满多少人送红包</small> | |
<div class="col-sm-6"> | |
<input style="width:100%;float:left;" class="form-control" type="text" name="peoplenum" id="peoplenum" > | |
<label class="hitLabel" for="peoplenum">*</label> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#列出所有会话 | |
$ tmux ls | |
#新建一个会话 | |
$ tmux new -s session-name | |
# 新建会话但并不指定名字 (不推荐这样做) | |
$ tmux new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#统计文件夹下文件的数目 | |
import os | |
DIR = '/tmp' #要统计的文件夹 | |
print(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-a:redis密码 | |
-n:选择Redis中哪个数据库 | |
keys:找出符合语法的redis key | |
通过管道,使用xargs将搜索到的key传递给redis,进行删除 | |
redis-cli -a Fkkg65NbRwQOnq01OGMPy5ZREsNUeURm -n 1 keys gold:canjoin:room:*:*:set | xargs redis-cli -a Fkkg65NbRwQOnq01OGMPy5ZREsNUeURm -n 1 del |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt # plt 用于显示图片 | |
import matplotlib.image as mpimg # mpimg 用于读取图片 | |
import numpy as np | |
''' | |
显示图片 | |
''' | |
lena = mpimg.imread('lena.png') # 读取和代码处于同一目录下的 lena.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.查看占用的端口 | |
终端输入:lsof -i tcp:port | |
将port换成被占用的端口(如:8086、9998) | |
将会出现占用端口的进程信息 | |
或者使用: lsof -i :5000 (看对应的端口号则可) | |
2.根据pid kill掉进程 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
import os | |
def timestamptotime(timestamp): | |
''' | |
时间戳转时间 | |
:param timestamp: 时间戳 | |
:return: 时间 | |
''' |