Skip to content

Instantly share code, notes, and snippets.

View RealYukiSan's full-sized avatar
👀
Observing the pattern

Yuki San RealYukiSan

👀
Observing the pattern
View GitHub Profile
@RealYukiSan
RealYukiSan / arch.md
Last active April 20, 2024 01:05
Start Guest OS on QEMU

Live Boot arch linux:

qemu-system-x86_64 \
-drive format=raw,file=./archlinux-2024.04.01-x86_64.iso,index=0,media=disk \
-enable-kvm -machine pc -cpu host -m 1G -nographic

Since the above command using -nographic, so we don't start VNC server, thus don't forget to add console=ttyS0 to kernel parameter, press on the bootloader to modify kernel parameter

not related link:

@RealYukiSan
RealYukiSan / note.md
Last active April 21, 2024 12:36
Play with linux system on QEMU

The idea came from Nir Lichtman video with the title: 'Making Simple Linux Distro from Scratch'

this gist just re-document it in the form of text

Requirement

  • compiled linux kernel
  • compiled static-linked busybox
  • installed qemu

Creating initramfs

@RealYukiSan
RealYukiSan / shell.js
Created April 11, 2024 07:21
use sh inside javascript
const { spawn } = require('node:child_process')
const readline = require('node:readline');
const { stdin: input, stdout: output } = require('node:process');
const rl = readline.createInterface({ input, output });
const shell = spawn('sh')
shell.stdout.on('data', (data) => {
process.stdout.write(data.toString())
@RealYukiSan
RealYukiSan / node-http.js
Created April 11, 2024 03:33
retry mechanism
const { get } = require("node:https")
require('dotenv').config();
function fetch(url) {
return new Promise((resolve, reject) => {
get(url, (res) => {
let buff = Buffer.alloc(0);
res.on("data", chunk => buff = Buffer.concat([buff, Buffer.from(chunk)]))
res.on("error", reject)
res.on("end", () => resolve(buff))
@RealYukiSan
RealYukiSan / note.md
Last active April 11, 2024 09:37
run ngrok in background

start the program in background

setsid ngrok tcp <port> &>/dev/null </dev/null

optional, if you want store the log, enable ngrok option --log=stdout

parse the json string with node

node -pe 'JSON.parse(process.argv[1])' $(curl -s http://localhost:4040/api/tunnels)
# atau
@RealYukiSan
RealYukiSan / async-node-https-get.js
Last active April 11, 2024 12:34
fetch telegram sticker
const { get } = require("node:https");
(async () => {
const stickerName = ['Elaina_san', 'bagasgoyang']
const token = "bot7003873933:AAFKl0LwWViMJIA34-qjbTh7nZwcNQr2hFs"
const domain = "https://api.telegram.org"
const file_baseurl = `${domain}/file/${token}`
const api_baseurl = `${domain}/${token}`
stickerName.forEach(async (name) => {
@RealYukiSan
RealYukiSan / time.sh
Last active April 10, 2024 02:21
Useful command to remind you about time
#!/usr/bin/sh
watch -n 0.1 "date +\"%d-%m-%Y %H:%M:%S.%9N\""
@RealYukiSan
RealYukiSan / alert-lowbat.sh
Last active April 17, 2024 02:40
auto shutdown on low battery
#!/bin/sh
threshold=10 # threshold percentage to trigger alert
while :; do
capacity=$(cat /sys/class/power_supply/BAT1/capacity)
# If battery is discharging with capacity below threshold
if [ "${capacity}" -lt ${threshold} ];then
# Send a notification that appears for 300000 ms (5 min)
@RealYukiSan
RealYukiSan / client.js
Created March 29, 2024 15:19
Tried simple websocket communication
const socket = new WebSocket("ws://localhost:8080")
socket.onopen = function (e) {
alert('[open] connection established')
alert('sending data to server')
socket.send('My name is who am i?');
}
socket.onmessage = function (ev) {
alert(`[message] data received from srv: ${ev.data}`);
@RealYukiSan
RealYukiSan / redsocks.rules
Created March 23, 2024 13:04
iptables rules for redsocks
# Transparent SOCKS proxy
# See: http://darkk.net.ru/redsocks/
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:REDSOCKS - [0:0]