Skip to content

Instantly share code, notes, and snippets.

View zRains's full-sized avatar
🍀
Lucky or ...

zrain zRains

🍀
Lucky or ...
View GitHub Profile
@zRains
zRains / cs.ts
Last active October 11, 2022 07:21
时效性localStorage简单实现
class CustomStorage {
// eslint-disable-next-line no-use-before-define
public static instance: CustomStorage | null = null
public myStorage: Map<string, { val: any; exp: number }> = new Map()
constructor({ clearExpire = true }) {
for (const [k, p] of Object.entries(localStorage)) {
if (/_isMystorage/.test(p))
try {
@zRains
zRains / link.rs
Last active June 1, 2022 12:58
Rust 链表
@zRains
zRains / mineStatus.js
Created September 17, 2022 17:12
Get Minecraft server info by LSP using nodejs.
const { Socket } = require('net')
class MineStatus {
/** @type {Socket} */
socket
/** @type {string} */
host
/** @type {number} */
@zRains
zRains / http_status.rs
Created September 23, 2022 09:50
From Nest.js
pub enum HttpStatus {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
EARLYHINTS = 103,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
async function async1() {
console.log('async1 start')
new Promise((resolve, reject) => {
try {
throw new Error('error1')
} catch (e) {
console.log(e)
}
setTimeout(() => {
resolve('promise4')
@zRains
zRains / setting.json
Created September 24, 2022 14:30
My vscode setting
{
"workbench.colorTheme": "One Dark Pro Darker",
"workbench.preferredDarkColorTheme": "Vitesse Dark",
"workbench.preferredLightColorTheme": "Vitesse Light",
"workbench.iconTheme": "material-icon-theme",
"workbench.editor.closeOnFileDelete": true,
"workbench.editor.limit.enabled": true,
"workbench.editor.limit.perEditorGroup": true,
"workbench.editor.limit.value": 5,
"workbench.list.smoothScrolling": true,
@zRains
zRains / 1024.rs
Created October 23, 2022 16:18
leetcode 1024 Rust implementation
use std::cell::RefCell;
use std::cmp;
use std::collections::HashSet;
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
#[derive(Debug)]
#[allow(dead_code)]
struct CalcResult<'a> {
@zRains
zRains / solution.rs
Created January 5, 2023 07:10
Interconversion of roman and integer
use std::collections::HashMap;
struct Solution;
impl Solution {
pub fn int_to_roman(int: i32) -> String {
let thousands = ["", "M", "MM", "MMM"];
let hundreds = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"];
let tens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
let ones = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
@zRains
zRains / traverseFile.js
Created February 27, 2023 06:46
Get files in a dir by ext.
const fs = require('node:fs')
const path = require('node:path')
/**
* Traverse files in a dir
* @param {string} dirPath Dir path
* @param {string[]} ext
* @param {number} [deep]
* @param {any[]} [collection]
*/
@zRains
zRains / resolveData.ts
Created April 4, 2023 09:06
Resolve value from object by given path.
function resolveData<T = any>(data: Record<string | number, any>, path: string): T {
const pathArr = path.split('.')
return path.length === 0 ? data : pathArr.reduce((originalData, path) => originalData[path], data)
}