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 / quiz.rs
Created July 11, 2024 08:49
little quiz
#![feature(const_trait_impl)]
fn extend_lifetime(x: &str) -> &'static str {
f::<S>(x)
}
const fn f<'a, T: Tr<'a> + ~const Drop>(x: &'a str) -> T::Ty {
// can call g with T: Drop bound, even though
// T: ~const Drop works for non-Drop-implementing types
g::<T>(x)
type StrLen<T extends string, R extends Array<string> = []> = T extends `${infer C}${infer P}`
? StrLen<P, [...R, C]>
: R['length']
type StrSplit<T extends string, S extends string, R extends Array<string> = []> = T extends `${infer X}${S}${infer Y}`
? StrSplit<Y, S, StrLen<X> extends 0 ? R : [...R, X]>
: StrLen<T> extends 0
? R
: [...R, T]
@zRains
zRains / cmd.sh
Created May 6, 2024 03:55
Get file md5 in PowerShell.
# https://serverfault.com/questions/57529/how-do-i-get-the-md5-of-a-file-on-windows
CertUtil -hashfile yourFileName MD5
@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<_>>()
};