Sprunge this! Sprunge that!

7

Your task is to create a program or function that creates a paste on sprunge.us. Your program/function must receive the text to sprunge from your language's usual input mechanism, such as standard in; or in the case of a function, it can be a string or whatever makes the most sense to you. Your program will POST the text from input to http://sprunge.us/ as multipart/form-data with the form field name of sprunge. Finally, your program will output/return the URL sent back in the reply from the POST.

This is a code golf, so shortest answer (in bytes) wins.

Here is an example solution using bash and curl taken directly from the sprunge.us website. Feel free to use it in your own golf:

curl -F 'sprunge=<-' http://sprunge.us

Which returns the URL to the paste, which looks like http://sprunge.us/aXZI, where the aXZI is the ID of the sprunge.

This is my first code golfing challenge, please let me know if this is too easy or not creative enough

Winny

Posted 2016-12-25T12:11:27.603

Reputation: 1 120

So, you're not allowed to write a function? Nice challenge, by the way. – XavCo7 – 2016-12-25T18:44:23.013

Correct, it must be a complete program. Thanks by the way. I have a feeling there might not be much room for improvement from the curl example... I could make this a popularity contest if that's the case. – Winny – 2016-12-25T19:20:13.120

2sprunge seems to be down (503)? – devRicher – 2016-12-25T22:41:15.643

Bummer! :( Maybe I should remake this question to use ptpb.pw...

– Winny – 2016-12-26T02:37:18.237

@devRicher looks like it's back up, sorry about that. I have no control over sprunge.us. – Winny – 2016-12-26T05:43:46.643

Why can't we write a function? – Rɪᴋᴇʀ – 2016-12-27T15:37:49.903

And I doubt anybody will improve on that curl code. (though if I've golfed the code, can I post an answer using the golfed curl code?) – Rɪᴋᴇʀ – 2016-12-27T15:38:49.433

I'm going to revise the question to allow functions & yes you can base your solution off my example. – Winny – 2016-12-28T02:58:15.297

I agree the example I gave was a bit too concise for a code golf challenge. With any luck, somebody will come up with a curious alterative. – Winny – 2016-12-28T03:04:15.720

Answers

1

Bash, 29 25 bytes

curl -F sprunge{=\<-,.us}

Thanks to @Score_Under for providing this awesome solution!

Old solution:

curl -Fsprunge=\<- sprunge.us

Quotes around 'sprunge=<-' are unnecessary, as long as the < is escaped.

EDIT: Interestingly, this alternative way has the exact same length:

a=sprunge
curl -F$a=\<- $a.us

markasoftware

Posted 2016-12-25T12:11:27.603

Reputation: 346

1Can be shorter with careful use of brace expansion: curl -F sprunge{=\<-,.us} – Score_Under – 2017-07-05T01:23:10.850

@Score_Under Thanks! updated – markasoftware – 2017-07-15T16:38:26.250

@Markasoftware The space between F and s is important. – Anders Kaseorg – 2017-07-16T00:05:22.687

2

Bash, 30 bytes

curl -F'sprunge=<-' sprunge.us

Just removed the unneeded space in -F 'sprunge=<-' and the http:// from the sprunge.us url. OP gave me explicit permission to golf his reference solution.

Rɪᴋᴇʀ

Posted 2016-12-25T12:11:27.603

Reputation: 7 410

2

HTML, 88 bytes

<form action="http:sprunge.us" method="POST"><textarea></textarea><button type="submit">

To test this easily, prepend data:text/html, to the code and paste it into your address bar (works for me on chrome).

Full (easily) testable code:

data:text/html,<form action="http:sprunge.us" method="POST"><textarea></textarea><button type="submit">

Rɪᴋᴇʀ

Posted 2016-12-25T12:11:27.603

Reputation: 7 410

You ought to be able to replace http: with //. – Jordan – 2017-01-05T03:03:16.217

@Jordan not for me? I think that looks for a file, not a http:// address. – Rɪᴋᴇʀ – 2017-01-05T03:48:58.573

//sprunge.us is a protocol-relative URL, so if it appears on an HTTPS site it'll resolve to https://sprunge.us and if it appears on an HTTP site it'll resolve to http://sprunge.us, so it might not work if you're trying it on an HTTPS site and sprunge.us only works with HTTP. Barring that, I dunno, and I'm not at a computer so it's impractical for me to test. Sorry! – Jordan – 2017-01-05T03:52:12.553

@Jordan it doesn't work, that's all I know. – Rɪᴋᴇʀ – 2017-01-05T14:34:45.760