• 0 Posts
  • 12 Comments
Joined 2 years ago
cake
Cake day: June 12th, 2023

help-circle



  • Wouldn’t say I use it often, but this thing resolves a domain name to an IP address:

    function resolve() {
      case $1 in
        -4)
          getent ahostsv4 $2 | grep STREAM | head -n 1 | cut -d ' ' -f 1
          ;;
        -6)
          getent ahostsv6 $2 | grep STREAM | head -n 1 | cut -d ' ' -f 1
          ;;
        -p)
          getent hosts $2 | head -n 1 | cut -d ' ' -f 1
          ;;
        *)
          getent ahosts $1 | grep STREAM | cut -d ' ' -f 1 | sort -u      
          ;;
      esac
    }
    

    All my aliases are just default arguments for programs or shorthands for my other scripts, most of which are specific for my setup.

    This is a very good argument for ffmpeg and ffprobe, by the way:

    alias ffmpeg="ffmpeg -hide_banner"
    alias ffprobe="ffprobe -hide_banner"
    

  • I gladly present you this jank.

    You might need these to compile:

    cargo add image
    cargo add clap --features derive
    

    And the jank itself:

    Some Rust code
    use std::path::PathBuf;
    
    use clap::Parser;
    use image::{ imageops::{self, FilterType}, ImageReader };
    
    #[derive(Parser)]
    struct Cli {
        path: PathBuf,
        #[arg(short = 'H', long, default_value_t = 30)]
        height: u32,
        #[arg(short, long, default_value_t = 0.4)]
        ratio: f32,
        #[arg(short, long, default_value_t, value_enum)]
        filter: Filter,
    }
    
    #[derive(clap::ValueEnum, Clone, Default)]
    enum Filter {
        Nearest,
        Triangle,
        Gaussian,
        CatmullRom,
        #[default]
        Lanczos3,
    }
    
    fn main() -> Result<(), Box<dyn std::error::Error>> {
        let args = Cli::parse();
        let filter = match args.filter {
            Filter::Nearest    => { FilterType::Nearest },
            Filter::Triangle   => { FilterType::Triangle },
            Filter::CatmullRom => { FilterType::CatmullRom },
            Filter::Gaussian   => { FilterType::Gaussian },
            Filter::Lanczos3   => { FilterType::Lanczos3 },
        };
        let img = ImageReader::open(args.path)?.decode()?;
        let original_ratio = img.width() as f32 / img.height() as f32;
        let width = ( args.height as f32 / args.ratio ) * original_ratio;
        let out = imageops::resize(&img, width as u32, args.height * 2, filter);
        let mut iter = out.enumerate_rows();
        while let Some((_, top)) = iter.next() {
            let (_, bottom) = iter.next().unwrap();
            top.zip(bottom)
                .for_each(|((_, _, t), (_, _, b))| {
                    print!("\x1B[38;2;{};{};{};48;2;{};{};{}m\u{2584}", b[0], b[1], b[2], t[0], t[1], t[2])
                });
            println!("\x1B[0m");
        }
        Ok(())
    }
    

  • Assuming you made a bit of a typo with your regexp, any of these should work as you want:

    grep -oE '/dev/loop[0-9]+'
    awk 'match($0, /\/dev\/loop[0-9]+/) { print substr($0, RSTART, RLENGTH) }'
    sed -r 's%.*(/dev/loop[0-9]+).*%\1%'
    

    AWK one is a bit cursed as you can see. Such ways of manipulating text is not exactly it’s strong suite.




  • For the love of all that’s saint, can we please stop recommending Manjaro to people, especially newbies?

    It’s not really a preference thing, Manjaro team did plenty of questionable stuff with it, as in DDoSing AUR, mind you, twice, or letting their server certificates expire, also more than once.

    It also routinely shows more stability issues that led to the infamous “I swear to god, if it’s Manjaro again…” in AUR discussions. Apart from AUR problems, they also shipped alpha quality things to their users, like this and this.

    I’ve used Manjaro myself for around a month. If you are treating it as a regular Arch installation, you will break it.

    If you want something up to date, but more stable than Arch, just use Fedora. If you insist on it being Arch-based, use something like CachyOS. Or you can read the wiki and install Arch itself. Arch is a DIY distro, after all.