Skip to content

Instantly share code, notes, and snippets.

@ourdaidai
ourdaidai / private_fork.md
Created December 19, 2022 05:47 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare git@github.com:usi-systems/easytrace.git

@ourdaidai
ourdaidai / uniout.py
Created March 19, 2021 10:05
[打印中文] 打印各种语言消除编码问题 #print #python
import uniout
from pprint import pprint
langs = [
'Hello, world!',
'你好,世界!',
'こんにちは世界',
u'Hello, world!',
u'你好,世界!',
u'こんにちは世界'
]
@ourdaidai
ourdaidai / gis_wkt_parse.py
Created February 2, 2021 09:41
[gis] gis相关 #wkt #geopandas
# -*- coding: utf-8 -*-
from shapely.geometry import Point, LineString, Polygon, MultiPolygon
from shapely import wkt
import geopandas as gpd
import pandas as pd
import os
#os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' # 万一中文有问题
@ourdaidai
ourdaidai / 正则表达式.txt
Last active February 2, 2021 07:35
[正则表达式] #reg
匹配表注释,只保留中文英文,忽略数据字典
^[\u4e00-\u9fa5_a-zA-Z0-9]+
匹配XX_AA_XX中的 'AA'
(?<=_).*?(?=_)
# 匹配 'CREATE TABLE TEST22 SELECT uid from test1' 中的 'TEST22'
def extract_table_name(sql):
sql = re.sub(r'\s+', ' ', sql)
p_name = re.compile(r'(?<=(CREATE TABLE\s))\S+')
@ourdaidai
ourdaidai / MysqlData.py
Last active October 28, 2020 02:04
[数据库连接类] pymysql #python
import pymysql
def reconnect_mysql(func):
def wrapper(self, *args, **kwargs):
try:
self.connection.ping(reconnect=True)
except pymysql.OperationalError:
self.connection = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password,
db=self.db, charset='utf8mb4')
finally:
@ourdaidai
ourdaidai / YAML的config操作.py
Last active October 13, 2020 03:43
[YAML的config操作] #yaml
import yaml
file = open('config.yaml', 'r', encoding='utf-8')
file_data = file.read()
file.close()
config = yaml.full_load(file_data)
CONNECT_DEBUG = config[config['DB_TABLES_DEBUG']['CONNECT']]
CONNECT_PRODUCE = config[config['DB_TABLES_PRODUCE']['CONNECT']]
@ourdaidai
ourdaidai / config_logging_mysql.py
Last active October 13, 2020 07:03
[config_logging_mysql] #python
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 28 10:06:04 2020
@author: tangliang
"""
import pymysql
import pandas as pd
from tqdm import tqdm
@ourdaidai
ourdaidai / tool_text.py
Created May 22, 2020 07:48
[字符串处理工具] #python
import unicodedata
if self._do_lower_case:
if is_py2:
text = unicode(text)
text = unicodedata.normalize('NFD', text)
text = ''.join([
ch for ch in text if unicodedata.category(ch) != 'Mn'
])
text = text.lower()
@ourdaidai
ourdaidai / ftp下载相关.py
Created January 15, 2020 11:42
[ftp下载相关] #ftp #python
import pymysql
import datetime
import time
import pandas as pd
from sqlalchemy import Column, String, create_engine
import os
from ftplib import FTP
current_path = os.path.dirname(__file__)
@ourdaidai
ourdaidai / 读取大文件.py
Created January 14, 2020 11:20
[读取大文件] #python
with open(filename, 'rb') as f:
for line in f:
<do something with the line>