Skip to content

Instantly share code, notes, and snippets.

View wermarter's full-sized avatar
🐹
lọ mọ

Hà Minh Chiến wermarter

🐹
lọ mọ
View GitHub Profile
ip addr show eth0 | grep inet
netsh interface portproxy add v4tov4 listenport=2200 listenaddress=0.0.0.0 connectport=2200 connectaddress=172.22.43.247
@wermarter
wermarter / half-close.js
Created September 24, 2024 04:46
NodeJS TCP half-close
const net = require('net')
const server = net.createServer({ allowHalfOpen: true }, (socket) => {
socket.on('data', (data) => {
console.log('Server <-', data.toString())
if (!socket.writableFinished) {
socket.write('hello')
console.log('Server -> hello')
// half-close
socket.end()
Array(300_000_000).fill(1)
@wermarter
wermarter / parent_dir.sh
Created October 14, 2023 02:05
find current dir and parent dir of running script
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PARENT_DIR=$( dirname $SCRIPT_DIR )
@wermarter
wermarter / generator.js
Created September 27, 2023 02:13
javascript generator vs stream API
const nReadlines = require("n-readlines");
const fs = require("fs");
const events = require('events');
main().then(() => {
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(
`The script uses approximately ${Math.round(used * 100) / 100} MB`
);
@wermarter
wermarter / ssh.bat
Created July 16, 2023 01:50
"remote.SSH.path": "C:\\ssh.bat"
C:\Windows\system32\wsl.exe ssh %*
@wermarter
wermarter / main.ts
Created May 26, 2023 02:50
nestjs-cargo-queue
export class BaseWorkerService<TaskInput, TaskOutput> {
private queue: QueueObject<TaskInput>;
private logger: Logger;
private workCounter = 0;
constructor(
workerName: string,
concurrency: number,
batchSize: number,
batchProcessor: (input: TaskInput[]) => Promise<TaskOutput[]>,
@wermarter
wermarter / timeout_function.js
Last active November 18, 2021 12:05
Timeout function execution
const timeout_function = async (func, timeLimit) => {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
console.log("Timeout reached");
reject(null);
}, timeLimit);
const result = func();
resolve(result);
@wermarter
wermarter / recode.py
Created December 19, 2017 02:03
Using FFMPEG to recode to 480p from text file contains list of dir
import os
from TheFetchers.TheCommons import filename_check
with open(input('> '), 'r') as f:
files = [i.strip() for i in f.readlines()]
for file in files:
fn = os.path.splitext(file)[0]+'.mp4'
output_file = filename_check(fn, True)
cmd = "ffmpeg -i \"%s\" -vf scale=-2:480 -c:v libx264 \"%s\"" % (file, output_file)
os.system(cmd)
import origami
APP_TOKEN = "nongh::2113789:5001:8000:54.158.186.33"
app = origami.register(APP_TOKEN)
@origami.crossdomain
@app.listen()
def concat():
allText = origami.getTextArray()