Skip to content

Instantly share code, notes, and snippets.

View zRains's full-sized avatar
🍀
Lucky

zrain zRains

🍀
Lucky
View GitHub Profile
@zRains
zRains / url.txt
Created February 2, 2024 05:50
Get chrome ext offline.
https://clients2.google.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=beta&prodversion=79.0.3945.53&lang=ru&acceptformat=crx3&x=id%3D<ID>%26installsource%3Dondemand%26uc
@zRains
zRains / cmd.bash
Created January 13, 2024 12:36
Ssh copy id in windows.
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"
@zRains
zRains / shell
Created December 8, 2023 02:04
Node openssl legacy issue
# Mac
NODE_OPTIONS="--openssl-legacy-provider"
# Windows ps
$env:NODE_OPTIONS="--openssl-legacy-provider"
@zRains
zRains / launch.json
Created October 20, 2023 16:17 — forked from cecilemuller/launch.json
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@zRains
zRains / Separate.d.ts
Created June 20, 2023 15:16
Thousand separator.
// 判断类型是否相等
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
// 条件判断
type If<C extends boolean, T, F> = C extends true ? T : F
// 获取类型数组最后一个类型
type LastEl<T extends string[]> = T extends [...infer _P, infer K] ? K : never
// 合法数字表达集合
@zRains
zRains / LRU.rs
Last active May 5, 2023 09:23
LRU impl by Rust.
mod test;
use std::{
cell::RefCell,
collections::{hash_map::Entry, HashMap},
fmt::{self, Debug},
rc::Rc,
};
#[derive(Debug)]
@zRains
zRains / add_big_num.rs
Created April 11, 2023 14:31
Add two big nums.
#![allow(unused)]
pub fn add_big_num(num_1: &str, num_2: &str) -> String {
let to_u8_arr = |num: &str| {
num.split("")
.filter(|&n| !n.is_empty())
.map(|n| n.parse::<u8>().unwrap())
.collect::<Vec<_>>()
};
@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)
}
@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 / 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"];