Skip to content

Instantly share code, notes, and snippets.

View dtranhuusm's full-sized avatar

Duy Tran-Huu dtranhuusm

  • NRG
  • Cypress, TX
View GitHub Profile
@dtranhuusm
dtranhuusm / test_remote.py
Created September 28, 2018 03:55
Sample code using decorator for caching celery+redis result
""" Module to test remote execution using Celery queue with Redis backend.
Setup:
* a redis database must be running and accessible.
* the environment variable redis_host mut be defined with value <ip>:<port>
* celery and redis packages must be installed
* celery worker(s) must be running this script:
```celery worker -A tests.test_remote -l info --autoscale=5,1```
Execute test:
pytest tests/test_remote.py
License: GPL v3
@dtranhuusm
dtranhuusm / plantumlmagic.py
Created September 28, 2018 20:01
Jupyter notebook magic for plantuml using web service
"""Save the file where you can import it in your jupyter notebook.
In a cell, execute:
import plantumlmagic
%reload_ext plantumlmagic
Then you can use the magic in another cell:
%%plantumlmagic localhost:1234
@startuml
Bob -> Alice : hello
@dtranhuusm
dtranhuusm / parse_tree.py
Last active October 12, 2018 19:13
Convert tree string to dictionary
""" Function to convert a tree in string format to a dictionary.
There is no error handling.
It doesn't allow a level to be skipped.
"""
def tree_child(acc, path, element):
node = element.lstrip()
current = None
for p in path:
if current:
current = current[p]
@dtranhuusm
dtranhuusm / rename_html2aspx.py
Created October 17, 2018 04:35
Make static html site browsable in Sharepoint by renaming the files with extension aspx and also the content of the files
import os
import re
import traceback
import sys
import logging
logger = logging.getLogger(__name__)
def explore_path(path, params):
@dtranhuusm
dtranhuusm / extract_properties.py
Created November 8, 2018 03:48
Build a dictionary from properties file
prop_match = re.compile(r'\s*(?P<prop_id>\S+)\s*=\s*(?P<prop_val>\S+)') # pylint: disable=W1401
def extract_properties(filename):
""" Extract properties from file
Args:
filename(str): file path
Returns: