Skip to content

Instantly share code, notes, and snippets.

View LianSheng197's full-sized avatar
🎉
支持有意義的事 / Support meaningful things.

b0ring LianSheng197

🎉
支持有意義的事 / Support meaningful things.
  • Home
  • 23:18 (UTC +08:00)
View GitHub Profile
@LianSheng197
LianSheng197 / ast-parser-example.js
Created October 25, 2023 19:44
一個僅支持 HTML 的 <html>, <head>, <body>, <title>, <h1>, <p> 六種標籤的極簡語法分析範例,不含屬性、自閉合標籤、錯誤恢復等常見 HTML 功能。以 JavaScript 編寫。
function lexer(input) {
const regex = /<\/?(title|h1|html|head|body|p)>|[^<]+/g;
let result, tokens = [];
while ((result = regex.exec(input)) !== null) {
tokens.push(result[0]);
}
return tokens;
}
function parser(tokens) {
@LianSheng197
LianSheng197 / __upload_file.md
Created December 10, 2022 01:20 — forked from maxivak/__upload_file.md
PHP upload file with curl (multipart/form-data)

We want to upload file to a server with POST HTTP request. We will use curl functions.


// data fields for POST request
$fields = array("f1"=>"value1", "another_field2"=>"anothervalue");

// files to upload
$filenames = array("/tmp/1.jpg", "/tmp/2.png");
const linkEl = document.createElement('link');
linkEl.rel = 'prefetch';
linkEl.href = urlWithYourPreciousData;
document.head.appendChild(linkEl);
@LianSheng197
LianSheng197 / base64url.php
Created December 27, 2021 10:21 — forked from nathggns/base64url.php
base64url functionality for php
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
@LianSheng197
LianSheng197 / OFCReportAnalysisCore.js
Created April 1, 2021 17:14
我們的浮游城戰報解析核心邏輯(以玩家爲例)
// 原本想說要開源,結果後來覺得實在寫得太噁爛
// 再加上不久後會有替代的專案(不是我寫的)
// 所以這裡只放上核心片段
class Report {
static year = 2021;
static month = 3;
static day = 5;
static hour = 19;
static saveData = (faction, value) => {
Level ██████████████████▉░░Lv.18/90%
Coding ░░░░░░░░░░░░░░░░░░░░░5000/0
----------------------------------------
https://codestats.net/users/LianSheng
@LianSheng197
LianSheng197 / linux-kill-pts.md
Created June 26, 2020 13:59 — forked from holmberd/linux-kill-pts.md
Kill tty/pts sessions in Linux

Kill user tty/pts sessions in Linux

Commands

  • w: show who is logged on and what they are doing
  • who: show who is logged on
  • tty: show current users pseudo terminal
  • ps -ft pts/1: get process id for the pseudo terminal
  • pkill: signal process based on name and other attributes
@LianSheng197
LianSheng197 / bash_and_ansi_escape_sequence.md
Created June 18, 2020 11:59 — forked from JoshCheek/bash_and_ansi_escape_sequence.md
Explanation of a confusing line of bash code / ANSI escape sequences.
echo "\[\033[${2:-37};60m\]${1}\[\033[0m\]"

Echo is the program echo that you can run from the terminal. (eg $ echo hello world) it works here because the output of the function is being captured and put into a string.


@LianSheng197
LianSheng197 / curl.md
Created April 14, 2020 05:03 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@LianSheng197
LianSheng197 / 📊 Weekly development breakdown
Last active April 3, 2021 00:07
📊 Weekly development breakdown
Java 2 hrs 41 mins ███████▉░░░░░░░░░░░░░ 37.5%
JSON 1 hr 47 mins █████▎░░░░░░░░░░░░░░░ 25.0%
JavaScript 1 hr 10 mins ███▍░░░░░░░░░░░░░░░░░ 16.4%
PHP 24 mins █▏░░░░░░░░░░░░░░░░░░░ 5.6%
Python 23 mins █▏░░░░░░░░░░░░░░░░░░░ 5.5%