Skip to content

Instantly share code, notes, and snippets.

View DefectingCat's full-sized avatar
🎮
ELDEN RING

Sonetto DefectingCat

🎮
ELDEN RING
View GitHub Profile
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];
@DefectingCat
DefectingCat / mod.ts
Created April 16, 2024 01:31
Build css module className
/**
* clsx
*/
export function cn(...rest: string[]) {
return rest.join(' ');
}
/**
* 构建 cn 函数
*
@DefectingCat
DefectingCat / Tooltip.module.less
Last active April 16, 2024 01:33
Tooltip with CSS
.body {
display: flex;
}
.btn {
display: flex;
position: relative;
// &:hover {
// background: rgba(0, 0, 0, 0.15);
@DefectingCat
DefectingCat / cve.rs
Created February 28, 2024 01:26
rust memory vulnerability
fn main() {
let mut safety = &String::from("hello");
println!("address of safety {:p}: {}", &safety, safety);
{
let name = "xfy".to_string();
let name = expand(&name);
println!("address of name {:p}: {}", &name, name);
safety = &name;
}
println!("address of safety {:p}: {}", &safety, safety);
@DefectingCat
DefectingCat / password.rs
Created February 23, 2024 05:12
rust argon2 password hash
use anyhow::{anyhow, Context};
use tokio::task;
use argon2::password_hash::SaltString;
use argon2::{password_hash, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
pub async fn hash(password: String) -> anyhow::Result<String> {
task::spawn_blocking(move || {
let salt = SaltString::generate(rand::thread_rng());
Ok(Argon2::default()
@DefectingCat
DefectingCat / count.sh
Created January 30, 2024 09:22
count git commit by author
git log --since="2023-01-01" --until="2023-12-31" --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
@DefectingCat
DefectingCat / header_reader.rs
Created January 30, 2024 06:22
rust async read tcp stream as header to string
pub async fn read_headers<R>(reader: R) -> Result<String>
where
R: AsyncRead + std::marker::Unpin,
{
let mut request_string = String::new();
let mut reader = BufReader::new(reader);
loop {
let byte = reader.read_line(&mut request_string).await?;
if byte < 3 {
break;
@DefectingCat
DefectingCat / mod.rs
Created January 30, 2024 02:30
rust accept async function in generic
use std::{collections::HashMap, future::Future};
pub struct Rymo<'a, F, Fut>
where
F: FnOnce() -> Fut + 'static + Send + Sync,
Fut: Future<Output = ()>,
{
pub port: String,
pub handle: HashMap<&'a str, F>,
}
@DefectingCat
DefectingCat / proxy.rs
Last active January 26, 2024 08:30
axum reverse proxy with cache to redis
use super::error::{RouteError, RouteResult};
use crate::AppState;
use anyhow::{anyhow, Result};
use axum::{
body::Body,
extract::{Request, State},
http::{response::Parts, HeaderName, HeaderValue, Uri},
response::{IntoResponse, Response},
};
use http_body_util::BodyExt;
@DefectingCat
DefectingCat / main.rs
Created January 25, 2024 08:50
serialize and deserialize with serde_json
use anyhow::Result;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Test {
name: String,
age: i32,
test: Option<String>,
}