4 ms·
Or, just for fun, in Sinatra - http://sinatra.rubyforge.org/ http://sinatra.rubyforge.org/ : require 'sinatra' get '/' do %{<html><body> <h1>#{T
by petercooper 18y ago
Or, just for fun, in Sinatra - http://sinatra.rubyforge.org/ http://sinatra.rubyforge.org/ :
require 'sinatra'
get '/' do
%{<html><body>
<h1>#{Time.now.mday == 25 && Time.now.month == 12 ? "YES" : "NO"}</h1>
</body></html>}
end
Sure, no internationalization or adaptation to local time, but I'd arrogantly assume most Internet users can understand YES and NO as well as I understand JA and NEIN or OUI and NON (apologies to speakers of non-Latin derived languages.. :))
- jrockway 18y agoTime.now.mday == 25 && Time.now.month == 12 ? "YES" : "NO" This will return the wrong answer if the first expression is evaluated on, say, November 25th and the second half of the expression isn't evaluated until December 1st. Very buggy ;)
- jackowayed 18y agoYeah, he should really define a function that spawns threads to evaluate each of those boolean pieces to speed it up and keep that bug from happening.
- DougBTX 18y agoI'm never sure what to make of posts like this. Sure, it is a short code snippet that works some of the time, but the original was trying to solve a more difficult problem. This code doesn't even try. What good is pretty code if it only runs on localhost? Oh, and if you really do only care about localhost, there isn't much difference between the Sinatra/Ruby code and PHP: <?php $date = getdate(); ?> <html><body> <h1><?php echo $date[mday] == 25 && $date[mon] == 12 ? "YES" : "NO" ?></h1> </body></html>
- petercooper 18y agoIf you stuck to just UTC, you could run it anywhere and it'd be logically (though not pragmatically) correct. In any case, I was being flippant because I thought the original was a joke of sorts. It was amusingly overengineered, so I thought I'd go too far in the opposite direction to play devil's advocate, as it were.
- almost 18y agoEven better, in Python! print "NO" It's missing some internationalization and it'll probably fail every now and then (but less than 0.03% of the time) but you'll have to agree it is very concise. Sorry, I'll shut up now :p