Skip to content

Instantly share code, notes, and snippets.

@Nyahua
Nyahua / falt_dict.py
Last active March 26, 2017 01:00
flatten embedded children dictionaries in python
# coding: utf-8
# In[31]:
dict_list = [
{'id': 1, 'key1': 'abc'},
{'id': 2, 'key1': 'def', 'key2': 123},
{'id': 3, 'key1': 'ghi', 'key2': 456, 'children': [
{'id': 4, 'key1': 'jkl'},
@Nyahua
Nyahua / json.dump_vs_dumps.md
Last active March 26, 2017 12:09
What is the difference between json.dumps and json.load? [closed]
@Nyahua
Nyahua / remove_github_repository.md
Created March 27, 2017 07:40
How to remove a directory from git repository ?
@Nyahua
Nyahua / no_hanghup_run.md
Created March 27, 2017 07:54
How to run the Python program in the background in Ubuntu machine?
@Nyahua
Nyahua / regex_digits_between_words.md
Created March 27, 2017 23:22
regular expression for 7 digits between special words

I got a wrong log as:

test_string = """
03/27/17 12:55.23something wrong with 20405 post id 450469503/27/17 12:50.55something
wrong with 20302 post id 450180903/27/17 11:41.18something wrong with 18314 
post id 443624203/27/17 11:26.56something wrong with 17922 post id 442210904/27/17 10:48.33
something wrong with 16775 post id 438259104/27/17 10:30.59something 
wrong with 16275 post id 436333705/27/17 
"""
@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.

@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 / 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/')
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 / 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)