Skip to content

Instantly share code, notes, and snippets.

View winguse's full-sized avatar
🎣
fishing

Yingyu Cheng winguse

🎣
fishing
View GitHub Profile
@winguse
winguse / flac2alac.bash
Created January 12, 2020 13:41 — forked from yenliangl/flac2alac.bash
Convert flac to Alac (Apple Lossless Audio Codec)
# convert flac files in current directory to Apple loss-less codec.
function flac2alac {
for f in *.flac; do
ffmpeg -i "$f" -acodec alac -vsync 2 -c:v copy -metadata COMMENT= -y "${f%.flac}.m4a"
#-map_meta_data $f:${f%.flac}.m4a;
done
}
@winguse
winguse / log.js
Created December 3, 2019 11:15
minium log implementation
const LOG_LEVELS = ['DEBUG', 'INFO', 'WARN', 'ERROR']
const [LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR] = LOG_LEVELS;
const LOG_LEVEL = LOG_DEBUG;
function makeLogFunc(level, func = console.log) {
return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(LOG_LEVEL) ? (...msg) => {
const now = new Date().toLocaleString();
func(...[now, level, ...msg]);
} : () => {};
}
@winguse
winguse / ip-range.js
Last active September 26, 2019 09:43
const fetch = require('node-fetch');
const { deepStrictEqual } = require('assert');
function ipv4ToInt(ip) {
return ip.split('.').reduce((acc, cur) => acc << 8 | +cur, 0);
}
function intToIpv4(i) {
return `${i >>> 24}.${i >>> 16 & 0xff}.${i >>> 8 & 0xff}.${i & 0xff}`;
const p = 0.723;
function oldRandom() {
return Math.random() < p ? 1 : 0;
}
const table = [[1, 2], [2, 3], [1, 3]];
let flag = 0;
function newRandom() {
@winguse
winguse / Application.scala
Created June 12, 2019 03:56
A simple CSV parser
object Application {
case class CsvLine(values: List[String] = Nil, inQuote: Boolean = false, buff: List[Char] = Nil)
@tailrec
def parseCsvLine(line: CsvLine, remains: List[Char]): List[String] = (line, remains) match {
case (CsvLine(values, false, buff), Nil) =>
values :+ buff.mkString
case (CsvLine(values, true, buff), '"' :: Nil) =>
values :+ buff.mkString
import java.util.{Timer, TimerTask}
import akka.actor.{Actor, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.concurrent.{Future, Promise}
import scala.util.Try
@winguse
winguse / Tenda U9 on linux.md
Last active October 20, 2023 09:40
Tenda U9 on linux

Two files:

  • /etc/usb_modeswitch.d/rtl8821cu
  • /usr/share/usb_modeswitch/0bda:1a2b
TargetVendor=0x0bda
TargetProduct=0x1a2b
StandardEject=1
@winguse
winguse / drop_rst.sh
Created November 19, 2018 13:09
drop rst package in router. 50% works under gfw
ip6tables -A FORWARD -p tcp --tcp-flags RST RST -j DROP
iptables -A FORWARD -p tcp --tcp-flags RST RST -j DROP
const asyncHooks = require('async_hooks');
const contextStore = new Map();
class Context {
constructor() {
this.id = Math.random();
}
}
/* ------------ monkey patching ------------ */
const http = require('http')
const originalServerEmit = http.Server.prototype.emit;
http.Server.prototype.emit = function (event) {
if (event === 'request') {
// setup the context here as the root of the execution tree
setContext();
}
return originalServerEmit.apply(this, arguments)