Skip to content

Instantly share code, notes, and snippets.

View araraloren's full-sized avatar
🏠
Working from home

loren araraloren

🏠
Working from home
View GitHub Profile
@araraloren
araraloren / main.rs
Created November 24, 2023 10:53
Json parser using neure
use std::{cell::RefCell, rc::Rc};
use neure::{err::Error, prelude::*, re::rec_parser};
use re::RecursiveCtor;
static JSON: &'static [u8] = include_bytes!("../sample.json");
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@araraloren
araraloren / regex.rs
Last active August 9, 2023 14:38
Regex
use neure::*;
const KEY_ANYWHERE: usize = 0;
const KEY_PLUS: usize = 1;
const KEY_SUB: usize = 2;
const KEY_SEQ: usize = 3;
const KEY_START: usize = 4;
const KEY_END: usize = 5;
const KEY_RANGE: usize = 6;
@araraloren
araraloren / thread_pool.rs
Created June 29, 2023 13:28
Thread pool in rust research
mod thread_pool {
use std::{
fmt::Display,
ops::{Deref, DerefMut},
sync::{
mpsc::{channel, Sender},
Arc, Mutex, MutexGuard, OnceLock,
},
thread::{spawn, JoinHandle},
time::Duration,
@araraloren
araraloren / parser-example.rs
Created January 3, 2023 12:52
Parsing example of derive macro
extern crate syn;
use std::iter::FromIterator;
use proc_macro2::Ident;
use proc_macro2::TokenStream;
use proc_macro_error::abort;
use quote::TokenStreamExt;
use quote::{quote, ToTokens};
use syn::GenericArgument;
@araraloren
araraloren / aopt-help.7z
Last active December 13, 2022 13:41
Help code for aopt
57,124,190,177,41,30,2,6,57,11,193,84,39,27,2,2,2,2,2,2,37,2,2,2,2,2,2,2,78,105,151,122,226,164,220,25,234,95,2,60,158,202,203,22,204,82,139,173,83,88,233,180,137,20,190,199,229,197,131,131,41,237,225,199,165,31,80,63,121,106,88,41,245,207,62,257,203,235,113,63,44,145,194,195,223,134,50,231,15,72,244,71,116,2,247,60,247,120,211,171,234,108,235,106,52,44,186,16,128,247,168,166,135,7,99,78,113,85,229,36,118,58,155,35,160,196,184,174,3,47,38,88,204,210,171,109,137,223,244,112,235,115,33,192,157,109,226,152,174,173,132,246,110,117,17,228,40,50,71,182,72,221,123,130,82,178,255,230,22,52,55,145,105,214,82,137,240,159,64,102,131,55,210,212,63,51,147,124,228,65,100,164,227,129,165,72,9,71,157,64,37,218,144,130,131,4,17,140,227,33,179,152,71,195,74,4,177,51,190,136,256,242,13,211,165,235,56,69,48,46,115,168,159,149,81,175,172,249,230,170,150,147,219,39,25,121,184,31,178,12,230,211,163,208,6,106,207,160,196,106,92,69,43,108,206,9,135,8,198,126,119,196,87,69,113,188,253,203,88,14,79,244,164,193,126,157,86,202,250,247,18
@araraloren
araraloren / scaning-file.cpp
Created December 7, 2022 15:01
Scanning file on windows
#include <fcntl.h>
#include <fileapi.h>
#include <fstream>
#include <io.h>
#include <iostream>
#include <locale>
#include <sstream>
#include <string>
#include <vector>
#include <windows.h>
@araraloren
araraloren / macro-function.rs
Created November 28, 2022 15:14
Are these macro and funciton both same logical ?
#[derive(Debug)]
pub struct Equal(i64);
#[derive(Debug)]
pub struct Bigger(i64);
pub trait Policy: std::fmt::Debug {
fn parse(&self, val: i64) -> Result<Option<i64>, String>;
}
@araraloren
araraloren / taskpool.rs
Last active November 25, 2022 09:48
Running task in thread pool
use futures::Future; // 0.3.25
use std::pin::Pin;
use std::{
collections::VecDeque,
fs::FileType,
path::{Path, PathBuf},
time::Duration,
};
use tokio::{
sync::mpsc::{channel, Receiver, Sender},
@araraloren
araraloren / merge.rs
Created November 20, 2022 03:26
Merge sort in rust
fn merge_sort<T>(vals: &mut Vec<T>, beg: usize, end: usize)
where
T: Default + Copy + PartialOrd,
{
let mid = (beg + end) / 2;
if beg < end {
merge_sort(vals, beg, mid);
merge_sort(vals, mid + 1, end);
}
@araraloren
araraloren / quick.rs
Created November 19, 2022 07:00
Quick select in rust example.
fn quick_select<T: Debug + Clone + PartialOrd>(vals: &mut Vec<T>, pos: usize, beg: usize, end: usize) -> Option<&T> {
if beg == end {
return vals.get(pos);
}
else {
let pivot = end - 1;
let mut swap_idx = beg;
// swap the pivot to end
vals.swap(beg, pivot);