Skip to content

Instantly share code, notes, and snippets.

View winguse's full-sized avatar
🎣
fishing

Yingyu Cheng winguse

🎣
fishing
View GitHub Profile
const asyncHooks = require('async_hooks');
const contextStore = new Map();
class Context {
constructor() {
this.id = Math.random();
}
}
@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
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 / 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
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 / 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}`;
@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]);
} : () => {};
}

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:

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 },
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