Skip to content

Instantly share code, notes, and snippets.

@NaClYen
NaClYen / all_in_one.js
Last active October 21, 2021 09:47
JS - url search params to dictionary
let dict = Array.from(new URLSearchParams(window.location.search)).reduce(
(d, [k, v]) => {
d[k] = v;
return d;
},
{}
);
@NaClYen
NaClYen / startup.sh
Created October 22, 2021 10:17
typescript-rollup-startup
yarn init
yarn -D typescript tslib @rollup/plugin-typescript
mkdir src
@NaClYen
NaClYen / test.js
Created October 27, 2021 03:41
nodejs - execute js file
const fs = require('fs')
const rawdata = fs.readFileSync('./path/to/file_with.anyext', 'utf8')
eval(rawdata)
@NaClYen
NaClYen / demo.ps1
Last active November 17, 2021 07:27
powershell find alias by keyword
# find DisplayName related to 'alias'
Find-Alias alias
@NaClYen
NaClYen / demo.ps1
Last active November 17, 2021 07:29
powershell get file lines for huge file
Get-File-Lines ./my.log
@NaClYen
NaClYen / read-line-by-line.js
Created November 19, 2021 03:21
nodejs read file line by line with built-in readline and fs
const readline = require("readline");
const fs = require("fs");
const input = fs.createReadStream("my.log", {
encoding: "utf-8",
});
const rl = readline.createInterface(input);
rl.on("line", (line) => {
@NaClYen
NaClYen / wait-test.ps1
Created November 22, 2021 07:49
powershell Wait-Job for multi jobs
function Wait-Test {
$a = Start-Job -ScriptBlock { ping 8.8.8.8 }
$b = Start-Job -ScriptBlock { echo "test" }
Wait-Job $a,$b
echo "done"
}
@NaClYen
NaClYen / test.js
Created December 7, 2021 06:09
fetch post json
fetch('http://localhost:8888/test', {
method: 'POST',
body: JSON.stringify({ name: 'NaCl' }),
headers: {
'content-type': 'application/json'
}
})