├── websocket-terminal ├── dist │ └── .gitignore ├── package.json ├── index.html ├── webpack.config.js ├── src │ └── entry.js └── index.js ├── simple-sshd ├── .gitignore ├── Makefile ├── README.md └── server.cpp ├── websocket-terminal-cpp-server ├── exec.sh ├── frontend.hpp ├── pty.hpp ├── base64.hpp ├── Makefile ├── sha1.hpp ├── pty.cpp ├── frontend.html ├── http.hpp ├── ws.hpp ├── base64.cpp ├── http.cpp ├── frontend.h ├── main.cpp ├── sha1.cpp └── ws.cpp ├── Daemon ├── Daemon │ ├── Resources │ │ └── icon.ico │ ├── App.config │ ├── Properties │ │ ├── Settings.settings │ │ ├── Settings.Designer.cs │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ └── Resources.resx │ ├── App.xaml │ ├── App.xaml.cs │ ├── MainWindow.xaml │ ├── Daemon.csproj │ └── MainWindow.xaml.cs └── Daemon.sln ├── bandwidth ├── package.json ├── README.md └── index.js ├── reversi ├── package.json ├── dist │ └── index.html └── index.js ├── azure-ddns ├── package.json └── index.js ├── music-read-trans ├── package.json ├── webpack.config.js ├── index.html └── src │ └── entry.js ├── flac-player-sdl ├── README.md ├── Makefile └── main.cpp ├── pcap-port-statistics ├── README.md └── main.cpp ├── wav-decode ├── README.md ├── index.html └── main.js ├── README.md ├── bilibili-regular-block └── tv.bilibili.player.xml └── .gitignore /websocket-terminal/dist/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple-sshd/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | server 3 | ssh 4 | .vscode -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export TERM=xterm-256color 4 | 5 | /bin/bash --login -------------------------------------------------------------------------------- /Daemon/Daemon/Resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ntzyz/playground/HEAD/Daemon/Daemon/Resources/icon.ico -------------------------------------------------------------------------------- /bandwidth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "pcap": "https://github.com/mranney/node_pcap.git" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /reversi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "express": "^4.16.4", 4 | "socket.io": "^2.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/frontend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern unsigned char frontend_html[]; 4 | extern unsigned int frontend_html_len; 5 | -------------------------------------------------------------------------------- /azure-ddns/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "azure-arm-dns": "^3.2.0", 4 | "express": "^4.16.4", 5 | "ms-rest-azure": "^2.6.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/pty.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct pty_t { 4 | bool ready = false; 5 | int master_fd; 6 | 7 | pty_t(); 8 | void spawn(); 9 | ~pty_t(); 10 | }; -------------------------------------------------------------------------------- /music-read-trans/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "vexflow": "^1.2.90", 4 | "webpack": "^4.41.6" 5 | }, 6 | "devDependencies": { 7 | "webpack-cli": "^3.3.11" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /flac-player-sdl/README.md: -------------------------------------------------------------------------------- 1 | FLAC Player 2 | =========== 3 | 4 | Decode and playback flac files with FLAC and SDL. 5 | 6 | ### Requirements 7 | FLAC, SDL1.2 8 | 9 | ### Compile 10 | ``` 11 | make 12 | ``` 13 | -------------------------------------------------------------------------------- /Daemon/Daemon/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Daemon/Daemon/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/base64.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using byte = unsigned char; 8 | 9 | namespace base64 { 10 | 11 | std::string encode(const std::vector &src); 12 | 13 | } -------------------------------------------------------------------------------- /pcap-port-statistics/README.md: -------------------------------------------------------------------------------- 1 | Pcap port statistics 2 | ==================== 3 | 4 | Collect all traffic data by port. 5 | 6 | ### Requirements 7 | 8 | libpcap 9 | 10 | ### Build 11 | 12 | ``` 13 | g++ -std=c++1z -o port_stat main.cpp -lpthread `pcap-config --libs` 14 | ``` -------------------------------------------------------------------------------- /wav-decode/README.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | A WAV decoder and player with oscilloscope visualizer in pure JavaScript. 4 | 5 | [View demo(Chrome/Chromium only)](https://ntzyz.github.io/playground/wav-decode/) 6 | 7 | ### API used 8 | 1. XMLHttpRequest 9 | 2. Promise 10 | 3. Yield 11 | 4. AudioContext 12 | 5. Canvas 13 | -------------------------------------------------------------------------------- /websocket-terminal/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "css-loader": "^0.28.5", 4 | "express": "^4.15.4", 5 | "node-pty": "^0.7.0", 6 | "socket.io": "^2.0.3", 7 | "style-loader": "^0.18.2", 8 | "webpack": "^3.5.5", 9 | "webpack-dev-server": "^2.7.1", 10 | "xterm": "^2.9.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /simple-sshd/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CCX = g++ 3 | CFLAGS = -Wall -O2 -std=c++11 4 | OBJS = server.o 5 | PROG = server 6 | LDFLAGS = -lssh 7 | 8 | all: $(PROG) 9 | 10 | $(PROG): $(OBJS) 11 | $(CCX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LDLIBS) 12 | 13 | server.o: server.cpp 14 | $(CCX) $(CFLAGS) -c server.cpp 15 | 16 | clean: 17 | rm -f *.o $(PROG) 18 | -------------------------------------------------------------------------------- /websocket-terminal/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /websocket-terminal/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: "./src/entry.js", 5 | output: { 6 | path: path.join(__dirname, 'dist'), 7 | filename: "bundle.js" 8 | }, 9 | module: { 10 | loaders: [ 11 | { test: /\.css$/, loader: "style-loader!css-loader" } 12 | ] 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /music-read-trans/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: "./src/entry.js", 5 | output: { 6 | path: path.join(__dirname, 'dist'), 7 | filename: "bundle.js" 8 | }, 9 | devServer: { 10 | contentBase: path.join(__dirname, '.'), 11 | index: 'index.html', 12 | compress: true, 13 | port: 9000, 14 | host: '0.0.0.0', 15 | } 16 | }; -------------------------------------------------------------------------------- /Daemon/Daemon/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Daemon/Daemon/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Daemon 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CXX=g++ 3 | LD=gcc 4 | 5 | TARGET=main 6 | CFLAGS=-Wall -O0 -ggdb -static 7 | LDFLAGS=-fPIC -lpthread -lm -lutil -static 8 | OBJS=main.o sha1.o base64.o pty.o ws.o http.o frontend.o 9 | 10 | .PHONY: clean 11 | 12 | $(TARGET): $(OBJS) 13 | $(CXX) -o $(TARGET) $(OBJS) $(LDFLAGS) 14 | 15 | %.o: %.cpp 16 | $(CXX) $(CFLAGS) -c $< -o $@ 17 | 18 | frontend.cpp: frontend.html 19 | xxd -i frontend.html > frontend.cpp 20 | 21 | clean: 22 | rm -rf $(OBJS) $(TARGET) frontend.cpp 23 | -------------------------------------------------------------------------------- /simple-sshd/README.md: -------------------------------------------------------------------------------- 1 | simple sshd 2 | =========== 3 | 4 | A simple Secure Shell Server built with libssh. 5 | ``` 6 | ntzyz@ntzyz-solaris ~ % ssh localhost -p 2022 7 | ntzyz@localhost's password: 8 | PTY allocation request failed on channel 0 9 | [NSH]$ 123 10 | ECHO: 123 11 | [NSH]$ ping 12 | Pong! 13 | [NSH]$ exit 14 | exiting... 15 | Connection to localhost closed. 16 | ``` 17 | 18 | #### Dependence 19 | libssh-dev 20 | 21 | #### Build and run 22 | ```bash 23 | $ sudo apt install libssh-dev 24 | $ make 25 | $ ./server 26 | ``` 27 | -------------------------------------------------------------------------------- /flac-player-sdl/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CXX=g++ 3 | LD=gcc 4 | 5 | SDL_CFLAGS=$(shell pkg-config sdl --cflags) 6 | SDL_LDFLAGS=$(shell pkg-config sdl --libs) 7 | FLAC_CFLAGS=$(shell pkg-config flac --cflags) 8 | FLAC_LDFLAGS=$(shell pkg-config flac --libs) 9 | 10 | TARGET=main 11 | CFLAGS=-Wall -O0 -ggdb $(SDL_CFLAGS) $(FLAC_CFLAGS) 12 | LDFLAGS=-fPIC $(SDL_LDFLAGS) $(FLAC_LDFLAGS) 13 | OBJS=main.o 14 | 15 | .PHONY: clean 16 | 17 | $(TARGET): $(OBJS) 18 | $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) 19 | 20 | %.o: %.c 21 | $(CC) $(CFLAGS) -c $< -o $@ 22 | 23 | clean: 24 | rm -rf $(OBJS) $(TARGET) -------------------------------------------------------------------------------- /websocket-terminal/src/entry.js: -------------------------------------------------------------------------------- 1 | import Terminal from 'xterm'; 2 | import 'xterm/src/xterm.css'; 3 | import io from 'socket.io-client'; 4 | 5 | Terminal.loadAddon('fit'); 6 | 7 | const socket = io(window.location.href); 8 | 9 | const term = new Terminal({ 10 | cols: 80, 11 | rows: 24, 12 | }); 13 | term.open(document.getElementById('#terminal')); 14 | term.on('resize', size => { 15 | socket.emit('resize', [size.cols, size.rows]); 16 | }) 17 | 18 | term.on('data', data => socket.emit('input', data)); 19 | 20 | socket.on('output', arrayBuffer => { 21 | term.write(arrayBuffer); 22 | }); 23 | 24 | window.addEventListener('resize', () => { 25 | term.fit() 26 | }); 27 | term.fit() 28 | -------------------------------------------------------------------------------- /websocket-terminal/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const site = express(); 3 | const http = require('http').Server(site); 4 | const io = require('socket.io')(http); 5 | const net = require('net'); 6 | const pty = require('node-pty'); 7 | 8 | site.use('/', express.static('.')); 9 | 10 | io.on('connection', function (socket) { 11 | let ptyProcess = pty.spawn('bash', ['--login'], { 12 | name: 'xterm-color', 13 | cols: 80, 14 | rows: 24, 15 | cwd: process.env.HOME, 16 | env: process.env 17 | }); 18 | ptyProcess.on('data', data => socket.emit('output', data)); 19 | socket.on('input', data => ptyProcess.write(data)); 20 | socket.on('resize', size => { 21 | console.log(size); 22 | ptyProcess.resize(size[0], size[1]) 23 | }); 24 | }); 25 | 26 | http.listen(8123); 27 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/sha1.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | sha1.hpp - header of 3 | 4 | ============ 5 | SHA-1 in C++ 6 | ============ 7 | 8 | 100% Public Domain. 9 | 10 | Original C Code 11 | -- Steve Reid 12 | Small changes to fit into bglibs 13 | -- Bruce Guenter 14 | Translation to simpler C++ Code 15 | -- Volker Diels-Grabsch 16 | Safety fixes 17 | -- Eugene Hopkinson 18 | */ 19 | 20 | #ifndef SHA1_HPP 21 | #define SHA1_HPP 22 | 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | class SHA1 30 | { 31 | public: 32 | SHA1(); 33 | void update(const std::string &s); 34 | void update(std::istream &is); 35 | std::string final(); 36 | static std::string from_file(const std::string &filename); 37 | 38 | private: 39 | uint32_t digest[5]; 40 | std::string buffer; 41 | uint64_t transforms; 42 | }; 43 | 44 | 45 | #endif /* SHA1_HPP */ 46 | -------------------------------------------------------------------------------- /Daemon/Daemon.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daemon", "Daemon\Daemon.csproj", "{48455FF1-66AE-4245-B35B-021CE8AEFFE3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {48455FF1-66AE-4245-B35B-021CE8AEFFE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {48455FF1-66AE-4245-B35B-021CE8AEFFE3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {48455FF1-66AE-4245-B35B-021CE8AEFFE3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {48455FF1-66AE-4245-B35B-021CE8AEFFE3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /bandwidth/README.md: -------------------------------------------------------------------------------- 1 | ## Bandwidth 2 | 3 | Find out who is consuming most of our bandwidth. Sample output: 4 | 5 | ``` 6 | 172.16.10.1 0.00 B/s 7 | 172.16.10.112 0.00 B/s 8 | 172.16.10.170 0.00 B/s 9 | 172.16.10.215 7.39 MB/s 10 | 172.16.10.247 0.00 B/s 11 | 172.16.10.41 0.00 B/s 12 | 172.16.10.81 0.00 B/s 13 | 224.0.0.1 0.00 B/s 14 | ``` 15 | 16 | ### Useage 17 | 18 | If you believe your router is powerful enough to run node.js, just run it on your router: 19 | 20 | 1. Install `python`, `git`, `git-http`, `node`, `gcc` with `opkg`. 21 | 2. Download the source code of `libpacp`, compile and install it. 22 | 3. Install node packages by `npm i`. 23 | 3. Run `index.js` with root privilege. 24 | 25 | Or, you can: 26 | 27 | 1. Install `iptables-mod-tee` on your OpenWrt/LEDE router. 28 | 2. Run `iptables -I FORWARD -j TEE --gateway $(echo $SSH_CLIENT | awk '{ print $1 }')` on your OpenWrt/LEDE router. 29 | 3. Run `index.js` with root privilege. 30 | 4. Run `iptables -D FORWARD -j TEE --gateway $(echo $SSH_CLIENT | awk '{ print $1 }')` on your OpenWrt/LEDE router. 31 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/pty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pty.hpp" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | pty_t::pty_t () { 13 | } 14 | 15 | void pty_t::spawn() { 16 | struct winsize winp; 17 | winp.ws_col = 80; 18 | winp.ws_row = 24; 19 | winp.ws_xpixel = 0; 20 | winp.ws_ypixel = 0; 21 | 22 | pid_t pid = forkpty(&master_fd, nullptr, nullptr, &winp); 23 | 24 | if (pid == -1) { 25 | perror("forkpty"); 26 | return; 27 | } else if (pid == 0) { // master 28 | char path[1024]; 29 | char *params[] = { 30 | path, 31 | nullptr 32 | }; 33 | 34 | getcwd(path, sizeof (path)); 35 | strcat(path, "/exec.sh"); 36 | 37 | execvp(path, params); 38 | perror("execvp"); 39 | } else { 40 | int flags = fcntl(master_fd, F_GETFL, 0); 41 | fcntl(master_fd, F_SETFL, flags | O_NONBLOCK); 42 | 43 | puts("pts created."); 44 | ready = true; 45 | } 46 | } 47 | 48 | pty_t::~pty_t() { 49 | close(master_fd); 50 | puts("pts closed."); 51 | } -------------------------------------------------------------------------------- /azure-ddns/index.js: -------------------------------------------------------------------------------- 1 | const DnsManagementClient = require('azure-arm-dns'); 2 | const msRestAzure = require("ms-rest-azure"); 3 | const express = require('express'); 4 | const site = express(); 5 | 6 | const subscriptionId = '<---->'; 7 | const resourcesGroup = '<---->'; 8 | const zoneName = '<---->'; 9 | let dnsClient = null; 10 | 11 | site.post('/update_dns', (req, res) => { 12 | if (!req.query.ip_addr) { 13 | res.send({ status: 'ok' }); 14 | } else { 15 | dnsClient.recordSets.update(resourcesGroup, zoneName, 'prefix.', 'A', { 16 | aRecords: [{ 17 | ipv4Address: req.query.ip_addr 18 | }] 19 | }).then((response) => { 20 | res.send({ 21 | status: 'ok', 22 | azure_response: response, 23 | }); 24 | }).catch((error) => { 25 | res.send({ 26 | status: 'error', 27 | azure_error: error, 28 | }); 29 | }) 30 | } 31 | }); 32 | 33 | msRestAzure.interactiveLogin({ 34 | domain: '<---->' 35 | }).then((creds) => { 36 | dnsClient = new DnsManagementClient(creds, subscriptionId); 37 | site.listen(3399, '127.0.0.1'); 38 | }).catch((error) => { 39 | console.error(error); 40 | }) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Playground 2 | ========== 3 | 4 | Codes for fun. 5 | 6 | 1. [wav-decode](wav-decode): WAV decoder and player with oscilloscope visualizer in pure JavaScript. 7 | 1. [simple-sshd](simple-sshd): Simple secure shell server. 8 | 1. [bilibili-regular-block](bilibili-regular-block): Blocking some annoying danmaku with these regular expressions. 9 | 1. [websocket-terminal](websocket-terminal): HTML5 remote terminal with xterm.js and WebSocket. 10 | 1. [Daemon](Daemon): Supervisor for processes like nginx & java. 11 | 1. [bandwidth](bandwidth): Simple bandwidth monitor utility. 12 | 1. [pcap-port-statistics](pcap-port-statistics): Collect all traffic data by port with libpcap. 13 | 1. [flac-player-sdl](flac-player-sdl): Decode and playback flac files with FLAC and SDL. 14 | 1. [reversi](reversi): Simple(Stupid?) strategy board game called [Reversi](https://en.wikipedia.org/wiki/Reversi), requires at least two players. 15 | 1. [Azure DDNS](azure-ddns): HTTP Server allowing you to update DNS records on Azure. Use it with `/etc/ppp/ip-up.d/` and `cURL`. 16 | 1. [websocket-terminal-cpp-server](websocket-terminal-cpp-server): WebSocket Terminal written with C++ and Linux API, server only. 17 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/frontend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 33 | 34 | -------------------------------------------------------------------------------- /Daemon/Daemon/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Daemon.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/http.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | struct http_request_t { 15 | enum { 16 | GET, POST, PUT, OPTIONS, 17 | DELETE, UNKNOWN // etc 18 | } request_method; 19 | std::string request_path; 20 | std::string http_version; 21 | std::map> headers; 22 | 23 | http_request_t(const uint8_t *const, const ssize_t); 24 | 25 | void parse_http_method(std::stringstream &); 26 | void parse_http_path(std::stringstream &); 27 | void parse_http_version(std::stringstream &); 28 | void parse_http_headers(std::stringstream &); 29 | }; 30 | 31 | struct http_response_t { 32 | int status_code; 33 | std::string status_text; 34 | std::map> headers; 35 | std::string body; 36 | 37 | http_response_t(const int); 38 | 39 | void http_status_code_to_status_text(); 40 | void initialize_response_headers(); 41 | void append_header_date(); 42 | void append_header_connection(); 43 | void append_header_server(); 44 | std::string to_response(); 45 | }; -------------------------------------------------------------------------------- /wav-decode/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | Ready ... 16 |
17 | Oscilloscope sampling interval: 18 | 19 | 20 |
21 | Ahhh please use a better browser. 22 |
23 | View source on GitHub. 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /bandwidth/index.js: -------------------------------------------------------------------------------- 1 | const pcap = require('pcap') 2 | const IPv4 = require('./node_modules/pcap/decode/ipv4'); 3 | const EthernetPacket = require('./node_modules/pcap/decode/ethernet_packet'); 4 | 5 | const session = pcap.createSession('br0'); 6 | const prefix = '172.16.10.'; 7 | 8 | const packet_size_map = {}; 9 | 10 | session.on('packet', raw_packet => { 11 | let packet; 12 | try { 13 | packet = pcap.decode.packet(raw_packet); 14 | } catch (_) { 15 | return; 16 | } 17 | if (packet.payload instanceof EthernetPacket && 18 | packet.payload.payload instanceof IPv4) { 19 | let tcp_packet = packet.payload.payload; 20 | let addr; 21 | 22 | if (tcp_packet.saddr.addr.join('.').indexOf(prefix) === 0) { 23 | addr = tcp_packet.saddr.addr.join('.'); 24 | } else { 25 | addr = tcp_packet.daddr.addr.join('.'); 26 | } 27 | 28 | packet_size_map[addr] = (packet_size_map[addr] || 0) + tcp_packet.length; 29 | } 30 | }); 31 | 32 | // From https://github.com/cnCalc/serainTalk/blob/dev/web/src/utils/filters.js 33 | function fileSize (size) { 34 | const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; 35 | let n = Math.max(Math.floor(Math.log(size) / Math.log(1024)), 0); 36 | return `${(size / (1024 ** n)).toFixed(2)} ${units[n]}`; 37 | } 38 | 39 | setInterval(() => { 40 | process.stdout.write('\x1b[2J\x1b[H') // clear 41 | Object.keys(packet_size_map).sort().forEach(addr => { 42 | console.log(`${addr}\t${fileSize(packet_size_map[addr])}/s`); 43 | packet_size_map[addr] = 0; 44 | }) 45 | }, 1000); 46 | 47 | -------------------------------------------------------------------------------- /music-read-trans/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 60 | 61 | 62 |
程序员小盆友是如何练习识谱的(不
63 |
64 |
65 | 66 | 67 |
68 |

69 |   
70 | 
71 | 


--------------------------------------------------------------------------------
/websocket-terminal-cpp-server/ws.hpp:
--------------------------------------------------------------------------------
 1 | #pragma once
 2 | 
 3 | #include 
 4 | #include 
 5 | #include 
 6 | #include 
 7 | 
 8 | #include 
 9 | #include 
10 | 
11 | #include 
12 | #include 
13 | 
14 | #include "pty.hpp"
15 | #include "http.hpp"
16 | #include "base64.hpp"
17 | #include "sha1.hpp"
18 | #include "frontend.hpp"
19 | 
20 | enum websocket_connection_stage_t {
21 |   handshaking,
22 |   established,
23 |   terminated,
24 |   unknown,
25 | };
26 | 
27 | struct websocket_frame_t {
28 |   using opcode_t = enum {
29 |     CONTINUATION_FRAME = 0x00,
30 |     TEXT_FRAME = 0x01,
31 |     BINARY_FRAME = 0x02,
32 |     CONNECTION_CLOSE_FRAME = 0x08,
33 |     PING_FRAME = 0x09,
34 |     PONG_FRAME = 0x0A,
35 |   };
36 | 
37 |   bool fin;
38 |   opcode_t opcode;
39 |   bool mask;
40 |   uint8_t mask_key[4] = { 0, 0, 0, 0 };
41 |   std::vector payload;
42 | 
43 |   bool debug = false;
44 | 
45 |   websocket_frame_t(std::unique_ptr, size_t);
46 | 
47 |   websocket_frame_t();
48 | 
49 |   void print_frame_info();
50 | 
51 |   std::unique_ptr to_raw_frame(size_t *frame_size);
52 | };
53 | 
54 | struct websocket_context_t {
55 |   websocket_connection_stage_t stage = websocket_connection_stage_t::unknown;
56 |   int client_fd = -1;
57 | 
58 |   uint8_t *received_buffer = nullptr;
59 |   ssize_t received_buffer_capacity = -1;
60 |   ssize_t received_buffer_used = -1;
61 |   bool enable_builtin_webpages = false;
62 |   pty_t pty;
63 |   std::function regist_pty_session;
64 | 
65 |   ~websocket_context_t();
66 | 
67 |   void append_buffer(uint8_t *buffer, ssize_t buffer_size);
68 |   void process();
69 |   void process_handshake();
70 |   ssize_t next_valid_ws_frame_size();
71 |   void process_data();
72 | };


--------------------------------------------------------------------------------
/reversi/dist/index.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 |   
 5 |   
 6 |   
 7 |   Document
 8 |   
 9 |   
26 | 
27 | 
28 |   

29 |

30 | 31 | 32 | 33 |
34 | 73 | 74 | -------------------------------------------------------------------------------- /Daemon/Daemon/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("Daemon")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("Daemon")] 15 | [assembly: AssemblyCopyright("Copyright © 2017")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /websocket-terminal-cpp-server/base64.cpp: -------------------------------------------------------------------------------- 1 | /* Public Domain from https://gist.github.com/ynov/aead6c4a4208e1808fb2, modified */ 2 | 3 | #include "base64.hpp" 4 | 5 | #include 6 | #include 7 | 8 | namespace base64 { 9 | 10 | static bool dlookupok = false; 11 | static char dlookup[256]; 12 | const static char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 13 | const static char padchar = '='; 14 | 15 | const char *getdlookup() 16 | { 17 | if (!dlookupok) { 18 | memset(dlookup, 0, sizeof(dlookup)); 19 | for (size_t i = 0; i < strlen(lookup); i++) { 20 | dlookup[(int) lookup[i]] = i; 21 | } 22 | } 23 | 24 | dlookupok = true; 25 | return dlookup; 26 | } 27 | 28 | std::string encode(const std::vector &src) 29 | { 30 | std::string encoded; 31 | 32 | int outputSize = 4 * ((src.size() / 3) + (src.size() % 3 > 0 ? 1 : 0)); 33 | encoded.reserve(outputSize); 34 | 35 | uint32_t tmp; 36 | int i, padding; 37 | int srcsz = src.size(); 38 | 39 | for (i = 0; i < srcsz; i += 3) { 40 | padding = (i + 3) - srcsz; 41 | tmp = 0; 42 | 43 | switch (padding) { 44 | case 2: 45 | tmp |= (src[i] << 16); 46 | break; 47 | case 1: 48 | tmp |= (src[i] << 16) | (src[i + 1] << 8); 49 | break; 50 | default: 51 | tmp |= (src[i] << 16) | (src[i + 1] << 8) | (src[i + 2]); 52 | break; 53 | } 54 | 55 | encoded += lookup[(tmp & 0xfc0000) >> 18]; 56 | encoded += lookup[(tmp & 0x03f000) >> 12]; 57 | encoded += padding > 1 ? padchar : lookup[(tmp & 0x000fc0) >> 6]; 58 | encoded += padding > 0 ? padchar : lookup[(tmp & 0x00003f)]; 59 | } 60 | 61 | return encoded; 62 | } 63 | 64 | std::vector decode(const std::string &src) 65 | { 66 | const char *dlookup = getdlookup(); 67 | std::vector decoded; 68 | 69 | int outputSize = (src.size() / 4) * 3; 70 | decoded.reserve(outputSize); 71 | 72 | char ch[4]; 73 | uint32_t tmp; 74 | size_t i, j; 75 | int padding = 0; 76 | 77 | for (i = 0; i < src.size(); i += 4) { 78 | for (j = 0; j < 4; j++) { 79 | if (src[i + j] == padchar) { 80 | ch[j] = '\0'; 81 | padding++; 82 | } else { 83 | ch[j] = dlookup[static_cast(src[i + j])]; 84 | } 85 | } 86 | 87 | tmp = 0; 88 | tmp |= (ch[0] << 18) | (ch[1] << 12) | (ch[2] << 6) | ch[3]; 89 | 90 | decoded.push_back((tmp & 0xff0000) >> 16); 91 | decoded.push_back((tmp & 0xff00) >> 8); 92 | decoded.push_back((tmp & 0xff)); 93 | } 94 | 95 | return decoded; 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /bilibili-regular-block/tv.bilibili.player.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | r=我是.+?党 4 | 5 | r=^\d{0,2}$ 6 | 7 | r=[aA][vV](170001|10388|10492) 8 | 9 | r=←↓↗↘ 10 | 11 | r=[恍惚红火]{2} 12 | 13 | r=[无五午5][时十⑩屎01][已以一][到刀] 14 | 15 | t=测试 16 | 17 | r=^[第前后][0-9一二三四五六七八九零十百千]+.{0,6}[!!\??]*$ 18 | 19 | t=厂下广卞 20 | 21 | r=倍速 *$ 22 | 23 | t=香菇 24 | 25 | r=^[好]{0,}前[!!~]{0,}$ 26 | 27 | t=高级弹幕 28 | 29 | r=([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF]) 30 | 31 | r=[\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF] 32 | 33 | r=(^ {5,}| {5,}$) 34 | 35 | t=吉吧 36 | 37 | r=[拜|过|新|早](.*?)年 38 | 39 | r=一口气(.+?)集 40 | 41 | r=我老婆 42 | 43 | r=[Ww][Ii][Ff][Ii] 44 | 45 | r=电光.+?信仰.+?长存 46 | 47 | r=(空降|空难|盲降|降落|指挥部|坐标|\d+?[::]\d+?) 48 | 49 | r=^(\d+?)[.。\ ] 50 | 51 | t=膜法 52 | 53 | r=^\+\d*?s$ 54 | 55 | r=^日常 56 | 57 | r=^前方(.+?)福利$ 58 | 59 | r=^\d{2,4}[。\.\/\-\::]\d{1,2}[。\.\/\-\::]\d{1,2} 60 | 61 | r=[苹水]果摊 62 | 63 | r=巧了[,, ] 64 | 65 | t=王之力 66 | 67 | t=做操 68 | 69 | r=[一二三四五六七八九十百千万零负0-9a-zA-Z]+?周目 70 | 71 | r=(爱的|供养|再问|自杀).+?(爱的|供养|再问|自杀) 72 | 73 | r=.+?入的{0,1}宅 74 | 75 | r=.{32,} 76 | 77 | r=^[苟利国家生死以岂因祸福避趋之]$ 78 | 79 | -------------------------------------------------------------------------------- /Daemon/Daemon/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 |