···11+#!/usr/bin/env -S cargo eval --
22+33+// cargo-deps: argh = "0.1"
44+55+use argh::FromArgs;
66+77+use std::net::TcpListener;
88+use std::io::BufRead;
99+use std::io::BufReader;
1010+use std::str;
1111+1212+#[derive(FromArgs)]
1313+#[argh(description = "simple debug server which logs the data sent to it.")]
1414+struct App {
1515+ #[argh(
1616+ option,
1717+ description = "interface to listen on.",
1818+ default = "\"0.0.0.0\".to_string()"
1919+ )]
2020+ host: String,
2121+2222+ #[argh(option, description = "port to listen on.", default = "7331")]
2323+ port: u16,
2424+}
2525+2626+fn main() {
2727+ let app: App = argh::from_env();
2828+2929+ let address = format!("{}:{}", app.host, app.port);
3030+ let listener = TcpListener::bind(&address).expect("should be able to start server");
3131+3232+ println!("Listening on {}", address);
3333+3434+ for stream in listener.incoming() {
3535+ let stream = stream.expect("stream should be present");
3636+ let mut stream = BufReader::new(stream);
3737+3838+ // This is not the "best" way to get the data sent over
3939+ // but it sure is the easiest :^)
4040+ let data = stream.fill_buf().expect("should have data");
4141+ let output = str::from_utf8(data).expect("should be able to parse data as text");
4242+ println!("{}", output);
4343+ }
4444+}
+44
flush_cache
···11+#!/usr/bin/env -S cargo eval --
22+33+// cargo-deps: argh = "0.1"
44+55+use argh::FromArgs;
66+77+use std::net::Shutdown;
88+use std::net::TcpStream;
99+use std::io::BufRead;
1010+use std::io::BufReader;
1111+use std::io::Write;
1212+1313+const FLUSH_COMMAND: &str = "FLUSHALL\r\n";
1414+1515+#[derive(FromArgs)]
1616+#[argh(description = "Flush the cache of a redis instance.")]
1717+struct App {
1818+ #[argh(
1919+ option,
2020+ description = "host for the redis instance.",
2121+ default = "\"127.0.0.1\".to_string()"
2222+ )]
2323+ host: String,
2424+2525+ #[argh(option, description = "port redis is listening on.", default = "6379")]
2626+ port: u16,
2727+}
2828+2929+fn main() {
3030+ let app: App = argh::from_env();
3131+3232+ let address = format!("{}:{}", app.host, app.port);
3333+ let mut stream = TcpStream::connect(address).expect("should be able to connect to redis");
3434+3535+ stream.write(FLUSH_COMMAND.as_bytes()).expect("should be able to write flush command");
3636+ stream.flush().expect("should be able to send flush command");
3737+ stream.shutdown(Shutdown::Write).expect("should be able to shutdown writer");
3838+3939+ let mut stream = BufReader::new(stream);
4040+4141+ let mut output = String::new();
4242+ let _ = stream.read_line(&mut output).expect("should be able to read response");
4343+ println!("{}", &output);
4444+}
+29
tag_release
···11+#!/usr/bin/env -S cargo eval --
22+33+// cargo-deps: argh = "0.1", chrono = "0.4"
44+55+use argh::FromArgs;
66+use chrono::prelude::*;
77+88+#[derive(FromArgs)]
99+#[argh(description = "Simple program to kill a process listening on a specific port.")]
1010+struct App {
1111+ #[argh(
1212+ option,
1313+ description = "how to format the date tag.",
1414+ default = "\"v%Y%m%d-%H%M\".to_string()"
1515+ )]
1616+ format: String,
1717+}
1818+1919+fn main() {
2020+ let app: App = argh::from_env();
2121+2222+2323+ let tag = Utc::now().format(&app.format).to_string();
2424+2525+ println!("# Run the following to tag and release this version");
2626+ println!();
2727+ println!("git tag -a {} -m \"\"", tag);
2828+ println!("git push origin --tags");
2929+}