Skip to content

Instantly share code, notes, and snippets.

View hungngocphat01's full-sized avatar

Ngọc Phát hungngocphat01

View GitHub Profile
from typing import Optional
from dataclasses import dataclass, field
@dataclass
class Reservation:
start: int
end: int
def overlap(self, other: "Reservation") -> bool:
return not (
@hungngocphat01
hungngocphat01 / python_dark_magics.md
Last active November 22, 2023 08:35
My collection of Python dark magics

Generic types

from typing import Generic, get_args

_T = TypeVar("_T")

class SomeClass(Generic[_T]):
  def __init__(self, x: _T):
    self.x = x
#!/bin/bash
export MODEL=/workspace/stable-diffusion-webui/models
function download_array() {
url_arr=("$@")
for url in ${url_arr[@]}; do
wget --content-disposition $url
done
}
document.querySelector(".hls-player_message").remove();
var subtitleCanvasElem = document.querySelector(".hls-player_in-subtitle");
subtitleCanvasElem.style.height = "70%";
subtitleCanvasElem.style.width = "70%";
subtitleCanvasElem.style.top = "unset";
// To use on mobile:
// javascript:(function () { document.querySelector(".hls-player_message").remove(); var subtitleCanvasElem = document.querySelector(".hls-player_in-subtitle"); subtitleCanvasElem.style.height = "70%"; subtitleCanvasElem.style.width = "70%"; subtitleCanvasElem.style.top = "unset"; })();
fixed acidity volatile acidity citric acid residual sugar chlorides free sulfur dioxide total sulfur dioxide density pH sulphates alcohol quality
7.4 0.7 0.0 1.9 0.076 11.0 34.0 0.9978 3.51 0.56 9.4 5
7.8 0.88 0.0 2.6 0.098 25.0 67.0 0.9968 3.2 0.68 9.8 5
7.8 0.76 0.04 2.3 0.092 15.0 54.0 0.997 3.26 0.65 9.8 5
11.2 0.28 0.56 1.9 0.075 17.0 60.0 0.998 3.16 0.58 9.8 6
7.4 0.7 0.0 1.9 0.076 11.0 34.0 0.9978 3.51 0.56 9.4 5
7.4 0.66 0.0 1.8 0.075 13.0 40.0 0.9978 3.51 0.56 9.4 5
7.9 0.6 0.06 1.6 0.069 15.0 59.0 0.9964 3.3 0.46 9.4 5
7.3 0.65 0.0 1.2 0.065 15.0 21.0 0.9946 3.39 0.47 10.0 7
7.8 0.58 0.02 2.0 0.073 9.0 18.0 0.9968 3.36 0.57 9.5 7
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 6.
"Country,Other",TotalCases,NewCases,TotalDeaths,NewDeaths,TotalRecovered,NewRecovered,ActiveCases,"Serious,Critical",TotalCases/1M pop,Deaths/1M pop,TotalTests,Test/1M pop,Population,Continent,1 Caseevery X ppl,1 Deathevery X ppl,1 Testevery X ppl,New Cases/1M pop,New Deaths/1M pop,Active Cases/1M pop
World,"507,654,954","+810,560","6,235,976","+3,289","459,911,989","+944,409","41,506,989","41,828","65,127",800.0,,,,All,"
",,,,,
China,"193,953","+2,841","4,663 ",+8,"157,869","+2,185","31,421",223,135,3,"160,000,000","111,163","1,439,323,776 ",Asia,"7,421","308,669",9,2,0.01,22
USA,"82,553,058","+45,204","1,017,609 ",+299,"80,355,389","+34,592","1,180,060","1,492","246,798","3,042","999,047,824","2,986,727","334,495,877 ",North America,4,329,0,135,0.9,"3,528"
India,"43,050,877",+903,"522,095 ",+33,"42,514,479",,"14,303",698,"30,654",372,"833,377,052","593,395","1,404,421,106 ",Asia,33,"2,690",2,0.6,0.02,10
Brazil,"30,330,629","+18,660","662,556 ",+86,"29,353,398","+12,596","314,675","8,318","140,890","3,078","
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 6.
"Country,Other",TotalCases,NewCases,TotalDeaths,NewDeaths,TotalRecovered,NewRecovered,ActiveCases,"Serious,Critical",TotalCases/1M pop,Deaths/1M pop,TotalTests,Test/1M pop,Population,Continent,1 Caseevery X ppl,1 Deathevery X ppl,1 Testevery X ppl,New Cases/1M pop,New Deaths/1M pop,Active Cases/1M pop
World,"506,844,394","+911,616","6,232,687","+3,310","458,967,580","+1,041,446","41,644,127","41,786","65,023",799.6,,,,All,"
",,,,,
China,"191,112","+2,761","4,655 ",+7,"155,684","+2,365","30,773",116,133,3,"160,000,000","111,163","1,439,323,776 ",Asia,"7,531","309,200",9,2,,21
USA,"82,507,854","+50,881","1,017,310 ",+440,"80,320,797","+36,111","1,169,747","1,514","246,663","3,041","998,630,495","2,985,479","334,495,877 ",North America,4,329,0,152,1,"3,497"
India,"43,049,974","+2,380","522,062 ",+56,"42,514,479","+1,231","13,433",698,"30,653",372,"832,927,938","593,076","1,404,421,106 ",Asia,33,"2,690",2,2,0.04,10
Brazil,"30,311,969","+32,699","662,470 ",+204,"29,340,802","+41,954","308,697","8,318","140,803","3

Cách cài đặt Zalo PC trên Linux

Cập nhật: Tháng 3 năm 2022.
Các lệnh liên quan đến cài đặt được viết cho Arch Linux. Người đọc tự nghiên cứu cách cài đặt wine cho các distro khác như Ubuntu.

Phiên bản Wine đã thử: 7.0.

Chuẩn bị

  1. Kiến thức căn bản về Linux.
  2. File exe cài đặt Zalo: tải từ web Zalo như bình thường. Có thể đổi user agent của trình duyệt để tải được, hoặc sử dụng Windows tải rồi copy sang.
@hungngocphat01
hungngocphat01 / hcmus-portal-tinhdiem.js
Last active February 19, 2022 05:46
Script tính điểm TB tích lũy trên portal HCMUS. Cần chọn "Tất cả" ở trường Năm học trước khi chạy.
// Lay diem
let rows = document.querySelectorAll('#tbDiemThiGK > tbody > tr')
rows = Array.from(rows).map(row => Array.from(row.querySelectorAll('td')).map(
cell => cell.innerHTML.trim()
));
// Transform, loai bo mon trung
const dataRows = [];
for (const row of rows) {
const mon = { ten: row[1], tinchi: Number.parseInt(row[2]), diem: Number.parseFloat(row[5]) };

Prerequisites

  • Windows fonts (grab them from e.g. an existing Windows installation or iso image).
  • A list of neccessary Windows fonts (I made a list of core fonts below, exluding region specific fonts like Thai, Japanese, etc.).

Steps

  • Copy all Windows fonts and the font list file into a folder.
  • Create a directory for Windows fonts.
$ mkdir -p ~/.local/share/fonts/Windows