Skip to content

Instantly share code, notes, and snippets.

@badboy
Last active October 31, 2023 08:56
Show Gist options
  • Save badboy/222302b6b40ba6afc412 to your computer and use it in GitHub Desktop.
Save badboy/222302b6b40ba6afc412 to your computer and use it in GitHub Desktop.
Poor dev's Rust Compiler
fn main() {
println!("Hello World!");
}
#!/bin/bash
# Requires `jq`, because I am lazy
# jq: https://stedolan.github.io/jq/
[ $# -ne 1 ] && echo "Usage: $(basename $0) file.rs" && exit
echo "{\"channel\":\"stable\",\"crateType\":\"bin\",\"mode\":\"debug\",\"tests\":false,\"code\":\"$(sed -e 's/"/\\"/g' -e 's/$/\\n/g' $1|tr -d '\n')\"}" \
| curl -skH"Content-Type:application/json" https://play.rust-lang.org/execute -d@- \
| jq .stdout \
| sed -e 's/^"//' -e 's/"$//' -e 's/\\n/\n/g' | sed '/^$/d'
#!/bin/bash
[ $# -ne 1 ] && echo "Usage: $(basename $0) file.rs" && exit
echo "{\"channel\":\"stable\",\"crateType\":\"bin\",\"mode\":\"debug\",\"tests\":false,\"code\":\"$(sed -e 's/"/\\"/g' -e 's/$/\\n/g' $1|tr -d '\n')\"}" | curl -skH"Content-Type:application/json" https://play.rust-lang.org/execute -d@- | jq .stdout | sed -e 's/^"//' -e 's/"$//' -e 's/\\n/\n/g' | sed '/^$/d'
@inkel
Copy link

inkel commented Feb 24, 2015

You can also compress line 2 like this:

[ $# -ne 1 ] && echo "Usage: $(basename $0) file.rs" && exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment