Skip to content

Instantly share code, notes, and snippets.

View tranduclinh2067's full-sized avatar

Trần Đức Lĩnh tranduclinh2067

View GitHub Profile
@tranduclinh2067
tranduclinh2067 / unlimited_trials_babeledit.txt
Created July 2, 2023 12:57
Activate BabelEdit temporarily / Unlimited trial
Obviously for educative purposes only.
Furthermore, this DOESN'T activate BabelEdit permanently.
If you like the software, buy it, the devs deserve it.
Since I have no money to buy it, I discovered a workaround for unlimited trials.
It's quite a annoying workaround, but ... it works!
Firstly go to "c:\windows\system32\drivers\etc\" and open the "hosts" file in Notepad/Notepad++/VSCode/Sublime/Atom/whatever as admin (if you don't open it as admin, it won't let you save it).
Add this line at the end of the file:
#!/usr/bin/env python3.4
import urllib.request
import asyncio
def return_response(url):
return urllib.request.urlopen(url).read()
@asyncio.coroutine
def read_page(loop, url):
2 - Autos & Vehicles
1 - Film & Animation
10 - Music
15 - Pets & Animals
17 - Sports
18 - Short Movies
19 - Travel & Events
20 - Gaming
21 - Videoblogging
22 - People & Blogs
@tranduclinh2067
tranduclinh2067 / Promise.js
Created April 9, 2019 13:49
Xử lý bất đồng bộ thông qua Promise (ES6)
var time = function(length) {
return new Promise (function (resolve, reject) {
setTimeout(function () {
if(length > 10000) {
reject ('Quá lâu để chờ đợi! \n Thời gian thực hiện là ' + length/1000 + ' giây!');
}
else {
resolve ('Thời gian thực hiện ' + length/1000 + ' giây!');
}
}, length);
@tranduclinh2067
tranduclinh2067 / Generator_Yield.js
Last active March 9, 2019 23:44
Muốn tạm dừng 1 dòng code nào đó để làm 1 việc khác, thực thi lại thông qua nhiều gần gọi giống nhau thông qua .next().
// Generator function là một function, có khả năng tạm ngưng thực thi trước khi hàm kết thúc, và có thể tiếp tục chạy ở 1 thời điểm khác.
// --------- Ví dụ đơn giản
function* Op(name) {
yield name * 5; // Thực thi lần thứ 1
yield name; // Thực thi lần thứ 2
}
const call = Op(4);
console.log(call.next().value); // Lần gọi thứ 1
console.log(call.next().value); // Lần gọi thứ 2
@tranduclinh2067
tranduclinh2067 / .split() .reverse() .join()
Last active March 2, 2019 04:44
1) Tách String thành Array. 2) Đảo ngược Array. 3) Đưa Array về String
// .split();
//=>String -> Array
var str = 'Tran Duc Linh';
var words = str.split(' ');
console.log(words[2]);
// "Linh"
// Khi tạo khoảng trắng bên trong ngoặc đơn, mỗi index là 1 cụm từ.
var chars = str.split('');
console.log(chars[5]);
// "D"
//MAP
let arr1 = [1,2,4];
let arr2 = arr1.map(X=>X*2);
console.log(arr2); //[2, 4, 8]
console.log(arr1); //[1, 2, 4]
//Việc thực thi mảng sẽ diễn ra theo trình tự clone rồi mới sửa (tránh phá nát mảng ban đâu), sau đó đưa kết quả cho arr2.
//FILTER
let arr1 = [1,2,4];
let arr2 = arr1.filter(X=>X>3);
@tranduclinh2067
tranduclinh2067 / Destructuring Assignment ES6 ++
Created January 12, 2019 04:22
Bạn muốn lấy các phần tử còn lại có trong mảng?
const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];
console.log(a, b); // 1, 2
console.log(arr); // [3, 4, 5, 7]
// => a = [0], tương tự vậy b[1], nhưng ...arr sẽ lấy hết các phần còn lại bao gồm arr[n++] tiếp theo sau đó.
@tranduclinh2067
tranduclinh2067 / Destructuring Assignment ES6
Last active January 12, 2019 04:06
Phân tách cơ cấu
// Tách các phần tử của Array hoặc Object thành nhiều biến chỉ bằng một đoạn code duy nhất.
//Array [a,b,c]
let date_Array = [20,06,1997]
let [,, c] = date_Array;
console.log(c);
//Object {d,m,y}
let date_Object = { day : 20, month : 06, year : 1997 }
let {day : d, month : m, year : y} = date_Object;
var abc = ['a','b','c'], def = ['d','e','f'];
var sum = [...abc, ...def];
console.log(sum);
//Result: ["a", "b", "c", "d", "e", "f"]