Skip to content

Instantly share code, notes, and snippets.

View katopz's full-sized avatar
🦀
Rust me if you can

Todsaporn Banjerdkit katopz

🦀
Rust me if you can
View GitHub Profile
@katopz
katopz / lazy-sd.md
Last active September 11, 2023 02:51
lazy download for sd

Get all d/l link as curl

Step

  1. open https://huggingface.co/lllyasviel/sd_control_collection/tree/main
  2. Run below code in browser console
let temp='';
document.querySelectorAll('a[href*="/resolve/"][href$=".safetensors"]').forEach(link => {
    const href = new URL(window.location.href).origin + link.getAttribute('href');
    temp+=`curl -OJL "${href}"\n`
@katopz
katopz / change-window-title.js
Created November 16, 2022 15:46
change header title tab to some element every second
// https://www.investing.com/currencies/usd-thb
setInterval(()=>{window.document.title = document.querySelectorAll('span[data-test=instrument-price-last]')[0].innerText}, 1000);
@katopz
katopz / regular-expression.md
Last active December 7, 2022 04:29
handy regular expression

Find 3 space before any word.

^\s{3}(?=\w)

Find text between tag <h2>$1.1</h2>

const matched_values = text.match(/(">\$)(.*?)</gm)
const value = matched_values.length === 3 ? matched_values[2] : NaN
@katopz
katopz / youtube-hd.js
Last active August 7, 2022 01:37
keep youtube at hi resolution
// https://gist.github.com/adisib/1e6b429b9bb630fceb170f3fa77c57a3
let ytPlayer = document.getElementById("movie_player") || document.getElementsByClassName("html5-video-player")[0];
let quality = ytPlayer.getAvailableQualityLevels()[0];
ytPlayer.stopVideo();
ytPlayer.setPlaybackQualityRange && ytPlayer.setPlaybackQualityRange(quality)
ytPlayer.setPlaybackQuality(quality);
let storedQuality = localStorage.getItem('yt-player-quality')
if (!storedQuality || storedQuality.indexOf(quality) === -1) {
let tc = Date.now(),
@katopz
katopz / force-push.sh
Created October 8, 2020 17:22
Force push on main from head (or other branch) // consider bad practice but sudo it ;p
# Switch main to head
git branch -f main head
# Force push
git push -f origin main
@katopz
katopz / postgres-restore-docker
Created September 26, 2020 04:53
Restore postgres from backup file in docker
docker run --name foo-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker inspect -f '{{ json .Mounts }}' foo-postgres | python -m json.tool
```
[
{
"Destination": "/var/lib/postgresql/data",
"Driver": "local",
"Mode": "",
"Name": "8ce3df1ef910ec01686401a1fc8cdfff729aa2cd88ccac852c436badab7f3dea",
@katopz
katopz / photopea-hide-ads.md
Last active April 16, 2024 04:48
How to hide photopea ads

Open console and run this for 0px width ads. (ads still working, adjust width size to suite your need)

document.querySelector("body > div.flexrow.app > div:nth-child(2)").setAttribute('style','max-width:0px')

document.querySelector("body > div.flexrow.app > div").setAttribute('style','width:100%')
document.querySelector("body > div.flexrow.app > div > div.flexrow > div.panelblock.mainblock").setAttribute('style','width:100%')
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.fixme { min-width:fit-content;overflow:unset; }';
document.querySelector("body > div.flexrow.app > div:nth-child(1) > div.flexrow").appendChild(style)
@katopz
katopz / netflix-fixer.md
Created August 2, 2020 15:01
A fix for Netflix's issue subtitles cause the screen colours to change

Open dev console and run this

document.querySelector(".AkiraPlayer").insertAdjacentHTML('beforebegin', `<div style="
    position: absolute;
    z-index: 999;
    color: black;
    background-color: black;
    width: 1px;
    height: 1px;
 display: block;
@katopz
katopz / bq-del-dedup.md
Created August 1, 2020 16:05
BigQuery delete deduplication
@katopz
katopz / nl-kbtg-json2csv.js
Created April 17, 2020 10:28
nl-kbtg-json2csv
fetch('https://covid19.th-stat.com/api/open/timeline')
.then(response => response.json())
.then(json => {
const header = Object.keys(json.Data.shift()).join(',')
const data = json.Data.map(e=>Object.values(e).join(',')).join('\n')
console.log(header + '\n' + data)
})