daemon

Daemon In computing, a daemon (also spelled demon) is a computer program that runs in the background, performing tasks without direct user interaction. It’s like a helpful assistant that quietly handles various system operations Backlinks rust daemonize

August 5, 2025 · 1 min · Kristian Alexander P

rust daemonize

Example of daemonizing in Rust use daemonize::Daemonize; fn main() { let daemonize = Daemonize::new() .pid_file("/tmp/my_daemon.pid") // Optional: Write PID to file .chown_pid_file(true) // Optional: Change ownership .working_directory("/tmp") // Optional: Set working directory .privileged_action(|| "Executed before drop privileges"); match daemonize.start() { Ok(_) => { // Daemon logic goes here println!("Daemon started successfully!"); loop { // Do daemon work std::thread::sleep(std::time::Duration::from_secs(5)); } }, Err(e) => eprintln!("Error, {}", e), } }

August 5, 2025 · 1 min · Kristian Alexander P

rust env test

Getting Environment variables In Rust, we use std::env use std::env; fn main() { let x = env::vars(); for (a, b) in x { println!("{:?} {:?}", a, b) } } "ALTERNATE_EDITOR" "emacsclient -c " "BASH_FUNC_pathappend%%" "() { pathremove \"${1}\" \"${2}\";\n local PATHVARIABLE=${2:-PATH};\n export \"$PATHVARIABLE\"=\"${!PATHVARIABLE:+${!PATHVARIABLE}:}$1\"\n}" "BASH_FUNC_pathprepend%%" "() { pathremove \"${1}\" \"${2}\";\n local PATHVARIABLE=${2:-PATH};\n export \"$PATHVARIABLE\"=\"$1${!PATHVARIABLE:+:${!PATHVARIABLE}}\"\n}" "BASH_FUNC_pathremove%%" "() { local IFS=':';\n local NEWPATH;\n local DIR;\n local PATHVARIABLE=${2:-PATH};\n for DIR in ${!PATHVARIABLE};\n do\n if [ \"${DIR}\" != \"${1}\" ]; then\n NEWPATH=${NEWPATH:+$NEWPATH:}$DIR;\n fi;\n done;\n export \"$PATHVARIABLE\"=\"${NEWPATH}\"\n}" "BROWSER" "firefox" "CARGO" "/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "CARGO_HOME" "/home/alexforsale/.cargo" "CARGO_MANIFEST_DIR" "/tmp/babel-5iTIx3/cargoDOdDFj" "CARGO_MANIFEST_PATH" "/tmp/babel-5iTIx3/cargoDOdDFj/Cargo.toml" "CARGO_PKG_AUTHORS" "" "CARGO_PKG_DESCRIPTION" "" "CARGO_PKG_HOMEPAGE" "" "CARGO_PKG_LICENSE" "" "CARGO_PKG_LICENSE_FILE" "" "CARGO_PKG_NAME" "cargoDOdDFj" "CARGO_PKG_README" "" "CARGO_PKG_REPOSITORY" "" "CARGO_PKG_RUST_VERSION" "" "CARGO_PKG_VERSION" "0.1.0" "CARGO_PKG_VERSION_MAJOR" "0" "CARGO_PKG_VERSION_MINOR" "1" "CARGO_PKG_VERSION_PATCH" "0" "CARGO_PKG_VERSION_PRE" "" "CLICOLOR" "1" "DBUS_SESSION_BUS_ADDRESS" "unix:path=/run/user/1000/bus" "DEBUGINFOD_URLS" "https://debuginfod.archlinux.org " "DESKTOP_SESSION" "i3" "DISPLAY" ":0" "DISTRO" "arch" "DISTROVER" "rolling" "EDITOR" "emacsclient -t " "FILE" "emacsclient -c -e (dired-jump)" "GOPATH" "/home/alexforsale/.local" "GPG_TTY" "/dev/tty1" "GTK2_RC_FILES" "/home/alexforsale/.config/gtk-2.0/gtkrc" "GTK_MODULES" "canberra-gtk-module" "GTK_RC_FILES" "/home/alexforsale/.config/gtk-1.0/gtkrc" "GTK_THEME" "Breeze-Dark" "HG" "/usr/bin/hg" "HISTFILE" "/home/alexforsale/.local/share/bash/bash_history" "HOME" "/home/alexforsale" "I3SOCK" "/run/user/1000/i3/ipc-socket.2313" "LANG" "en_US.UTF-8" "LD_LIBRARY_PATH" "/tmp/babel-5iTIx3/cargoDOdDFj/target/debug/deps:/tmp/babel-5iTIx3/cargoDOdDFj/target/debug:/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib" "LOGNAME" "alexforsale" "LS_COLORS" "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.7z=01;31:*.ace=01;31:*.alz=01;31:*.apk=01;31:*.arc=01;31:*.arj=01;31:*.bz=01;31:*.bz2=01;31:*.cab=01;31:*.cpio=01;31:*.crate=01;31:*.deb=01;31:*.drpm=01;31:*.dwm=01;31:*.dz=01;31:*.ear=01;31:*.egg=01;31:*.esd=01;31:*.gz=01;31:*.jar=01;31:*.lha=01;31:*.lrz=01;31:*.lz=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.lzo=01;31:*.pyz=01;31:*.rar=01;31:*.rpm=01;31:*.rz=01;31:*.sar=01;31:*.swm=01;31:*.t7z=01;31:*.tar=01;31:*.taz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tgz=01;31:*.tlz=01;31:*.txz=01;31:*.tz=01;31:*.tzo=01;31:*.tzst=01;31:*.udeb=01;31:*.war=01;31:*.whl=01;31:*.wim=01;31:*.xz=01;31:*.z=01;31:*.zip=01;31:*.zoo=01;31:*.zst=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.jxl=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:" "MAIL" "/var/spool/mail/alexforsale" "MAIL_APP" "thunderbird" "MM_CHARSET" "en_US.UTF-8" "MONITOR1" "DP-1" "MOTD_SHOWN" "pam" "PATH" "/home/alexforsale/.local/perl5/bin:/home/alexforsale/.ghcup/bin:/home/alexforsale/.cargo/bin:/home/alexforsale/.cabal/bin:/home/alexforsale/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin" "PERL5LIB" "/home/alexforsale/.local/perl5/lib/perl5" "PERL_LOCAL_LIB_ROOT" "/home/alexforsale/.local/perl5" "PERL_MB_OPT" "--install_base \"/home/alexforsale/.local/perl5\"" "PERL_MM_OPT" "INSTALL_BASE=/home/alexforsale/.local/perl5" "PWD" "/tmp/babel-5iTIx3/cargoDOdDFj" "QT_XCB_GL_INTEGRATION" "none" "RUSTUP_HOME" "/home/alexforsale/.rustup" "RUSTUP_TOOLCHAIN" "stable-x86_64-unknown-linux-gnu" "RUST_BACKTRACE" "0" "RUST_RECURSION_COUNT" "1" "SCREENDIR" "/home/alexforsale/.config/screen" "SCREENRC" "/home/alexforsale/.config/screen/config" "SHELL" "/usr/bin/bash" "SHLVL" "2" "SSH_AGENT_PID" "2186" "SSH_ASKPASS" "ssh-askpass" "SSH_AUTH_SOCK" "/tmp/ssh-XXXXXXZtMjDO/agent.2185" "SSL_CERT_DIR" "/etc/ssl/certs" "SSL_CERT_FILE" "/etc/ssl/cert.pem" "SUDO_ASKPASS" "/home/alexforsale/.local/bin/ssh-askpass" "TERM" "ansi" "TERMINAL" "alacritty" "USER" "alexforsale" "VISUAL" "emacsclient -c " "WINDOWPATH" "1" "XAUTHORITY" "/home/alexforsale/.Xauthority" "XCURSOR_PATH" ":/usr/share/icons:/home/alexforsale/.local/share/icons" "XCURSOR_SIZE" "24" "XCURSOR_THEME" "Bibata-Modern-Classic" "XDG_CACHE_HOME" "/home/alexforsale/.cache" "XDG_CONFIG_HOME" "/home/alexforsale/.config" "XDG_DATA_DIRS" "/usr/share:/usr/local/share" "XDG_DATA_HOME" "/home/alexforsale/.local/share" "XDG_DESKTOP_DIR" "/home/alexforsale/Desktop" "XDG_DOCUMENTS_DIR" "/home/alexforsale/Documents" "XDG_DOWNLOAD_DIR" "/home/alexforsale/Downloads" "XDG_MUSIC_DIR" "/home/alexforsale/Music" "XDG_PICTURES_DIR" "/home/alexforsale/Pictures" "XDG_PUBLICSHARE_DIR" "/home/alexforsale/Public" "XDG_RUNTIME_DIR" "/run/user/1000" "XDG_SEAT" "seat0" "XDG_SESSION_CLASS" "user" "XDG_SESSION_ID" "1" "XDG_SESSION_TYPE" "tty" "XDG_TEMPLATES_DIR" "/home/alexforsale/Templates" "XDG_VIDEOS_DIR" "/home/alexforsale/Videos" "XDG_VTNR" "1" "_" "/usr/bin/emacs" "npm_config_prefix" "/home/alexforsale/.local" Specific Variable std::env::var returns a Result<String, VarError>. ...

August 2, 2025 · 2 min · Kristian Alexander P

rust external command

use std::process::Command; fn main() { let mut list_dir = Command::new("ls"); list_dir.status().expect("process failed to execute"); println!(); } Cargo.lock Cargo.toml src target

August 2, 2025 · 1 min · Kristian Alexander P

rust fib

fn fib(x: i32) -> i32 { match x { 0 => 0, 1 => 1, _ => fib(x -1) + fib(x -2), } } fn main() { for a in 0..=10 { println!("fib {} is: {}", a, fib(a)) } } fib 0 is: 0 fib 1 is: 1 fib 2 is: 1 fib 3 is: 2 fib 4 is: 3 fib 5 is: 5 fib 6 is: 8 fib 7 is: 13 fib 8 is: 21 fib 9 is: 34 fib 10 is: 55 use std::collections::HashMap; fn memoized_fib(n: u64, memo: &mut HashMap<u64, u64>) -> u64 { if memo.contains_key(&n) { return *memo.get(&n).unwrap(); } let result = match n { 0 => 0, 1 => 1, _ => memoized_fib(n - 1, memo) + memoized_fib(n - 2, memo), }; memo.insert(n, result); result } fn main() { let mut memo: HashMap<u64, u64> = HashMap::new(); for x in 0..=20 { println!("fib ({}): {}", x, memoized_fib(x, &mut memo)); } } fib (0): 0 fib (1): 1 fib (2): 1 fib (3): 2 fib (4): 3 fib (5): 5 fib (6): 8 fib (7): 13 fib (8): 21 fib (9): 34 fib (10): 55 fib (11): 89 fib (12): 144 fib (13): 233 fib (14): 377 fib (15): 610 fib (16): 987 fib (17): 1597 fib (18): 2584 fib (19): 4181 fib (20): 6765

August 2, 2025 · 2 min · Kristian Alexander P

alacritty

Alacritty is a simple, GPU-accelerated terminal emulator written in Rust. It supports scrollback, 24-bit colors, copy/paste, clicking on URLs, and custom key bindings.

August 1, 2025 · 1 min · Kristian Alexander P

dmenu

dmenu is a fast and lightweight dynamic menu for X. It reads arbitrary text from stdin, and creates a menu with one item for each line. The user can then select an item, through the arrow keys or typing a part of the name, and the line is printed to stdout. dmenu_run is a wrapper that ships with the dmenu distribution that allows its use as an application launcher. Backlinks rofi

August 1, 2025 · 1 min · Kristian Alexander P

fd

fd is a program written in Rust to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find. While it does not aim to support all of find’s powerful functionality, it provides sensible (opinionated) defaults for a majority of use cases.

August 1, 2025 · 1 min · Kristian Alexander P

firefox

Firefox is a popular open source graphical web browser from Mozilla.

August 1, 2025 · 1 min · Kristian Alexander P

fonts

A computer font is implemented as a digital data file containing a set of graphically related glyphs. A computer font is designed and created using a font editor. A computer font specifically designed for the computer screen, and not for printing, is a screen font. Formats Bitmap fonts Outline or vector fonts Backlinks gtk

August 1, 2025 · 1 min · Kristian Alexander P