Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
107

Python 2.7 + xkcd, 55 bytes xkcd is a third-party Python package. In Python, there is a package for everything! lambda n:[xkcd.getComic(n).altText][n==859] import xkcd For 404: urllib2.HTTPError: HTTP Error 404: Not Found For 859: IndexError: list index out of range


63

Pure Bash (no utilities), 200 bytes - 40 bonus = 160 while read u;do u=${u#*//} d=${u%%/*} exec 3<>/dev/tcp/$d/80 echo "GET /${u#*/} HTTP/1.1 host:$d Connection:close ">&3 mapfile -tu3 A a=${A[@]} a=${a#*<p>} a=${a%</p>*} echo "${a//<\/p>*<p>/" "}" done I think this is up to the spec, though of course watch out for ...


57

Bash + netcat + ss + …, 65 60 characters nc -lp$1 -c'ss src :'$1'|awk \$0=\$5|tr .: +#|bc' exec $0 $1 Not a serious solution, was just curious about this possibility. Thanks to: ninjalj for suggesting the awk based filtering (-5 characters) Sample run: (terminal 1) bash-4.3$ ./ip-reduce.sh 8080 (terminal 2) bash-4.3$ nc localhost 8080 128 bash-4.3$ ...


46

Oration, 41 bytes Not winning, but sure was fun. As of right now, I'm only 1 bytee behind python! I need webbrowser Now open "http:ppcg.ga" Explanation: I need compiles to import $1 with webbrowser being the module. Now runs the following command from the module as module.command with the arguments of anything following. So this compiles to: #!/usr/...


43

Batch, 17 bytes Saved 3 bytes thanks to Mego. start www.ppcg.ga This will open in your default browser if you run it from the windows command line. I think it'll work in Powershell too, but I'm not sure.


39

GNU Awk: 69 characters A server itself (endlessly serves one request at a time), no library used. Send 418 to everybody who connects (82 69 characters): BEGIN{while(s="/inet/tcp/80/0/0"){print"HTTP/1.1 418\n"|&s close(s)}} Send 418 to everybody who sends something (93 80 characters): BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline print"HTTP/1.1 ...


39

jQuery + JavaScript, 85 bytes $.get("//api.stackexchange.com/posts/82610?site=codegolf",d=>alert(d.items[0].score)) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> History -6 bytes because I was using the var data instead of d. -3 bytes thanks to @msh210 -13 bytes thanks to @CᴏɴᴏʀO'Bʀɪᴇɴ -...


35

GNU Emacs, 29 27 14 bytes (eww"ppcg.ga") EWW is a browser inside Emacs. The browse-web function is an alias for eww, and so that makes eww the default browser in Emacs: Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com. Thanks to @CoolestVeto, @Jonathan Leech-Pepin and @zyabin101.


34

Bash + coreutils + Lynx browser, 61 bytes Thanks to @FDinoff for the tips: lynx -dump codegolf.stackexchange.com/posts/28164/body|grep 2


32

Bash (33) nc -lp80 -q1<<<"HTTP/1.1 418 ";$0


30

PHP - 85 bytes <?for($s=socket_create_listen(80);socket_write(socket_accept($s),"HTTP/1.1 418 ");); Saved with Windows-Style (CR-LF) line endings, requires php_sockets enabled. I actually used this as my error code for the Hard Code Golf: Create a Chatroom challenge, but no one noticed. Browser-Friendly version <?for(socket_getsockname($s=...


30

Stack Exchange Data Explorer, 56 54 53 51 46 bytes -1 byte thanks to Hyper Neutrino. -5 bytes thanks to Giacomo Garabello. SELECT ID FROM USERS WHERE##S##=DISPLAYNAME--S Try it online! Not sure if this is completely valid but... Input must be surrounded in single quotes '. Also, I still don't get why SQL programmers like to shout but it's apparently ...


29

Bash (with dnsutils), 3 bytes Sends a DNS request for "." (DNS root), exit code is 0 for success and >0 otherwise. Golfed dig Test % dig >/dev/null; echo $?; 0 % nmcli nm wifi off % dig >/dev/null; echo $?; 9 Disclaimer This will obviously only work if your DNS server is sitting in the provider's network, i.e. in the "Internet" (as your ...


24

PowerShell, 17 16 Bytes saps www.ppcg.lol Using an even shorter domain provided by Milo. saps www.ppcg.ga While start is a known alias for Start-Process there is another one for saps. You can see this from Get-Alias. It follows the convention for similar Start- and Stop- cmdlets.


24

JavaScript ES6, 107 bytes fetch`//api.stackexchange.com/posts/82672?site=codegolf`.then(r=>r.json()).then(b=>alert(b.items[0].score)) Real programmers don't use XMLHttpRequest. Real programmers use the Fetch API.


24

Bash, 43 42 40 bytes curl -L enwp.org/$@|grep -o Canada|wc -l Uses curl, grep, and wc to count occurrences of "Canada" in specified webpage. Like the other answers, input is given in the format July_1. This is my first time posting on the Code Golf SE and I'm not quite familiar with all of the rules. Any feedback would be most welcome. Didn't realize that ...


23

C#, 284 283 282 278 274 254 bytes class A{static int Main(string[]a){var b=new System.Net.Sockets.TcpListener(int.Parse(a[0]));b.Start();for(;;){var c=b.AcceptTcpClient();var d=c.Client.LocalEndPoint.Serialize();new System.IO.StreamWriter(c.GetStream()).WriteLine(d[4]+d[5]+d[6]+d[7]);}}} Classic example of a basic C# TCP server. Testing: Terminal 1: $ ./...


22

Ruby, 155 186 195 148 138 110 97 characters require'open-uri';puts open('http://codegolf.stackexchange.com/posts/28159/body').read[/req.+;/]; I had to make it one line, because otherwise it would output newlines as \n instead of actual newlines. +31 characters because I didn't notice some characters were being escaped. +9 characters to get rid of the ...


22

Linux ELF/x86, 146 bytes 00000000 7f 45 4c 46 01 00 00 00 5a 0e 00 00 5a 5e eb 10 |.ELF....Z...Z^..| 00000010 02 00 03 00 0c 50 eb 10 0c 50 eb 10 04 00 00 00 |.....P...P......| 00000020 5e 53 43 53 52 89 e1 b0 66 3d 20 00 01 00 cd 80 |^SCSR...f= .....| 00000030 97 55 6b ed 0a 01 c5 ac 2c 30 79 f6 43 0f cd 01 |.Uk.....,0y.C...| 00000040 dd 55 89 ...


22

Python 2 + Requests, 104 102 95 94 bytes -2 bytes thanks to Erik the Outgolfer. -1 byte thanks to Jonathan Allan. lambda n:[get('http://xkcd.com/%d/info.0.json'%n).json()['alt']][n==859] from requests import* Obligatory: import antigravity Poorly written script, 98 bytes So, writing poor scripts is actually hard to do intentionally... This also breaks ...


21

PHP, 175 bytes (215 - 40 bonus) 227 229 239 202 216 186 bytes Have fun browsing the web: for(;$i=parse_url(trim(fgets(STDIN))),fwrite($f=fsockopen($h=$i[host],80),"GET $i[path] HTTP/1.1 Host:$h Connection:Close ");preg_match_all('!<p>(.+?)</p>!si',stream_get_contents($f),$r),print join(" ",$r[1])." "); Reads URLs from STDIN like http://www....


21

Terminal (OSX), 20 18 17 bytes open http:ppcg.ga Saved 2 thanks to CoolestVeto


21

Bash, 80 79 75 69 bytes w3m api.stackexchange.com/posts/82616?site=codegolf|tr ,: \\t|cut -f20 For scoring purposes, \t should be replaced with a TAB character. This requires w3m, which should be available by default on most Linux distros. Thanks to @NoOneIsHere for -2 bytes! How it works w3m is a command-line web browser. It queries the URL and (...


20

PowerShell - 69 62 (irm codegolf.stackexchange.com/posts/28236/body).div.pre.code


20

Node.js (LiveScript) http module - 66 require(\http)createServer (->&1.writeHead 418;&1.end!) .listen 80 Inspired by Qwertiy's answer. net module - 76 require(\net)createServer (->it.write 'HTTP/1.1 418\r\n';it.end!) .listen 80


20

Ruby + Rack, 19 bytes run->e{[418,{},[]]} Must be saved as config.ru, and run with the rackup command. Or if you prefer "pure" Ruby: Rack::Handler::WEBrick.run->e{[418,{},[]]} 42 bytes + -rrack flag = 48 bytes


20

Bash + system utilities, 56 53 49 48 bytes Update: saved 4 bytes thanks to Digital Trauma and 1 byte more thanks to Dennis curl -L `yes google.com|sed $1q`|wc|dc -e1k?$1/p In my original answer I was using yes in combination with xargs to emulate a for loop. But curl can accept as input a list of URLs, so only the output from yes is actually needed. When ...


20

05AB1E, 65 64 bytes Code: •в=6{•5ôvy’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’.w’„Ö="ˆ"’¡1èт£þ}})ZQā*O<“D M·‡“#è Uses the 05AB1E encoding. Explanation: •в=6{• converts the number в=6{ from base 255 to base 10, resulting in 1201208478. The first half being the ID of Dennis (12012) and the second half being the ID of Martin (8478). Split into pieces of 5 using 5ô to get ...


19

Bash + GNU utils, 8 5 bytes saved thanks to @Muzer. wget to. The other shell answers check the return code and echo some status output accordingly. This is unnecessary. The shell return code is already a usable Truthy/Falsey code and accessible in the $? parameter which is idiomatic for bash. Return code 0 means True. Return code >0 means False. In ...


19

PowerShell v3+, 147 123 119 103 101 96 Bytes $a,$b=irm api.stackexchange.com/users/12012`;8478?site=codegolf|% I*|% r*n;$a-$b|% T*g "D;M;Tie" Saved 24 bytes using true/false output instead of the names. Saved another 4 by restructuring the final checks. saved 16 by getting only the reputations of the two users from the request, saves having to use the |% ...


Only top voted, non community-wiki answers of a minimum length are eligible