Skip to content

Instantly share code, notes, and snippets.

View hungngocphat01's full-sized avatar

Hung Ngoc Phat hungngocphat01

  • Japan Advanced Institute of Science and Technology
  • Hometown of 蓮ノ空
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
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,"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
@hungngocphat01
hungngocphat01 / escrotum-wrapper.sh
Created August 14, 2021 15:28
A simple wrapper for escrotum
#!/usr/bin/zsh
if [[ $1 == "current_window" ]] then;
bc <<< "ibase=16; $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | sed 's/.*0x//')" | xargs escrotum -Cx
elif [[ $1 == "whole_screen" ]] then;
escrotum -C
elif [[ $1 == "partial" ]] then;
escrotum -sC
fi;
notify-send "Screenshot captured!"
@hungngocphat01
hungngocphat01 / darwin-man.txt
Last active August 7, 2021 07:02
Output of 2 first lines of manpage for every macOS commands in /usr/bin
Output of the first 2 lines of manpage for every macOS Big Sur 11.1 commands in /usr/bin, most of which are titled "BSD xxx Commands Manual", which implies that OSX uses BSD's implementation for its basic UNIX commands.
AssetCacheLocatorUtil(8) BSD System Manager's Manual AssetCacheLocatorUtil(8)
AssetCacheManagerUtil(8) BSD System Manager's Manual AssetCacheManagerUtil(8)
AssetCacheTetheratorUt... BSD System Manager's ManualAssetCacheTetheratorUt...
DeRez(1) DeRez(1)