Skip to content

Instantly share code, notes, and snippets.

@Nyahua
Nyahua / dict_subset.py
Created March 30, 2017 14:12
how to get a subset / diff from dict
def dict_inter(dict_in, flds):
dict_out = {
key: dict_in[key] for key in flds if key in dict_in.keys()
}
return dict_out
def dict_diff(dict_in, flds):
dict_out = {
key: dict_in[key] for key in dict_in.keys() if key not in flds
}
@Nyahua
Nyahua / ubuntu_tips.md
Last active October 23, 2018 13:20
ubuntu tips

run a python program in background

nohup $python program.py &

disable ssh timeout

  • first: sudo nano /etc/ssh/sshd_config

  • add the following lines:

TCPKeepAlive no
@Nyahua
Nyahua / vaccum.py
Created April 10, 2017 02:15
VACUUM sqlite in python3.6
import sqlite3, os
def vacuum(db_name):
print("Filesize of {} before vaccum is {:,d} bytes.".
format(db_name, os.stat(db_name).st_size)
)
conn = sqlite3.connect(db_name)
isolation = conn.isolation_level
print(isolation)
conn.isolation_level = None
@Nyahua
Nyahua / handyexcel.py
Created May 1, 2017 13:54
some handy excel helping functions with the help of openpyxl
import openpyxl
import numpy as np
import pandas as pd
def get_column_letter(col_idx):
"""Convert a column number into a column letter (3 -> 'C')
Right shift the column col_idx by 26 to find column letters in reverse
order. These numbers are 1-based, and can be converted to ASCII
ordinals by adding 64.
"""
@Nyahua
Nyahua / folium_html_marker.py
Created May 4, 2017 14:13
add html ref to popup marker
import folium
ref_html = r'<a href="http://www.shenyang.gov.cn/" target="_blank"> I am here </a>'
pop_html = folium.Popup(folium.Html(ref_html, script=True))
map_1 = folium.Map(location=[41.8057, 123.4315], zoom_start=12,
tiles='Stamen Terrain')
folium.Marker(
location = [41.8057, 123.4315],
popup = pop_html).add_to(map_1)