this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add more small utilities

+117
+44
dbg_server
··· 1 + #!/usr/bin/env -S cargo eval -- 2 + 3 + // cargo-deps: argh = "0.1" 4 + 5 + use argh::FromArgs; 6 + 7 + use std::net::TcpListener; 8 + use std::io::BufRead; 9 + use std::io::BufReader; 10 + use std::str; 11 + 12 + #[derive(FromArgs)] 13 + #[argh(description = "simple debug server which logs the data sent to it.")] 14 + struct App { 15 + #[argh( 16 + option, 17 + description = "interface to listen on.", 18 + default = "\"0.0.0.0\".to_string()" 19 + )] 20 + host: String, 21 + 22 + #[argh(option, description = "port to listen on.", default = "7331")] 23 + port: u16, 24 + } 25 + 26 + fn main() { 27 + let app: App = argh::from_env(); 28 + 29 + let address = format!("{}:{}", app.host, app.port); 30 + let listener = TcpListener::bind(&address).expect("should be able to start server"); 31 + 32 + println!("Listening on {}", address); 33 + 34 + for stream in listener.incoming() { 35 + let stream = stream.expect("stream should be present"); 36 + let mut stream = BufReader::new(stream); 37 + 38 + // This is not the "best" way to get the data sent over 39 + // but it sure is the easiest :^) 40 + let data = stream.fill_buf().expect("should have data"); 41 + let output = str::from_utf8(data).expect("should be able to parse data as text"); 42 + println!("{}", output); 43 + } 44 + }
+44
flush_cache
··· 1 + #!/usr/bin/env -S cargo eval -- 2 + 3 + // cargo-deps: argh = "0.1" 4 + 5 + use argh::FromArgs; 6 + 7 + use std::net::Shutdown; 8 + use std::net::TcpStream; 9 + use std::io::BufRead; 10 + use std::io::BufReader; 11 + use std::io::Write; 12 + 13 + const FLUSH_COMMAND: &str = "FLUSHALL\r\n"; 14 + 15 + #[derive(FromArgs)] 16 + #[argh(description = "Flush the cache of a redis instance.")] 17 + struct App { 18 + #[argh( 19 + option, 20 + description = "host for the redis instance.", 21 + default = "\"127.0.0.1\".to_string()" 22 + )] 23 + host: String, 24 + 25 + #[argh(option, description = "port redis is listening on.", default = "6379")] 26 + port: u16, 27 + } 28 + 29 + fn main() { 30 + let app: App = argh::from_env(); 31 + 32 + let address = format!("{}:{}", app.host, app.port); 33 + let mut stream = TcpStream::connect(address).expect("should be able to connect to redis"); 34 + 35 + stream.write(FLUSH_COMMAND.as_bytes()).expect("should be able to write flush command"); 36 + stream.flush().expect("should be able to send flush command"); 37 + stream.shutdown(Shutdown::Write).expect("should be able to shutdown writer"); 38 + 39 + let mut stream = BufReader::new(stream); 40 + 41 + let mut output = String::new(); 42 + let _ = stream.read_line(&mut output).expect("should be able to read response"); 43 + println!("{}", &output); 44 + }
+29
tag_release
··· 1 + #!/usr/bin/env -S cargo eval -- 2 + 3 + // cargo-deps: argh = "0.1", chrono = "0.4" 4 + 5 + use argh::FromArgs; 6 + use chrono::prelude::*; 7 + 8 + #[derive(FromArgs)] 9 + #[argh(description = "Simple program to kill a process listening on a specific port.")] 10 + struct App { 11 + #[argh( 12 + option, 13 + description = "how to format the date tag.", 14 + default = "\"v%Y%m%d-%H%M\".to_string()" 15 + )] 16 + format: String, 17 + } 18 + 19 + fn main() { 20 + let app: App = argh::from_env(); 21 + 22 + 23 + let tag = Utc::now().format(&app.format).to_string(); 24 + 25 + println!("# Run the following to tag and release this version"); 26 + println!(); 27 + println!("git tag -a {} -m \"\"", tag); 28 + println!("git push origin --tags"); 29 + }