Skip to content

Instantly share code, notes, and snippets.

@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)
@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 / 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 / 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 / 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 / add_new_line_csv.md
Created March 29, 2017 15:02
append new row to old csv file python

using the csv module from the standard library and the open method to avoid leaving the file open.

The key point is using 'a' for appending when you open the file.

import csv   
fields=['first','second','third']
with open(r'name', 'a') as f:
    writer = csv.writer(f)
    writer.writerow(fields)
 
mongodump --db=<old_db_name> --collection=<collection_name> --out=data_directory/
tar -zcvf archive.tar.gz data_directory/ 

mongorestore --db=<new_db_name> --collection=<collection_name> data/<db_name>/<collection_name>.bson

@Nyahua
Nyahua / mongdb_aggregation_pipeline_example.md
Created March 28, 2017 08:42
mongdb aggregation pipeline python example
import pymongo, json
def db_connection(db_name, collection_name):
 client = pymongo.MongoClient('mongodb://localhost:27017/')
@Nyahua
Nyahua / sql-mongo_comparison.md
Created March 28, 2017 08:36
sql mongo comparisoon

SQL to MongoDB Mapping Chart

SQL to MongoDB Mapping Chart

In addition to the charts that follow, you might want to consider the Frequently Asked Questions section for a selection of common questions about MongoDB.

Executables

The following table presents the MySQL/Oracle executables and the corresponding MongoDB executables.

@Nyahua
Nyahua / sql-mongo_comparison.md
Created March 28, 2017 06:48 — forked from aponxi/sql-mongo_comparison.md
MongoDb Cheat Sheets

SQL to MongoDB Mapping Chart

SQL to MongoDB Mapping Chart

In addition to the charts that follow, you might want to consider the Frequently Asked Questions section for a selection of common questions about MongoDB.

Executables

The following table presents the MySQL/Oracle executables and the corresponding MongoDB executables.