The network is the computer. ... and the planet is now overheating.
Internet, the great CO2 production device. http://www.internetlivestats.com/watch/co2-emissions/ Phil On Thu, Mar 24, 2016 at 8:58 PM, Sven Van Caekenberghe <s...@stfx.eu> wrote: > This is a really great joke: > > > http://left-pad.io/ <http://left-pad.io/> > > But should you feel the need to implement this extremely valuable web > service yourself, here is how you could do it in Pharo (error handling is > not 100% bullet proof, this is just a quick demo, but you get the idea): > > 'paddin'' oswalt' padLeftTo: 68 with: $@. > > (ZnServer startDefaultOn: 8080) > onRequestRespond: [ :req | > | str len ch | > str := req uri queryAt: #str ifAbsent: [ '' ]. > len := req uri queryAt: #len ifAbsent: [ '' ]. > len := Integer readFrom: len ifFail: [ 0 ]. > ch := (req uri queryAt: #ch ifAbsent: [ ' ' ]) first. > ZnResponse ok: (ZnEntity text: (str padLeftTo: len with: ch)) ]. > > ZnClient new > host: #localhost; > port: 8080; > queryAt: #str put: 'paddin'' oswalt'; > queryAt: #len put: 68; > queryAt: #ch put: $@; > get. > > $ curl 'http://localhost:8080/?str=paddin%27%20oswalt&len=68&ch=@' > > Of course, if you are really going this into production, you'll have to > pay me and Pharo the necessary royalties ;-) > > Sven > > PS: Returning a JSON (which does not really make sense here) is left as an > exercise. > > > >