This file contains hidden or 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
>>>s = ['variable1 (name3)', 'variable2 (name2)', 'variable3 (name1)'] | |
>>> s.sort(key = lambda x: x.split()[1]) | |
>>> s | |
['variable3 (name1)', 'variable2 (name2)', 'variable1 (name3)'] |
This file contains hidden or 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
find . -maxdepth 1 ! -name 'file1' ! -name 'file2' -type f -exec rm -v {} + |
This file contains hidden or 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 glob | |
path = 'c:\\projects\\hc2\\' | |
files = [f for f in glob.glob(path + "**/*.txt", recursive=True)] | |
for f in files: | |
print(f) |
This file contains hidden or 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 requests | |
from bs4 import BeautifulSoup | |
url = 'https://www.troyhunt.com/the-773-million-record-collection-1-data-reach/' | |
res = requests.get(url) | |
html_page = res.content | |
soup = BeautifulSoup(html_page, 'html.parser') | |
text = soup.find_all(text=True) | |
output = '' |
This file contains hidden or 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 requests | |
url = "http://192.168.1.22:18888/loginByAuth" | |
querystring = {"username":"YLCS001","password":"92ba8aba25647d2812bba427ce5e2d17"} | |
payload = "" | |
headers = { | |
'cache-control': "no-cache", | |
'Postman-Token': "ef77fde8-e52d-49b7-b315-ec67a45ec2db" |
This file contains hidden or 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
# 批量重启小时内挂掉的docker | |
docker ps -a | grep minutes | awk '{print $1}'|xargs sudo docker restart |
This file contains hidden or 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
find . -name "*.png" -ctime +10|xargs -t -I {} rm {} |
This file contains hidden or 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
for file in $(cat ~/Desktop/files.txt); do mv "$file" ~/newfolder; done | |
find ./ -name "app_info*.csv" |xargs -i cp {} ./app_info_bak |
This file contains hidden or 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
可以用pandas里面的map映射字典。 | |
In [1]: import pandas as pd | |
In [2]: df = pd.DataFrame({'A':['AAAI','ICDM','SDM','WWW','KDD'], | |
'B':[0.88, 0.41,0.22, 0.33, 0.35]}) | |
In [3]: type_dict = {"AAAI":"AI","ICDM":"DM","SDM":"DM","KDD":"DM","WWW":"NEW"} | |
In [4]: df["C"] = df['A'].map(type_dict) |
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
@desc: 互换键值位置 | |
@author: Bingo Cai | |
""" | |
prefs = {'Lady in the water':{'Lisa Rose':2.5, 'Gene Seymour':3.0}, | |
'Lady in the moon':{'Lisa Rose':3.5, 'Gene Seymour':2.0}, | |
'spring festival':{'Lisa Rose':1.5, 'Gene Seymour':1.0}, |