in reply to Nine-line Perl example of gaming a geolocation service and an open invitation to golf it
Update: Screw golf, it's not even good code.
The following is so much better, and by his count, it's only 4 lines even though it's practically not golfed:
#!/usr/bin/perl -MIO::Socket my $body = join('&', "vid=$ARGV[0]", "private=0", "geolat=".( $ARGV[1] + rand() * 0.0001 - 0.00005 ), "geolong=".( $ARGV[2] + rand() * 0.0001 - 0.00005 ), ); sleep(rand()*600); print( { my $sock = IO::Socket::INET->new( PeerAddr => 'api.foursquare.com:80', Proto => 'tcp', ) or die $! } join("\r\n", 'POST /v1/checkin HTTP/1.1', 'Host: api.foursquare.com', 'User-Agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)' .' AppleWebKit/420+ (KHTML, like Gecko)' .' Version/3.0 Mobile/1C10 Safari/419.3', 'Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic XXXXXX', 'Content-length: '.length($body), "", $body, ), ); $_ = <$sock>;
I'm not convinced that long User-Agent is required. And you can surely get away with not waiting for the reply. (Could fail, but not likely.)
I was tempted to write the User-Agent as equivalent
'User-Agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)', 'User-Agent: AppleWebKit/420+ (KHTML, like Gecko)', 'User-Agent: Version/3.0 Mobile/1C10 Safari/419.3',
|
|---|