Skip to content

Instantly share code, notes, and snippets.

@weizh888
weizh888 / example.py
Created June 28, 2018 16:37 — forked from tkaemming/example.py
python logging timer decorator
import logging, time
from timer import timed
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
@weizh888
weizh888 / error_unzip.md
Last active September 10, 2018 08:01
Error: end of central directory record signature not found
  • Zip file created in python using:
import zipfile

zf = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED)
zf.write(file, os.path.basename(file))
  • When unzipping file, got error:

Step 1. Install MySQL

Debian / Ubuntu

sudo apt-get update
sudo apt-get install python-dev default-libmysqlclient-dev
  • Python 3

sudo apt-get install python3-dev

import pandas as pd
import zipfile

zip_file_path = 'file_path'
zf = zipfile.ZipFile(zip_file_path)

csv_file_name = 'csv_file_name'
df = pd.read_csv(zf.open(csv_file_name))
  • Method 1
import os

file_path = 'path/to/file/example.csv'
filename_w_ext = os.path.basename(file_path)
filename, file_ext = os.path.splitext(filename_w_ext)

Output:

  • MYSQL

    • date --> unix timestamp

    UNIX_TIMESTAMP('2018-09-25', 'yyyy-MM-dd')

    • unix timestamp --> date

FROM_UNIXTIME(1255033470, 'yyyy-MM-dd')

git clone xxx
git remote add <another-fork-alias> <another-fork-URL>
git checkout <local_branch>

Forward jupyter notebook from remote host

Host abc
  HostName xx.xx.xxx.xx
  User username
  • In .bash_profile:
function jptabc(){
  • Specify the python version
virtualenv --python=<local_python_path> <venv_name>
  • .gitignore

  • git config core.fileMode false

  • git config core.autocrlf or git config --global core.autocrlf or git config --local core.autocrlf