Skip to content

Instantly share code, notes, and snippets.

Avatar

szabolcs kurdi szkrd

  • tralfamadore
View GitHub Profile
@szkrd
szkrd / forward-rot.js
Last active Mar 2, 2022
bi-directional port forwarding with a dumb rot13 cypher
View forward-rot.js
// this is a very simple implementation of rot13 cypher over sockets, to avoid primitive
// deep packet inspection (https://gist.github.com/gmurdocca/88857b58dc4668d88b0d0fae6ebf8b64);
// a more robust solution would be to use obs4 (https://github.com/Yawning/obfs4), which
// implements the ScrambleSuit protocol as a tor transport plugin with a standalone
// runner/wrapper (for example https://github.com/twisteroidambassador/ptadapter in python)
const net = require('net');
const parseIpPort = (s = '') => ({ ip: s.split(':')[0], port: parseInt(s.split(':')[1], 10) });
const addrs = { from: parseIpPort(process.argv[2]), to: parseIpPort(process.argv[3]) };
const ports = { from: addrs.from.port, to: addrs.to.port }
const hosts = { from: addrs.from.ip, to: addrs.to.ip }
@szkrd
szkrd / forward.js
Created Feb 22, 2022
Wait for interface to come up then start forwarder to local server (windows).
View forward.js
const net = require('net');
const spawn = require('child_process').spawn;
const ports = [80, 5000];
const sleepSecs = 30;
const interfaceMatcher = /(169\.254\.[\d\.]+)/;
function doForward(listenInterface = '0.0.0.0') {
const server = net.createServer(function (from) {
const to = net.createConnection({ host: '127.0.0.1', port: ports[1] });
from.pipe(to).on('error', (err) => console.log('from error', err.code));
@szkrd
szkrd / md2pdf.js
Last active Dec 9, 2021
convert markdown to pdf using puppeteer
View md2pdf.js
// first: `npm init -- yes && npm i -S showdown@1.9.1 github-markdown-css@5.1.0 serve@13.0.2 puppeteer-core`
// then: `node . --help`
const fs = require('fs');
const http = require('http');
const puppeteer = require('puppeteer-core');
const showdown = require('showdown');
const githubMarkdownCss = fs.readFileSync(require.resolve('github-markdown-css'), 'utf8');
const handler = require('serve-handler'); // without serve loading local files, like images, would not be possible
const die = (text = '', code = 1) => process.exit(~~console.error(text) + code);
@szkrd
szkrd / xiaomi-redmi-4x-unlock.md
Created Aug 10, 2021
Xiaomi Redmi 4x unlock, lineage install and root
View xiaomi-redmi-4x-unlock.md

Unlock Xiaomi Redmi 4X (santoni) and install Lineage OS via sideloading

So far the most useful documentation was at Lineage's Redmi section, random "mobile enthusiast" sites were "not very good" and youtube videos are to be avoided like the plague.

Files needed

  • SDK platform tools from android.com
  • mi flash unlock gui tool (miflash_unlock-en-5.5.224.24.zip)
  • newest twrp for device (twrp-3.5.2_9-0-santoni.img), from twrp site
@szkrd
szkrd / watch-log.js
Created Jul 5, 2021
watch for changes in a log file in a memory efficient way (like tail -f)
View watch-log.js
// npm init --yes && npm i -S chalk chokidar split
const fs = require("fs");
const { stat } = require("fs").promises;
const { red, cyan } = require("chalk");
const chokidar = require("chokidar");
const split = require("split");
let config = require("./config.json"); // { okPattern: string, nokPattern: string, logFile: string }
try {
config = require("./config.user.json");
} catch (err) {}
@szkrd
szkrd / youtube-listen.js
Created Mar 7, 2021
Listen to a youtube stream in puppeteer (headless chrome/chromium). By default plays Chillcow's channel, works on linux and windows, clicks on all the popup crap.
View youtube-listen.js
// first: `npm init -- yes && npm i chalk puppeteer-core`
// then: `node . --help`
const puppeteer = require('puppeteer-core');
const chalk = require('chalk');
// ---
const ifHasParam = (s = '') => process.argv.includes(s);
const paramValueOf = (s = '') => (process.argv.find(x => x.startsWith(`${s}=`)) || '').split('=')[1];
const DEFAULT_VIDEO_ID = '5qap5aO4i9A'; // ChillCow; his other channel is "DWcJFNfaw9c"
const DEBUG = ifHasParam('--debug');
const SHOW_HEAD = ifHasParam('--head');
@szkrd
szkrd / taskbar.au3
Last active Jan 31, 2021
Calling a dll with autoit
View taskbar.au3
Func ToggleTaskbarAutohide($hide = False)
; this is the message id (from nf-shellapi-shappbarmessage documentation page at microsoft.com)
Local Static $ABM_SETSTATE = 0xA
; these two are message payloads, probably defined as constants in the dll / c lib itself
; a list could be found here: https://stackoverflow.com/a/44746235
Local Static $ABS_AUTOHIDE = 1, $ABS_ALWAYSONTOP = 2
; appbardata will be filled with the results (or prefilled with the input),
; the SHAppBarMessage documentation tells us how it looks:
@szkrd
szkrd / bookmarks-json-to-md.js
Created Jan 4, 2021
convert pinboard exported bookmarks json to markdown
View bookmarks-json-to-md.js
const fs = require('fs');
const source = require('./pinboard_export.json');
const uniq = (value, index, self) => self.indexOf(value) === index;
let text = '';
source.forEach(bkm => {
text += `## ${bkm.description}\n`;
if (bkm.extended) text += `${bkm.extended}\n`
text += `${bkm.href}\n`
if (bkm.tags) {
const tags = bkm.tags.split(' ').map(t => {
@szkrd
szkrd / test-utils-json.js
Created Sep 17, 2020
Make json snapshots less painful: replace functions/classes with their names (if possible), convert dates to numbers, remove undefined enumerable properties
View test-utils-json.js
function logObject(obj) {
let result = JSON.stringify(obj, null, 2);
let hr = '';
for (let i = 0; i < 80; i++) { hr += '-'; }
const lines = result.split('\n');
result = lines.map(line => line.replace(/^(\s+)"([a-zA-Z0-9_$]*)"/, '$1$2')).join('\n');
console.log(`${hr}{{{\n${result}\n}}}${hr}`);
}
function stringifyComplexObjects(obj) {
@szkrd
szkrd / huskify.sh
Last active Jul 14, 2020
force install husky (probably v4.x only)
View huskify.sh
#!/usr/bin/env bash
function addHook() {
echo -e "#!/bin/sh\n# husky" > .git/hooks/$1
echo '. "$(dirname "$0")/husky.sh"' >> .git/hooks/$1
chmod +x .git/hooks/$1
}
DIRNAME="$(basename "${PWD}")"
if [ "${DIRNAME}" = 'server' ] || [ "${DIRNAME}" = 'client' ]; then echo "Do not run this script in the server/client subdir!"; exit 1; fi
if [ ! -f ./node_modules/husky/package.json ]; then echo "Project has no husky?"; exit 2; fi