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
use neure::{ctx::re_policy, prelude::*};
const DATA: &str = include_str!("../input.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = re::array(['&', '=']).not().repeat_one_more();
let val = re::array(['\'', '&', '=']).not().repeat_one_more();
let query = key.sep_once("=", val).sep("&");
let url = '?'.not().repeat_one_more().sep_once("?", query);
let key = re::array(['\'', ':']).not().repeat_one_more();
@araraloren
araraloren / calc_parser.rs
Created March 19, 2024 13:13
A parser example for calcuate expression.
use std::iter::once;
use neure::{neu::digit, prelude::*, re::rec_parser};
#[derive(Debug)]
pub enum Expr<'a> {
Int(i64),
Op(&'a str),
@araraloren
araraloren / main.rs
Created February 26, 2024 12:02
Using specialization take item from tuple
pub trait TakeOut<T, R> {
type Rem;
fn take_out(self) -> (T, Self::Rem);
}
pub struct __First;
impl<Head, Tail> TakeOut<Head, __First> for (Head, Tail) {
type Rem = Tail;
@araraloren
araraloren / main.py
Created February 24, 2024 15:54
Python using PySide6 in vscode
import sys
from pathlib import Path
from PySide6.QtGui import QGuiApplication
from PySide6.QtCore import QUrl, QObject, Slot
from PySide6.QtQml import QQmlApplicationEngine, QmlElement
QML_IMPORT_NAME = "com.bridge.py"
QML_IMPORT_MAJOR_VERSION = 1
@araraloren
araraloren / main.rs
Created February 24, 2024 07:38
Detect key press
use std::{
io::stdout,
time::{Duration, Instant},
};
use crossterm::{
cursor::MoveToNextLine,
event::{poll, read, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
style,
terminal::{disable_raw_mode, enable_raw_mode},
@araraloren
araraloren / playground.rs
Created February 3, 2024 12:58 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![crate_type = "proc-macro"]
use proc_macro2::Ident;
use proc_macro2::Literal;
use quote::quote;
use syn::{parse_macro_input, spanned::Spanned, ItemFn};
///
///```
/// use playground::named;
@araraloren
araraloren / xml.rs
Created December 19, 2023 15:05
Xml parser
use neure::{
err::Error,
prelude::*,
re::{rec_parser, RecursiveCtor},
};
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
#[derive(Debug, PartialEq, Eq)]
@araraloren
araraloren / shadow.rs
Created December 8, 2023 11:36
Rust shadow
use neure::prelude::*;
const INPUT: &str = include_str!("../input.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> {
let nl = '\n'.repeat_one();
let sp = " ".ws();
let num = neu::digit(10);
let num = num.repeat_one_more();
let num = num.map(re::map::from_str_radix::<i64>(10));
@araraloren
araraloren / day3-1.rs
Last active December 5, 2023 12:59
Advent of Code 2023
use neure::prelude::*;
const INPUT: &str = include_str!("../input.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Debug)]
enum T {
S(usize),
N((usize, usize, i32)),
}
@araraloren
araraloren / day1-1.rs
Last active December 4, 2023 12:41
Advent of Code 2023
const INPUT: &str = include_str!("../input.txt");
use neure::prelude::*;
fn main() {
let line_re = neu::digit(10)
.repeat_one()
.map(re::map::from_str_radix::<i32>(10))
.padded(neu::ascii_alphabetic().repeat_zero_more())
.repeat(1..)