2
1
Your goal in this code golf is to compile all the Stack Exchange sites' favicons.
Getting the Domains
The domains you will be using will be:
*.stackexchange.com
stackexchange.com
stackoverflow.com
superuser.com
serverfault.com
askubuntu.com
mathoverflow.net
stackapps.com
stackauth.com
Everything but stackexchange.com
and stackauth.com
, as of now, can be gathered from /sites
.
All the meta counterparts will also be included. (just prepend meta.
to the beginning of any of the domains to get the meta site)
The list above shows the order of the sites. Sites without their own domain (*.stackexchange.com
, i.e. codegolf.stackexchange.com
) are first in the stylesheet, and are sorted alphabetically. After you've sorted the subdomain sites, the rest of the domains are in the order listed above.
Then, you can append /favicon.ico
to each one of the domains you dynamically compiled and get the 32 by 32 pixel image that results from it.
Here's another list for domains that redirect to *.stackexchange.com
sites:
askdifferent.com
→apple.stackexchange.com
arqade.com
→gaming.stackexchange.com
seasonedadvice.com
→cooking.stackexchange.com
Output the Images
As soon as you have all of the favicons from the sites and their meta counterparts, your code combines them. Optionally, convert them into .PNG files (you gathered .ICOs, and trying to get favicon.png
doesn't work) After that, you can start combining the images into one rectangle.
There will be 10 columns, each 32 pixels in width, making a total of 320 pixels. The number of rows will match those needed to fit all the favicons, and they are 32 pixels in height.
Your code should output an image with all of the favicons you gathered as a transparent .PNG file, which is already , like seen below:
Scoring
This is code-golf and so the least bytes wins!
Leaderboard
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
# Language Name, N bytes
where N
is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
# Ruby, <s>104</s> <s>101</s> 96 bytes
var QUESTION_ID=86753;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var a=!1,r=e.body_markdown.split("\n");try{a|=/^#/.test(e.body_markdown),a|=["-","="].indexOf(r[1][0])>-1,a&=LANGUAGE_REG.test(e.body_markdown)}catch(n){}return a}function shouldHaveScore(e){var a=!1;try{a|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(r){}return a}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.sort(function(e,a){var r=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0],n=+(a.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0];return r-n});var e={},a=1,r=null,n=1;answers.forEach(function(s){var t=s.body_markdown.split("\n")[0],o=jQuery("#answer-template").html(),l=(t.match(NUMBER_REG)[0],(t.match(SIZE_REG)||[0])[0]),c=t.match(LANGUAGE_REG)[1],i=getAuthorName(s);l!=r&&(n=a),r=l,++a,o=o.replace("{{PLACE}}",n+".").replace("{{NAME}}",i).replace("{{LANGUAGE}}",c).replace("{{SIZE}}",l).replace("{{LINK}}",s.share_link),o=jQuery(o),jQuery("#answers").append(o),e[c]=e[c]||{lang:c,user:i,size:l,link:s.share_link}});var s=[];for(var t in e)e.hasOwnProperty(t)&&s.push(e[t]);s.sort(function(e,a){return e.lang>a.lang?1:e.lang<a.lang?-1:0});for(var o=0;o<s.length;++o){var l=jQuery("#language-template").html(),t=s[o];l=l.replace("{{LANGUAGE}}",t.lang).replace("{{NAME}}",t.user).replace("{{SIZE}}",t.size).replace("{{LINK}}",t.link),l=jQuery(l),jQuery("#languages").append(l)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*$)/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table></div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table></div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>
You might want to consider providing a list of URLs to use and what order they should be in as it is a bit ambiguous at the moment. Also, what does "unlimited rows/height" mean? Do you intend every submission to output the same image or can users choose the dimensions of the rectangle? – GamrCorps – 2016-07-27T22:03:02.867
@GamrCorps It means if more sites are added to the current lineup and they end up requiring a new line, then it can be added. – haykam – 2016-07-27T22:04:22.983
Ok. Two more questions though: are URL shorteners allowed and do you require submissions to be full programs, functions, or either? I think this question could have benefited time in the sandbox.
– GamrCorps – 2016-07-27T22:06:15.180@GamrCorps Also, You can find a list of the Stack Exchange subdomains on Wolfram Alpha.
– haykam – 2016-07-27T22:06:30.077@GamrCorps URL shorteners are not allowed, and they have to be either – haykam – 2016-07-27T22:07:22.700
4The list of Stack Exchange sites is not fixed; subdomains may be added or removed at all times. The challenge spec should include the list that is required for this task. – Dennis – 2016-07-27T22:09:50.990
@Dennis It has to be dynamically found. – haykam – 2016-07-27T22:13:46.047
2OK, so what about SE sites that aren't a subdomain of SE.com or SO.com? Should they be excluded? – Dennis – 2016-07-27T22:20:07.063
@Dennis Can you give me examples? – haykam – 2016-07-28T00:31:10.033
superuser.com
,serverfault.com
,askubuntu.com
,askdifferent.com
,mathoverflow.net
,stackapps.com
,seasonedadvice.com
,stackauth.com
– Dennis – 2016-07-28T02:21:47.5831
What about parse the sites from http://stackexchange.com/sites ?
– Giacomo Garabello – 2016-07-28T15:17:11.6101@GiacomoGarabello That is an option. – haykam – 2016-07-28T16:18:49.937
@Dennis, adding those into the main post. – haykam – 2016-07-28T16:19:07.840
Sites without their own domain The order of the images in the sprite-sheet will be that, except the separate sites not including Stack Overflow will be in alphabetical order.
This entire part needs some major clarification. I meanSites without their own domain...
what?The order of the images in the sprite-sheet will be that
what is "that"? And what are the "separate sites" mentioned here? – R. Kap – 2016-07-29T00:59:35.723Not to say that this is a bad question. This can still be a pretty good question in my opinion. It just needs quite a bit of clarification. – R. Kap – 2016-07-29T01:03:06.380
@R.Kap, I've explained it a bit more. Somehow I never finished writing that sentence in my edit. – haykam – 2016-07-29T01:22:52.247
1
@Dennis, Seasoned Advice is actually at
– haykam – 2016-07-29T01:24:49.277cooking.stackexchange.com
andseasonedadvice.com
is just a redirect, much likearqade.com
redirects togaming.stackexchange.com
.I feel like the sorting order needs to be less arbitrary. Instead of how you specified, can it just be *.stackexchange.com alphabetically by subdomain, then the remaining sites alphabetically by domain? Also, where are the meta sites factored in? – Patrick Roberts – 2016-07-29T02:03:21.407
1Actually,
www.stackexchange.com/favicon.ico
returns a16 x 16
image. – R. Kap – 2016-07-29T19:54:57.700Also,
– R. Kap – 2016-07-29T20:13:15.530www.seasonedadvice.com/favicon.ico
returns a 404 not found error.@R.Kap you're right about stackexchange, but you forgot that seasonedadvice redirects: http://cdn.sstatic.net/Sites/cooking/img/favicon.ico. It's in my sprite-sheet.
– Patrick Roberts – 2016-07-29T20:14:26.293@PatrickRoberts Yeah, but then again, OP did say to just append
/favicon.ico
to the end of each domain to get the favicon, but when I do that towww.seasonedadvice.com
, I get the 404 error. – R. Kap – 2016-07-29T20:16:33.347@R.Kap see this comment. He knows.
– Patrick Roberts – 2016-07-29T20:17:19.010@PatrickRoberts Well then, in that case, why is
www.seasonedadvice.com
in the list? And if that has to be there, why isn'twww.arqade.com
also in the list? – R. Kap – 2016-07-29T20:19:15.270Let us continue this discussion in chat.
– Patrick Roberts – 2016-07-29T20:22:34.080www.stackauth.com
also returns a16 x 16
favicon. – R. Kap – 2016-07-29T20:33:34.517@R.Kap, I've posted a question on Meta Stack Exchange.
– haykam – 2016-07-29T21:30:20.867