Skip to content

Instantly share code, notes, and snippets.

View DefectingCat's full-sized avatar
🎮
ELDEN RING

Sonetto DefectingCat

🎮
ELDEN RING
View GitHub Profile
@DefectingCat
DefectingCat / binding_arr.rs
Created July 4, 2024 05:11
rust at operator binding
fn main() {
let strs = ["hello world", "1", "hello", "world"];
let mut remaining: &[&str] = &strs;
while let [current, tail @ ..] = remaining {
println!("{} - {:?}", current, tail);
remaining = tail;
}
println!("The real strs {:?}", strs);
}
@DefectingCat
DefectingCat / .gitlab-ci.yml
Created June 6, 2024 03:19
gitlab ci docker runner use ssh private key
before_script:
- "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )"
- eval $(ssh-agent -s)
- chmod 400 "$SSH_PRIVATE_KEY"
- ssh-add "$SSH_PRIVATE_KEY"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
@DefectingCat
DefectingCat / daemon.json
Created June 6, 2024 03:04
docker daemon
{
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"],
"insecure-registries" : ["192.168.1.57:8004"],
"data-root": "/home/xfy/data/docker-var"
}
@DefectingCat
DefectingCat / validator.rs
Created June 5, 2024 14:44
axum json and form validator
use axum::{
async_trait,
extract::{rejection::FormRejection, FromRequest, Request},
Form, Json,
};
use once_cell::sync::Lazy;
use regex::Regex;
use serde::de::DeserializeOwned;
use validator::Validate;
@DefectingCat
DefectingCat / jwt.rs
Created June 5, 2024 14:43
rust jsonwebtoken
use std::sync::OnceLock;
use jsonwebtoken::{DecodingKey, EncodingKey, Header};
use serde::{Deserialize, Serialize};
pub struct Keys {
pub encoding: EncodingKey,
pub decoding: DecodingKey,
}
impl Keys {
@DefectingCat
DefectingCat / password.rs
Created June 5, 2024 14:43
argon2 password hash
use anyhow::{anyhow, Context};
use tokio::task;
use argon2::password_hash::SaltString;
use argon2::{password_hash, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
/// 生成 hash
///
/// ## Arguments
///
@DefectingCat
DefectingCat / full.rs
Last active June 5, 2024 14:40
axum routes nest and trace layer
use std::{collections::HashMap, time::Duration};
use axum::{
async_trait,
body::Bytes,
extract::{FromRequestParts, MatchedPath, Path, Request},
http::{request::Parts, HeaderMap, StatusCode, Uri},
middleware,
response::{IntoResponse, Response},
routing::get,
@DefectingCat
DefectingCat / removeHash.ts
Created May 28, 2024 03:09
remove query in url hash
/**
* 根据 key 删除 url 中 hash 中的指定 query
*
* #/?booth_id=Ep3wmDXbjk2&code=041Cax100CXyaS1mjI1005Tw1E3Cax1N
*
* @param hash url 中的 hash
* @param deleteKey 需要删除的 query 的 key
*/
export function removeHash(hash: string, deleteKey: string) {
if (hash.length < 3) return;
@DefectingCat
DefectingCat / incraseNumber.ts
Last active May 8, 2024 03:38
incraseNumber js javascript animation
/**
* 按间隔更新数字,数字增长的动画。
*
* @param start 动画开始的值
* @param end 动画最后结束的值
* @param updateFn 更新值状态的方法
* @param duration 动画总时长
* @param setpDuration 每次更新的间隔
* @param precision 数字精度
*
struct ByteIter<'remainder> {
remainder: &'remainder [u8],
}
/* impl<'remainder> ByteIter<'remainder> {
fn next(&mut self) -> Option<&'remainder u8> {
if self.remainder.is_empty() {
None
} else {
let byte = &self.remainder[0];