Skip to content

Instantly share code, notes, and snippets.

View thieu1995's full-sized avatar
🎯
Focusing

Nguyen Van Thieu thieu1995

🎯
Focusing
View GitHub Profile
@thieu1995
thieu1995 / linux_to_windows_files.py
Last active May 8, 2020 22:32
Rename your files in input folder cross platform between linux and windows.
### Thieu Nguyen (https://www.researchgate.net/profile/Thieu_Nguyen6)
import os
import sys
import re
exclude_folders = [".git", "LICENSE", ".gitignore"]
chars_to_remove = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", ":", ",", "<", ">", ";", "+", "|"]
regular_expression = '[' + re.escape(''.join(chars_to_remove)) + ']'
def _rename_files_(path_to_folder=None):
@thieu1995
thieu1995 / download_all_git_repositories.sh
Created May 8, 2020 22:37
Download all public github's repository of a specific user
#!/bin/bash
# Clone all github.com repositories for a specified user.
if [ $# -eq 0 ]
then
echo "Usage: $0 <user_name> "
exit;
fi
USER=$1
@thieu1995
thieu1995 / multiprocessing_with_pool.py
Last active May 8, 2020 23:25
How to handle multiprocessing in python
### Thieu Nguyen (https://www.researchgate.net/profile/Thieu_Nguyen6)
### Excellent article here: https://medium.com/@urban_institute/using-multiprocessing-to-make-python-code-faster-23ea5ef996ba
import time
import multiprocessing
def basic_func(x):
if x == 0:
return 'zero'
elif x % 2 == 0:
return 'even'
@thieu1995
thieu1995 / multiprocessing_vs_multithreading_keras.md
Created May 10, 2020 09:16
Best way to combine multiprocessing python and multithreading tensorflow

For Tensorflow > 2.0 and Keras

  • 2 types of settings:
    • on environment (your os system - linux, windows, mac)
      • It will run your script on multiple cores (CPUs - processors)
      • 2 types:
        • type 0: taskset (some people said we should reset taskset due to the mixed settings of libraries like numpy, scikit-learn, scipy, pandas,....) ==> I tried but it is not working for tensorflow
        • type 1: os.environ['NAME'] = 'CORES'
        • type 2: os.sched_setaffinity(CORE_ID, {LIST_OF_CORE_IDS})
  • tensorflow operations
@thieu1995
thieu1995 / useful_command_linux.sh
Created May 17, 2020 00:17
List of useful command line in linux
# Remove files/folders
rm -rfv folder
rm file_* # *: pattern
rm -v folder/* # Remove all child file in that folder
# Determine file size, all file size in folder
du -sh foldername/filenames
# Watch GPU memory usage in linux
watch -d -n 1 nvidia-smi
@thieu1995
thieu1995 / roulette_wheel_selection.py
Created May 22, 2020 12:46
In Roulette Wheel Selection, this is the best way to deal with negative fitness values
from numpy import min, sum, ptp, array
from numpy.random import uniform
list_fitness1 = array([-12, -45, 0, 72.1, -32.3])
list_fitness2 = array([0.5, 6.32, 988.2, 1.23])
def get_index_roulette_wheel_selection(list_fitness=None):
""" It can handle negative also. Make sure your list fitness is 1D-numpy array"""
scaled_fitness = (list_fitness - min(list_fitness)) / ptp(list_fitness)
minimized_fitness = 1.0 - scaled_fitness
@article{xie2021predicting,
title={Predicting roof displacement of roadways in underground coal mines using adaptive neuro-fuzzy inference system optimized by various physics-based optimization algorithms},
author={Xie, Chengyu and Nguyen, Hoang and Bui, Xuan-Nam and Nguyen, Van-Thieu and Zhou, Jian},
journal={Journal of Rock Mechanics and Geotechnical Engineering},
year={2021},
publisher={Elsevier},
url={https://doi.org/10.1016/j.jrmge.2021.07.005},
doi={10.1016/j.jrmge.2021.07.005},
}
@thieu1995
thieu1995 / top_categories_jekyll.html
Created July 1, 2020 09:05
Determine the top contributors in your Jekyll website.
<ul>
{% for category in site.categories %}
{% assign category_name = category[0] %}
<li>
<a href="/blog/categories/{{ category_name | slugify }}/">
{{ category_name | capitalize | replace: "-", " " }}:
<span class="badge badge-light">{{site.categories[category_name].size}} articles
</span>
</a>
</li>
@thieu1995
thieu1995 / reverse_order_content_and_sidebar.html
Created July 1, 2020 12:54
This block code will make your main content of blog reverse the order with the right sidebar (Jekyll, Bootstrap 4.5, Responsive)
<div class="container-fluid">
<div id="blog_wrapper">
<div class="row">
<div class="col-12 col-lg-9 order-lg-first order-md-last order-sm-last order-last">
{{ content }}
</div>
<div class="col-12 col-lg-3 order-lg-last order-md-first order-sm-first order-first">
{%- include right_sidebar.html -%}
</div>
</div>
@incollection{yang2010new,
author = "Xin-She Yang",
booktitle = "Nature inspired cooperative strategies for optimization (NICSO 2010)",
pages = "65–74",
publisher = "Springer",
title = "A new metaheuristic bat-inspired algorithm",
year = "2010",
url={https://doi.org/10.1007/978-3-642-12538-6_6}
}