Skip to content

Instantly share code, notes, and snippets.

View duchenpaul's full-sized avatar
:shipit:
Out sick

Chenny Du duchenpaul

:shipit:
Out sick
  • Citrix Systems, Inc.
  • Nanjing
View GitHub Profile
@duchenpaul
duchenpaul / df_to_fwf.py
Created September 25, 2020 02:20
Convert dataframe to fwf
import pandas as pd
import pickle
import numpy as np
from tabulate import tabulate
left_align_gen = lambda length, value: eval(r"'{:<<<length>>}'.format('''<<value>>'''[0:<<length>>])".replace('<<length>>', str(length)).replace('<<value>>', str(value)))
right_align_gen = lambda length, value: eval(r"'{:><<length>>}'.format('''<<value>>'''[0:<<length>>])".replace('<<length>>', str(length)).replace('<<value>>', str(value)))
# df = pd.read_pickle("dummy.pkl")
@duchenpaul
duchenpaul / chunks.py
Last active July 4, 2020 08:23
Split list into pieces evenly
def chunks(l, n):
n = max(1, n)
result = [l[i:i+n] for i in range(0, len(l), n)]
if len(result) * n > len(l):
last = result.pop(-1)
result[-1] += last
return result
lenf = 205
div = 4
@duchenpaul
duchenpaul / date_validation.py
Created March 6, 2020 12:26
validate date in a file
from datetime import datetime
with open('test.txt') as f:
date_list = f.read().split('\n')
date_list = [ x.replace('"', '').strip() for x in date_list if x]
for x in date_list:
try:
datetime.strptime(x, '%m/%d/%Y')
@duchenpaul
duchenpaul / table_transfer.py
Created February 22, 2020 14:17
Transfer data between databases using pandas dataframe
from tqdm import tqdm
import pandas as pd
from sqlalchemy import create_engine, MetaData
SOURCE_TABLE_NAME_LIST = ['individual_tagging_sd', ]
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
@duchenpaul
duchenpaul / shrink_img.sh
Last active November 1, 2019 15:29
Shrink the size of raspberry pi image.
#!/bin/bash
if [ $# -lt 1 ]; then
echo -e "Shrink the size of raspberry pi image.\nUsage: bash $0 xxx.img "
ls -l *.img
exit
fi
IMG=$1
@duchenpaul
duchenpaul / file_split.py
Created April 2, 2019 07:29
Split csv into X line, with or without header
import os
def split(filehandler, delimiter=',', row_limit=1000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
import csv
reader = csv.reader(filehandler, delimiter=delimiter)
current_piece = 1
current_out_path = os.path.join(
output_path,
@duchenpaul
duchenpaul / nwqs_data_extract.py
Created February 11, 2019 04:26
Extract data from nwqs
import json
import sqlparse
import xmltodict
from pprint import pprint
def xml2dict(xmlString):
'''Return json object'''
jsonString = json.dumps(xmltodict.parse(xmlString), indent=4)
xml_in_dict = json.loads(jsonString)
@duchenpaul
duchenpaul / robot_click.py
Created January 6, 2019 14:08
A very simple program which clicks back forward
import time
import pyautogui
print('ready')
time.sleep(3)
print('start')
for i in range(30):
pyautogui.click(1689,444)
time.sleep(.5)
sudo pip install git+git://github.com/powerline/powerline
wget https://github.com/powerline/powerline/blob/develop/font/PowerlineSymbols.otf?raw=true -O PowerlineSymbols.otf
sudo mv PowerlineSymbols.otf /usr/share/fonts/
fc-cache -vf /usr/share/fonts/
wget https://raw.githubusercontent.com/powerline/powerline/develop/font/10-powerline-symbols.conf
sudo mv 10-powerline-symbols.conf /etc/fonts/conf.d/
echo "set rtp+=/usr/lib/python2.7/site-packages/powerline/bindings/vim/" >> ~/.vimrc
echo "set laststatus=2" >> ~/.vimrc
echo "set t_Co=256" >> ~/.vimrc
  1. Open putty
  2. Set host name: hostname.onedumb.com, port: 203
  3. In category, go to Connection->SSH->Tunnels, set Source port: 1433, Destination: sqlhost:1433
  4. Click Add button
  5. Click open, login as: pi password: 1qazxsw2
  6. It should be connected to the server, keep it in hte background
  7. Open SQLServer client
  8. Servername: 127.0.0.1
  9. Login: SA
  10. Password: passWORD