Skip to content

Instantly share code, notes, and snippets.

Avatar
🎣
fishing

Yingyu Cheng winguse

🎣
fishing
View GitHub Profile
View youtube-dl-server.js
const http = require('http');
const { spawn } = require('child_process');
const jobs = {};
setInterval(() => {
Object.keys(jobs).forEach(url => {
const {ts} = jobs[url];
if (Date.now() - ts > 24 * 3600 * 1000) {
delete jobs[url];
View network-conf.sh
#!/bin/sh
echo '
net.core.wmem_max = 12582912
net.core.rmem_max = 12582912
net.ipv4.tcp_rmem = 10240 87380 12582912
net.ipv4.tcp_wmem = 10240 87380 12582912
net.ipv4.tcp_window_scaling = 1
@winguse
winguse / create_place_holder.js
Last active Jul 1, 2020
copy and paste this in your browsers' console...
View create_place_holder.js
const walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
const delay = [];
while (true) {
const node = walk.nextNode();
if (!node) break;
if (!node.textContent.trim()) continue;
const { parentElement } = node;
if (parentElement.tagName === 'STYLE') continue;
const { color, display } = getComputedStyle(parentElement);
if (display === 'inline') {
View get-routes.js
const fs = require('fs')
const http = require('http');
// https://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest
// https://ftp.apnic.net/stats/apnic/delegated-apnic-latest
/**
* get content from URL
* @param {String} url URL
* @returns {Promise<String>} the response body of input URL
View hammerspoon-simple-tilling.lua
local timer=require'hs.timer'
local checkMods=require'hs.eventtap'.checkKeyboardModifiers
local function modsPressed() return checkMods(true)._raw>0 end
local frontWindows = {}
local frontFocusIdx = 0
local modes = {
full = { 1 },
half = { 0.5, 0.5 },
View keybase.md

Keybase proof

I hereby claim:

  • I am winguse on github.
  • I am winguse (https://keybase.io/winguse) on keybase.
  • I have a public key whose fingerprint is 66DE FC48 E0A1 9969 AB1F 97A1 C985 F630 4EC9 1173

To claim this, I am signing this object:

@winguse
winguse / flac2alac.bash
Created Jan 12, 2020 — forked from yenliangl/flac2alac.bash
Convert flac to Alac (Apple Lossless Audio Codec)
View flac2alac.bash
# 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 Dec 3, 2019
minium log implementation
View log.js
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]);
} : () => {};
}
View ip-range.js
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}`;
View re-random.js
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() {