Skip to content

Instantly share code, notes, and snippets.

View hta218's full-sized avatar
🇻🇳
Working @ [::1]:443

Tuan Anh (Leo) Huynh hta218

🇻🇳
Working @ [::1]:443
View GitHub Profile
@hta218
hta218 / deep-merge.js
Created December 13, 2022 01:15 — forked from ahtcx/deep-merge.js
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}
@hta218
hta218 / git-clearHistory
Created June 7, 2021 15:25 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@hta218
hta218 / vscode-settings.json
Last active May 25, 2021 04:51
VS Code settings
{
"workbench.iconTheme": "material-icon-theme",
"editor.fontSize": 18,
"workbench.startupEditor": "newUntitledFile",
"editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
"explorer.confirmDragAndDrop": false,
"editor.tabSize": 2,
"emmet.syntaxProfiles": {
"javascript": "js"
},
@hta218
hta218 / pagefly-atc-shopify.js
Last active April 17, 2020 03:41 — forked from paul-phan/pagefly-atc-shopify.js
pagefly-atc-shopify.js
////////////////////////////////////////////////// Basic template
// PageFly ATC Helpers - Do not delete
try {
window.addEventListener('load', function() {
window.__pagefly_helper_store__ && window.__pagefly_helper_store__.subscribe(function(res) {
// Handle update cart here
});
});
} catch(e) { console.error("PF Error:: ", e) }
@hta218
hta218 / toPlainEnglish
Last active April 13, 2020 07:57
Replace all VNese letters with the corresponding English accents and remove all special characters (`!@#$%^&*()+=)
const toPlainEnglish = str => {
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a")
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e")
str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i")
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o")
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u")
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y")
str = str.replace(/đ/g, "d")
str = str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ/g, "A")
str = str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g, "E")
numbers = [2018, 1, 5, 0, -10, 20, 15, -7]
sorted_numbers = []
sorting = True
while sorting:
min_numb = min(numbers)
sorted_numbers.append(min_numb)
numbers.remove(min_numb)
low = 1
high = 100
playing = True
print('Guess your number game')
input('Now think of a number from 1 to 100, then press Enter')
print("""
All you have to do is answer to my guess
'c' if my guess is correct
map = {
'size_x' : 5,
'size_y' : 5
}
player = {
"x" : 3,
"y" : 4
}
@hta218
hta218 / mlab.py
Last active February 27, 2018 07:56
Mlab connect guide for c4e course
import mongoengine
#mongodb://<dbuser>:<dbpassword>@ds249798.mlab.com:49798/muadongkhonglanh
host = "ds249798.mlab.com"
port = 49798
db_name = "muadongkhonglanh"
user_name = "admin"
password = "admin"