Skip to content

Instantly share code, notes, and snippets.

@NaClYen
NaClYen / download-file-in-web.js
Created Jun 28, 2022
auto download file in web
View download-file-in-web.js
function download(source) {
const fileName = source.split("/").pop();
let el = document.createElement("a");
el.setAttribute("href", source);
el.setAttribute("download", fileName);
document.body.appendChild(el);
el.click();
el.remove();
}
@NaClYen
NaClYen / auto-click.py
Created Jan 22, 2022
py auto mouse click
View auto-click.py
# press Esc to exit app
# click mouse mid button to switch working
from operator import eq
import time
from pynput.mouse import Button, Controller
from pynput import mouse
from pynput import keyboard
mouseCtrl = Controller()
@NaClYen
NaClYen / restore.js
Created Jan 21, 2022
restore console log/warn/error/trace ...etc in chrome
View restore.js
// 概念就是導向新的 iframe 裡面去, 金夭壽XDD
// https://stackoverflow.com/a/7089553/6573523
var i = document.createElement('iframe');
i.style.display = 'none';
document.body.appendChild(i);
window.console = i.contentWindow.console;
@NaClYen
NaClYen / update_query.py
Created Jan 13, 2022
add/update URL query
View update_query.py
# ref: https://stackoverflow.com/questions/2506379/add-params-to-given-url-in-python
import urllib.parse as urlparse
from urllib.parse import urlencode
url = "http://home.your/echo?id=22"
data = {'name': 'nacl', 'age': 18}
# 轉換並拆解成陣列
url_parts = list(urlparse.urlparse(url))
@NaClYen
NaClYen / cat_style.sh
Last active Dec 16, 2021
shell write formatted text file with environment variables
View cat_style.sh
#!/bin/sh
cat <<EOF >/path/to/config.json
{ "ip": "$ip"}
EOF
@NaClYen
NaClYen / upload_file.js
Created Dec 10, 2021
javascript upload string blob as file
View upload_file.js
function upload(txt) {
// wrapper by Blob
const blob = new Blob([txt], { type: "text/html" });
// warpper by File
const file = new File([blob], "test.plan");
const formData = new FormData();
formData.append("File", file);
fetch("http://localhost/upload", {
@NaClYen
NaClYen / create_array.js
Created Dec 10, 2021
javascript create array without for-loop
View create_array.js
// [1, 1, 1, 1, 1]
[...new Array(5)].map(() => 1)
// [0, 1, 2, 3, 4]
[...new Array(5)].map((_, index) => index)
@NaClYen
NaClYen / grep.ps1
Created Dec 8, 2021
windows powershell style grep
View grep.ps1
function grep {
$input | Out-String -Stream | Select-String -Pattern $args
}
@NaClYen
NaClYen / show.ps1
Created Dec 8, 2021
windows show powershell profile location
@NaClYen
NaClYen / test.js
Created Dec 7, 2021
fetch post json
View test.js
fetch('http://localhost:8888/test', {
method: 'POST',
body: JSON.stringify({ name: 'NaCl' }),
headers: {
'content-type': 'application/json'
}
})