text:
Display Frames from .txt file
The Task:
Given a .txt file with frames of ASCII art each separated by a \n (see this example if you are unclear) output a motion picture with frame with 1 frame per second.
Note that there is a trailing \n on the final frame.
Each frames dimensions will be:

X<80
Y<20

The Rules

The Previous frame must be cleared before the next is displayed, so just printing each frame onto the terminal isn't a valid answer.
New You can grab the file name however you want, either from it being stored in a variable or from sys args.
New The images must Loop indefinitely
This is code golf: smallest program wins.

Example
Input
0   0
0   0
00000
0   0
0   0

00000
0
00000
0
00000

0   0
 0 0
  0
  0
  0

Output

Un-golfed
import curses, time

stdscr = curses.initscr()

Frames = file.read(file('Frames.txt')).split('\n')
while True:
    y = 0
    for i in range(len(Frames)):
        stdscr.addstr(y,0,Frames[i])
        stdscr.refresh()
        y += 1
        if Frames[i] == '':
            y = 0
            stdscr.clear()
            time.sleep(1)

In languages that don't really support file handling (like JavaScript), is it also OK to put the input in a variable?

@ProgramFOX I guess you can open the file in a browser and use document.body.innerText

@ProgramFOX Make's it a little unfair, the file handling aspect adds many chars in most languages

Mathematica, 41 bytes
Import@f~StringSplit~"\n\n"~ListAnimate~1

Expects the file name to be stored in variable f.
This is the first time Mathematica's precedence rules for @ and .~.~. are exactly the way I need them.
Btw, this snippet could go horribly wrong if the file extension is anything else than .txt (because Mathematica will try to guess how to do the import based on that), but luckily that file ending is part of the challenge specification.

Bash, 82
IFS=
clear
for((;;)){
while read a;do
[ "$a" ]&&echo $a||(sleep 1;clear)
done<$1
}

Assumes the file name of the .txt file is provided as the first argument to the script.
Note that a trailing empty line must be present at the end of the .txt file for this to work.
Special thanks to @professorfish and @DigitalTrauma.

isn't $IFS blank by default? also, use for ((;;)){ ... } instead of while :;do ... done

@professorfish IFS by default is . Need to set it to '' so that read can read multiple consecutive spaces, as in the last line of Y

A couple of small reductions: IFS= and [ "$a" ] instead of [ -n "$a" ]

Ruby, 88 86 56 55 characters
$<.read.split($/*2).cycle{|i|system'cls';$><<i;sleep 1}

This program assumes the file name is given as the first argument.
Thanks a lot to Ventero for sharing great improvements!
Un-golfed:
$<.read.split($/*2).cycle{ |i|   # read file, split by two newlines, and loop
    system 'cls'   # clear screen
    $><<i   # print the current array item
    sleep 1   # sleep one second
}

This program reads the file, splits it into chunks, and prints each chunk separately after clearing the screen. cls only works on Windows. A variant with clear is 57 characters.

you can save a character or two, by using a line break instead of the first ; and omitting the parentheses when calling split.

@m.buettner: Thanks! But why would a line break save characters? Doesn't a line break count as a character?

I wasn't entirely sure what Ruby would do with the semicolon if you omit the parentheses. In general though, I'd rather use line breaks than semicolons as it doesn't make a difference for the character count.

@m.buettner: I prefer semicolons, because on Windows, a line break can consist of 2 characters: \r\n.

That depends on how you configure your editor. :P I'm using almost exclusively Windows, but my Sublime is configured to use \n anyway. Also here on code golf no one will make you add another point to your score for each line break just because you are using Windows. ;)

$* is shorthand for ARGV, which would save two characters. In this case, you can save even more by using ARGF (or $<) though: a=$<.read.split"\n\n". a.size is also shorter than a.length. And since sleep returns its argument after returning, you can combine the last two statements in your loop into i+=sleep 1.

Actually, nevermind the last bit, you can completely eliminate i by using Array#cycle, which loops forever if no argument is given: a.cycle{|i|system"cls";$><<i;sleep 1}. And splitting at $/+$/ is another character shorter than "\n\n".

That also allows you to inline the definition of a: $<.read.split($/+$/).cycle{...} (Sorry about the triple comment, I always think of new improvements right after the comment edit period is over :) )

@m.buettner: Ah, I see. I used Notepad to write this, and AFAIK, there is no Notepad configuration that can change that.

@ProgramFOX yes you're probably right

Whoa you've beating APL with Ruby.

(not tested) -1 char: replace $/+$/ with $/*2

@daniero: Thanks, that works!

Slightly different approach (manually check for the empty line instead of relying on split): $<.cycle{|i|system"cls"if$_;sleep 1if$_=$/==i;$><<i}. This version doesn't clear the screen before the first frame, but that seems to be allowed by the rules: "The previous frame must be cleared".

@Ventero: That's shorter indeed, but a different approach, so you can post that as a different answer. Also, I think it is invalid. It doesn't clear the screen before the first frame, but the frame before the first frame is actually the third frame (the "Y" frame), and it doesn't clear that.

@ProgramFOX Since the approach really isn't that different, I won't post it as a separate answer. Also, I'm not sure I understand what you mean with "the frame before the first frame is actually the third frame". When run, the code first prints the "H", then clears, then prints the "E", clear, "Y", clear, "H", rinse, repeat. So the only missing clear is before printing anything at all - which doesn't seem to be required by the rules.

@Ventero: On my computer, it does not clear the screen after the "Y", and both the "Y" and the "H" appear on the screen.

@ProgramFOX Ah, I guess your input file has Windows-style line endings (\r\n)? This version explicitly compares every line against $/, which is \n by default.

@Ventero: Yes, it has \r\n line endings, but even after using dos2unix to convert the Windows-style line-endings to Unix-style line endings, I get the same problem.

Dyalog APL (64)
(Can't beat Mathematica this time. It seems to have a built-in for everything.)
{⎕ML←3⋄{⎕SM←1 1,⍨⊂⊃⍵⊂⍨~⍵∊⎕TC⋄⎕DL 1}¨M⊂⍨~(4/1)⍷⎕TC∊⍨M←80 ¯1⎕MAP⍵}

This is a function that takes the filename as its argument. It assumes the file is in Windows (\r\n) format.
Explanation:

⎕ML←3: set migration level to 3 (allowing ⊂ to be used as APL2's split feature)
M←80 ¯1⎕MAP⍵: read the file given by the right argument as an ASCII file, and store the contents in M.
M⊂⍨~(4/1)⍷⎕TC∊⍨M: find all occurrences of four consecutive terminal control characters, and split M on those. This gives each frame.
{...}¨: for each of these...

⊂⊃⍵⊂⍨~⍵∊⎕TC: split the argument (=one frame) on terminal control characters, and then turn the vector-of-vectors into a matrix (so it will display each line on a separate line, this is necessary because ⎕SM does not understand control characters.)
⎕SM←1 1,⍨: then display it in the upper left of the ⎕SM window.
⎕DL 1: and then wait for one second.

Ha, finally! And still my answer is not a lot shorter because the function names are just so damn long! :D

Someone needs to write a Mathematica preprocessor that maps every built in function to a Unicode character

Awk, 53
BEGIN{RS=RS RS}{system("clear")}1;{system("sleep 1")}

New rules:
Awk, 74
BEGIN{RS=z}{a[NR]=$0}END{while(!system("sleep 1;clear"))print a[i++%NR+1]}

This only loops once, but it can be shortened to BEGIN{RS=z}{system("sleep 1;clear")}1 ... In awk, "" is special as RS meaning multiline records. To support the new rule of looping indefinitely, I have this so far: BEGIN{RS=z}END{for(;!system("sleep 1;clear");)print a[i++%NR+1]}{a[NR]=$0} at 74 characters. gawk supports changing ARGV so you can do BEGIN{RS=z}{system("sleep 1;clear");ARGV[ARGC++]=ARGV[ARGC-1]}1 at 63 characters.

@laindir: Thanks, I can't come up with anything better.

Python 117
Assumes the file name is stored in variable f.
import time,os
while 1:
 for i in file.read(file(f)).split('\n'):
  print i
  if i=='':time.sleep(1);os.system('cls')

Note: replace 'cls' with 'clear' if on a unix based system, adding 2 chrs.
ctl+C to quit

for i in F: s.addstr(y,0,i); ... if i=='': ...

Use open(f).read() instead of file.read(file(f)), shorter by 4 bytes.

Perl, 40
seek ARGV,0,!eof;sleep 1;system clear

run as
perl -p00 frames.pl < animation.txt

(i.e. animation file is read through STDIN). 3 bytes for p00 were added to count. It's 2 characters shorter i.e. 38 on Windows because of cls instead of clear. Or, to be portable:
seek ARGV,0,!eof;sleep 1;system$^O=~/Win/?cls:clear

Or, stretching rules a bit (and then 31+3=34):
seek ARGV,sleep(1)&`reset`,!eof

Rebol, 74
forever[foreach s split to-string read f"^/^/"[call"clear"print s wait 1]]

Expects the filename to be stored in variable f.   Below is an ungolfed example:
f: %ascii-art.txt

forever [
    foreach s split to-string read f "^/^/" [
        call "clear"
        print s
        wait 1
    ]
]

Java, 678 characters(when golfed)
Of course with GUI, since doing stuff in console sucks with Java, especially if you want to clear the screen ...
import java.awt.Font;
import java.io.File;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingWorker;

public class G extends JFrame
{
    static JTextArea b = new JTextArea();

    G()
    {
        setSize(170, 370);

        add(b);
        b.setFont(new Font(Font.MONOSPACED, 0, 50));
    }

    public static void main(final String[] args)
    {
        new G().setVisible(true);
        new SwingWorker()
        {
            protected Void doInBackground()
            {
                for(;;)
                {
                    try(Scanner s = new Scanner(new File(args[0])))
                    {
                        String l = null;
                        while(s.hasNextLine())
                        {
                            if(l == null  || (l = s.nextLine()).isEmpty())
                            {
                                Thread.sleep(1000);
                                b.setText(l == null ? (l = s.nextLine()) + '\n' : null);
                            }
                            else
                                b.setText(b.getText() + l + '\n');
                        }
                    }
                    catch(Exception i){}
                }
            }
        }.execute();
    }
}

Just realized there were dimensions in the author's post, but I'm too lazy to change my code now. Won't win anyway :P

Cobra - 163
class P
    def main
        while 1
            for i in File.readAllLines("t.txt")
                print i
                if i=="",.x
            .x
    def x
        Threading.Thread.sleep(1000)
        Console.clear

Groovy - 121 119 chars
Ported ProgramFOX's answer to Groovy 2.2.1. The "clear console" is weak.
edit: replaced recursive closure with simple while loop, which is shorter and no stack overflow
a=new File(args[0]).text.split "\n\n";i=0;p={println it};while(1){p a[i++%a.size()];Thread.sleep(1000);80.times{p ""}}

Ungolfed:
a = new File(args[0]).text.split "\n\n"
i = 0

p = { println it }

while(1) {
    p a[i++%a.size()]
    Thread.sleep(1000)
    80.times{p ""}
}

Groovy, 81
This is a more groovy way:
new File(args[0]).text.split("\n\n").each{["cls"].execute();print it;sleep(1000)}

ungolfed
new File(args[0]).text.split("\n\n").each{
    ["cls"].execute()
    print it
    sleep(1000)
}

The command "cls" doesn't work on my Mac. Also, the requirements suggest that the motion picture loops.

@Michael Easter cls is for Windows I think... try clear

GNU sed, 32
1eclear
/^$/{
esleep 1;clear
d
}

C# 226
Why bother eh?
namespace System{class P{static void Main(){for(;;)foreach(var x in Text.RegularExpressions.Regex.Split(new IO.StreamReader("f.txt").ReadToEnd(),"\n\r\n")){Console.Clear();Console.WriteLine(x);Threading.Thread.Sleep(1000);}}}}

Un-golfed:
namespace System
{
    class P
    {
        static void Main()
        {
            for(;;)
            foreach (var x in Text.RegularExpressions.Regex.Split(new IO.StreamReader("f.txt").ReadToEnd(), "\n\r\n"))
            {
                Console.Clear();
                Console.WriteLine(x);
                Threading.Thread.Sleep(1000);
            }
        }
    }
}

Or in LINQPAD (so C# can stay semi-competitive with uber shorthand langs :D)
C# LINQPAD - 134
for(;;)foreach(var x in Regex.Split(new StreamReader("f.txt").ReadToEnd(),"\n\r\n")){x.Dump();Thread.Sleep(1000);Util.ClearResults();}

I feel a bit dirty, but hey, this is code-golf.

SmileBASIC, 74 bytes
F=LOAD(F)@L
IF" "*!CSRX>F[I]THEN WAIT 60CLS
?F[I];
I=(I+1)MOD LEN(F)GOTO@L

F should be the file name


text:
Write a program that downloads itself
Write a program that connects to this site, downloads the very answer in which it is posted, extracts its own source code and prints it out. The output must be identical to the source code. Shortest code (in bytes) wins.
Rules:

No URL shorteners allowed.
The answer must have a regular format - a heading with the language name and size, optional description, code block, optional description and explanation. No unnatural delimiters allowed.
The output must originate from the actual code block posted on the site.
The functionality must not depend on the position in the answer list; it should work even if there are multiple pages and the answer it not on the first one.
New: special note for answers that are supposed to be run in a browser: it  is ok to require running them on the codegolf domain (to obey the same-origin policy) but the domain and path should be included in the solution in order to make it fair.

Catch-22: How am I supposed to test my submission?

I forsee people posting answers and deleting them, so they can test their code.

@m.buettner answers can be tested on other answers (to other questions) first, then posted, then edited to change the URL :)

I think the participants should agree on a code of conduct that no two answers will be in the same language with the same character count (i.e. be a gentleman and use an additional character if there's a tie), such that everyone can save characters but not having to scrape for author or ID of the post (so posts can be identified by the headline directly). ;)

@m.buettner I'm not sure that would save characters... basically I can allow this technique, but I won't require such conduct

I bet the next question will be a program that program itself.

How does this challenge handle comments designed to interfere with an answer?

@hexafraction if comments are able to interfere with an answer, then the answer is not very good...

Given enough answers one submission might end up on page 2, 3, ... Must the solutions account for this?

@Sylwester yes I already mentioned that in the question

A question stuck in my head: How to write a tweet that links to itself without using any URL shorteners, but by estimating the tweet id your tweet?

@Sylwester that shouldn't be a problem - if you use the direct link to the answer (instead of the question), the correct page should be open already.

Concerning your new rule for JavaScript because it is powerful on this question is just like create a rule "Only language used in production accepted" because GolfScript is not fair for the majority of code-golf questions. Anyway, this is just my opinion...

@Michael The rule is just about the circumstances of running the code. It's like saying that a program that prints "/0/1/2/3/.../20" must not depend on being executed in a folder with that exact path. And if only production languages were accepted, somebody WILL use GolfScript in production :)

is jQuery allowed? (and more broadly, is this commonly allowed/disallowed in this site?)

@Martijn I see no reason to exclude it, as long as it follows the rules

I proposed the opposite of this a bit ago: http://meta.codegolf.stackexchange.com/questions/1412/proposed-question-sandbox-mark-xii-retired/1528#1528 it never came to fruition.

@m.buettner I love the way your catch-22 comment has exactly 22 upvotes :D
Here: http://i.imgur.com/twJzcfa.png

@SHiNKiROU That does not apply here, as you can post the answer and then edit it to include the url of the answer

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

And what happens if I type that magic word grep is looking for?

lynx lynx lynx lynx. This comment will be grepped out (and the heading as well)

@hexafraction Awww. You had to go and ruin it!

I would assume that no answer above you can use a "keyword" so you could select only the first result.

Or he could just be more specific with something like grep lynx -d to match where the -dump flag is. Oh wait... Thats broken now too

codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself can be replaced with codegolf.stackexchange.com/q/28154.

This url should work. codegolf.stackexchange.com/posts/28164/body And it ignores comments. I also think its within the rules that you can use it...

lynx -dump codegolf.stackexchange.com/posts/28164/body|tail -1 is 62 characters. (I think it should work if you edit your answer)

@FDinoff Thats great!  Thanks!

2 2 2 2 2 2 does it still work?

@haneefmubarak Yep, still works :)  Comments are not included in the changed URL format, as recommended by FDinoff.

@DigitalTrauma awww... damn.

@DigitalTrauma Okay, you're right. I thought it was a typo since the Q no. is 28154.

curl doesn't work?

@NoOneIsHere I'm not aware that curl has an equivalent to lynx's -dump option, that just outputs the page content, and not the html tags

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 annoying backslash.
Thanks to Nathan Osman for saving 2 chars, and Ventero for saving 55 (!!!) by removing the need for most of the fixes listed above.

The explanation
Let's beautify this a bit first. However, I'm going to have to use a somewhat... interesting notation in this code. I can't use semicolons at all in this post, for reasons explained later, so I will use {SEMI} in place of semicolons instead.
require 'open-uri'
resp = open('http://codegolf.stackexchange.com/posts/28159/body').read
puts resp.match(/req.+{SEMI}/){SEMI}

Alright, now let's walk through this. The first two lines are fairly self-explanatory -- they fetch the HTML text of this answer.
Now, the last line is the interesting one here. You see that seemingly useless semicolon at the end of the code? It's absolutely required, and here's why.
First, resp.match extracts the code to be printed. The regexp it uses for this is the trick: /req.+{SEMI}/. It grabs the start of the code, REQuire'net/http', by searching for req (re would grab my REputation). Then, it finds the end of the code by searching for a semicolon! Since + is greedy by default, it will keep going until it finds the semicolon that signifies the end of the code. See why I can't use semicolons anymore?
After that, I don't have to unescape anything thanks to Ventero's fix of not using \ at all anymore. All I have to do is fix {AMPERSAND} changing into {AMPERSAND}amp{SEMI}, which can be achieved simply by removing the amp{SEMI} part. No need for this anymore because of new URL. After that, the original code has been retrieved! (Note: I can't use the ampersand either, because that gets HTML-encoded which causes a semicolon to be created.)

Some characters are getting escaped..

@aditsu Gah; didn't notice that. Fixed.

You're gonna hate this.. a backslash is getting duplicated. There's also a newline difference, but that's a minor thing.

@aditsu Argh! :P Fixed also. The newline thing is because of puts; it could be fixed with print but meh. Just pretend there's a trailing newline in the code, even though SE won't be able to show it.

You can shave off two bytes by using withbody in the filter instead of !9WA((ItYa.

.body[/e>.+?</][2..-5] should save quite a few characters.

And with something like .body[/req.+-3./], you can save even more, especially because then you can drop the CGI.unescapeHTML call (plus the require), and instead use .sub("amp;",""). Also, using require"open-uri" and open("http://api.stack....").read saves even more - though this requires Ruby >= 2, I think. To fix the newline, use $><< instead of puts (which saves another character).

(With the .sub call, you'll have to change the RegExp to /req.+""./, if I'm not mistaken)

@Ventero Wow! Thanks. I have to use net/http because otherwise un-gzipping the API's output costs too much. Can't use $><< because then I'd have to unescape < and >, which costs more than it saves. I also altered your regex a bit.

@Doorknob: When you use Ruby 2, you get uncompressed output from open-uri. But yeah, missed the part about unescaping <>. And I like the seemingly useless semicolon! :)

@Ventero Hm. I'll look into that in a sec; I'm writing up an explanation right now. Thanks; I'm particularly proud of that semicolon trick because I find it extremely clever for some reason :P

With the new URL, you don't need the .sub anymore. And maybe you could use a similar trick with the semicolon at the beginning of your code (e.g. by prepending your code with another semicolon or an exclamation mark or something), which could save another character.

For the link,  http://codegolf.stackexchange.com/a/28159 would give the same result as yours and would save some chars.

I believe that the require'open-uri'; can be passed as a command line argument as -ropen-uri, which would save more bytes

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

DOM in a shell. Nice!

Doesn't irm require Azure Rights Management? Without that module, I think you could do it with  Invoke-WebRequest.

@ScottLeadley irm is the alias for Invoke-RestMethod and was introduced with PowerShell v3 core. http://www.computerperformance.co.uk/powershell/powershell3-alias.htm

Holy crap. A PowerShell code golf answer with a length in the same order of magnitude as the leading answers. +1

@AdamMaras Ha, I know what you mean! It does happen occasionally though. http://codegolf.stackexchange.com/a/26811/4565 and http://codegolf.stackexchange.com/a/21982/4565 weren't too far from the lead.

@bfred.it: strictly speaking, this isn't DOM, which refers to a specific API rather than any HTML/XML APIs.

JavaScript - 123 122 101 95 92 91 87 86 114
with(new XMLHttpRequest)send(open(0,/\codegolf.stackexchange.com\posts\28175\body/,0)),alert(/w.*/.exec(response))

Runs in the console of your web browser on this page. Tested on the latest Chrome and Firefox.
edit: +28 bytes to add the full domain.
Firefox doesn't like my Regex URL trick anymore with this update :(
Here's the rule-breaking 86 byte solution:
with(new XMLHttpRequest)send(open(0,/posts\28175\body/,0)),alert(/w.*/.exec(response))

That made me awe. Multiple times.

@bfred.it I just cut a byte using an interesting regex. I hope it makes you awe one more time.

If printing to the console is an acceptable method of output, you can shorten by 7 chars by removing the alert.

Also , according to the new rule you gotta add codegolf.stackexchange.com/ to the url.

@TejasKale From what I've seen people frown upon solutions that don't actually alert/document.write/console.log the answer.

Ruby + wget + gunzip, 159 86 82 71
Using tip of @FDinoff to use http://codegolf.stackexchange.com/posts/28173/body.
puts `wget -qO- codegolf.stackexchange.com/posts/28173/body`[/pu.*\]/]

Tested. Thanks to @ace and @Bob for command line optimization.

You can combine the flags in wget, as in wget -qO- url. Also, in bash you do not need the double quotes for the url, so this may also work for you.

You can leave out the http://.

CJam - 53
"codegolf.stackexchange.com/posts/28184/body"g54/1=);

I'm making this community wiki since I'm answering my own question and don't really want to compete :p
Credits to FDinoff for the URL choice.

Woot, +1 for smiley face in code

@Cruncher ); doesn't look too smiley to me...

JavaScript, 228
r=new XMLHttpRequest()
c='code'
r.open('GET','//'+c+'golf.stackexchange.com/posts/28157/body')
r.onreadystatechange=function(){this.readyState==4&&alert((a=r.responseText).substr(i=a.indexOf(c)+5,a.indexOf('/'+c)-i-1))}
r.send()

Runs on this page.

How do you run it?

@aditsu It is supposed to be run on the JavaScript console of a browser. But I am still testing (and fixing) it, please wait

@aditsu It should work now. Open your browser console (press F12) and paste this code there.

you sir, need a if(this.readyState == this.DONE) inside the function.

@Fabricio You're right! Thanks a lot :)

You can save 10 chars, if you ommit the parens from the XMLHttpRequest and use with instead of assigning the XHR to r. with(new XMLHttpRequest){open('GET','/posts/28157/body');onreadystatechange=function(){if(readyState==4)alert((a=responseText).substr(i=a.indexOf(c='code')+5,a.indexOf('/'+c)-i-1))};send()}

@C5H8NNaO4 I know I can, but I'd rather not, otherwise people may think I am copying the other JS answer. (And in fact I got an un-upvote after copying the URL...)

@ace I see :) I didn't saw the other js answer until now. Then take this upvote from me

Nice answer. How do you get the URL of your post?

@bacchusbeale By clicking the "share" button below the answer, you can see the post number 28157. As for the format of the URL (/posts/[number]/body), I copied it from other's answer... Originally I used the StackExchange API.

Java now 634, 852, was 1004
Code has been updated; thanks for suggestions.
Golfed: now replaces &gt with >
//bacchus
package golf;
import java.net.*;
import java.util.*;
public class G{
public static void main(String[] a) throws Exception {
Scanner z;
URL u;
int x=0;
String s;
u=new URL("http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself");
z=new Scanner(u.openConnection().getInputStream());
z.useDelimiter("\\s*//bacchus\\s*");
while(z.hasNext())
{
s=z.next();
s=s.replace(">", ">");
if(x>0)System.out.println("//bacchus\n"+s);
x++;
if(x>2)break;
}
System.out.println("//bacchus\n");
}
}
//bacchus

Submitting for testing, I will edit and try golfing it shortly.
Needed to change x>1 to x>2 because test string is also in my code.
Note: Code golf replaces > symbol to &gt.
//bacchus
package golf;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Golf {

    public static void main(String[] args) throws IOException {
        URL u;
        URLConnection c;
        InputStream i;
        InputStreamReader r;
        BufferedReader b;
        String s;
        int x=0;
        try {
            u=new URL("http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself");
            c=u.openConnection();
            i=c.getInputStream();
            r=new InputStreamReader(i);
            b=new BufferedReader(r);
            while((s=b.readLine())!=null)
            {
                if(s.contains("//bacchus")) x++;
                if(x>0)System.out.println(s);
                if(x>2) break;
            }
            i.close();
            b.close();
        } catch (MalformedURLException ex) {

        }
    }

}
//bacchus

How do you handle comments containing //bacchus?

You could inline a lot of stuff, try-with-resources, and use * imports to save a lot of code.

@SimonKuang - I'd also just leave the streams open rather than closing stuff.  Also, throws Exception rather than trying to handle anything.  Also, I think using a Scanner rather than a BufferedReader would be simpler, especially as you could set the delimiter to //bacchus, which would make things somewhat easier...

Python, 175 167 bytes
This uses two external libraries; I didn't read that it was unauthorized.
import bs4,requests
print(bs4.BeautifulSoup(requests.get('http://codegolf.stackexchange.com/q/28154').text).select('#answer-28171')[0].select('pre > code')[0].string)

Longer, but nicer looking code:
import bs4, requests
request = requests.get('http://codegolf.stackexchange.com/q/28154')
soup = bs4.BeautifulSoup(request.text)
answer = soup.select('#answer-28171')[0]
code = answer.select('pre > code')[1].string
print(code)

The questions in the url can be replaced with q: http://codegolf.stackexchange.com/q/28154

The space in bs4, requests (line 1) can be removed to reduce 1 byte.

Rebmu, 91 characters
Due to the Catch-22 I have to post to get this answer's URL.  :-/  Okay, got it.
paTSrd http://codegolf.stackexchange.com/a/28154[ththcpCto]prC

Rebmu is a dialect of Rebol, and you can read all 'bout it.  The equivalent Rebol here would be:
parse to-string read http://codegolf.stackexchange.com/a/28154 [
    thru
    thru
    copy c to
]
print c

Rebol's PARSE is a sort of highly-literate answer to RegEx.  It starts a parser position of the input (which can be any series, including structural blocks...binary data...or string types).  The rules are a language for how the parse position moves.
Tags and URLs are really just strings under the hood in the language.  But they are "flavored", and as Rebol is dynamically typed you can check that type.  READ for instance knows that if you give it a URL-flavored string, then it should dispatch to a scheme handler to do the reading.  (In this case, the one registered for HTTP).  You get back UTF-8 bytes by default, so we use to-string to decode that and get a series of codepoints in a normal Unicode string.
In the case of the parse dialect, encountering a tag type is just matched as if it were a string that looked like the tag.  THRU is an instruction meaning "skip until the ensuing rule is matched, and then place the match position at the end of what you just matched."  (TO is the analogue that matches, but leaves the parse position before the element).
So we zip along past the .  Then we zip past the next occurrence of , with our parse position now located right after the >.  PARSE's COPY command then lets us copy data up to another rule, in this case that rule is [TO ]... so we get into the variable C everything up until right before that <.
Cool, huh?  :-)
Technically I could shave more off it, for instance by seeking TO "</" and that saves three characters--there's no need to match the whole  end tag when just </ would do.  Similar arguments could me made for the start tag.  But Rebmu is about literate golfing...even if you might think it looks odd at first!
UPDATE: the /body trick is out of the bag, but I'm similarly going to leave it as-is...because I think it is more educational this way.

w3m 45 characters
w3m codegolf.stackexchange.com/a/28336|grep ☻

☺. Does it still work? Edit: Looks like it does.

@ace I get your comment when I run it

Fixed :) Anyone else?

Haskell, 563 613 bytes
import Control.Monad
import Data.List
import Network.HTTP
m%f=join(fmap f m)
q s=(simpleHTTP(getRequest"http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself?answertab=oldest#tab-top"))%getResponseBody%(putStrLn.head.filter((==)(s++show s)).map(take 613).tails)
main=q"import Control.Monad\nimport Data.List\nimport Network.HTTP\nm%f=join(fmap f m)\nq s=(simpleHTTP(getRequest\"http://codegolf.stackexchange.com/questions/28154/write-a-program-that-downloads-itself?answertab=oldest#tab-top\"))%getResponseBody%(putStrLn.head.filter((==)(s++show s)).map(take 613).tails)\nmain=q"

Tested. Has page support via "oldest posts" feature. Uses quine-line structure to find what to print.
The import Control.Monad is only because >>= generates > in HTML.

 Javascript +jQuery, 87, 67
I'm not sure wether I'm allowed to use jQuery, but:
$('body').load('//codegolf.stackexchange.com/posts/28268/body pre')

Javascript + jQuery, if excecuted in this page: 27, 25
For fun, if it would be excecuted here:
$('[id$=268] pre').html()

$('[id$=28268] pre').html()

This outputs more than the source code.

67: $('body').load('//codegolf.stackexchange.com/posts/28268/body pre')

You are correct, I wrongly asumed the whole reply instead of the code

Dart, 164
I thought I'd try this in Dart, is pretty fun to use imo.
This can be run in the console in DartEditor, but does require the http package added in pubspec.yaml
import"package:http/http.dart"as h;h.read("http://codegolf.stackexchange.com/posts/28215/body").then((s){print(new RegExp(r"im.+(?:})").firstMatch(s).group(0));});}

Ungolfed version:
import "package:http/http.dart" as h;

void main()
{
  h.read("http://codegolf.stackexchange.com/posts/28215/body").then((s)
  {
    print(new RegExp(r"im.+(?:})").firstMatch(s).group(0));
  });
}

R 114 characters
library(XML);cat(xpathSApply(xmlParse("http://codegolf.stackexchange.com/posts/28216/body"),'//code',xmlValue)[1])

No real magic here: it takes the value of the field between the html tags . Uses library XML (as one can see in the code quite obviously). Outputs the result as stdout.

APL (Dyalog Unicode), 108 bytes
6 3⌷⎕XML{(⎕SE.SALT.New'HttpCommand'('GET'⍵)).Run.Data}'https://codegolf.stackexchange.com/posts/211205/body'

Don't Try it online, try it locally
Correct link coming soon.
Output:

bash + awk, 71 bytes
curl -sL codegolf.stackexchange.com/q/28154 |awk -F\> '/\#/ {print $3}'

Doesn't seem to work - it outputs a lot of other stuff along with this answer.

@Riking true, it seems to be position-dependent (breaking the last rule)

You can leave out the http://.

@user155406: note that each answer has a URL - this one is  http://codegolf.stackexchange.com/a/28179/14710

Ruby, 237 215 146 132
require'mechanize'
a=Mechanize.new
puts a.get('http://codegolf.stackexchange.com/a/28159').search('.lang-rb code:nth-child(1)').text

Pretty sure you can remove a few spaces here and there to save a few bytes.

@richard who cares I'm not going to win anyway.

Do it for the lols, not for winning.

@RichardA done, and I also removed few chars from the regexp.

Java, 300 294
import java.net.*;import java.util.*;public class G{public static void main (String [] a) throws Exception{Scanner s=new Scanner(new URL("http://codegolf.stackexchange.com/posts/28189/body").openConnection().getInputStream()).useDelimiter("./?[c]ode\\W");s.next();System.out.print(s.next());}}

An improved version of bacchusbeale's answer which:

doesn't close resources unnecessarily
doesn't declare unnecessary variables
uses a Scanner to avoid having to loop over the input
uses a regexp that doesn't match itself to avoid having to skip over a middle occurrence of the start/end marker.

Updated:

Use a direct URL to the post, so we don't need a unique comment to identify the start/end of the code; now uses [...] as the delimiters to search for (actually using the regular expression "./?[c]ode\W", so as to avoid having to decode < and > -- the "\W" is necessary rather than the shorter "." to avoid it matching part of the URL to the post, unfortunately, which costs 2 characters, and the square brackets around c prevent the regex matching itself).

You have a bunch of unnecessary spaces. Also your class doesn't need to be public.

openConnection().getInputStream() can also be shortened to openStream()

w3m 55 bytes
w3m codegolf.stackexchange.com/posts/28242/body|grep x

Based on @DigitalTrauma

Python, 164
Works by extracting the text between the code tags. It is quite long but it will always function correctly unless the html page is edited directly or a new code block is added before the one below (having a block of code after should have no effect on the output of the program).
import urllib2
print urllib2.urlopen("http://codegolf.stackexchange.com/posts/28617/body").read().split(chr(60)+"code"+chr(62))[1].split(chr(60)+"/code"+chr(62))[0]

Very late but I appreciate the smart use of chr() to avoid the code containing any characters that need escaping.

Processing, 90
print(loadStrings("http://codegolf.stackexchange.com/posts/28657/body")[2].substring(11));

Edit: Finally got it!

Javascript, 138
a=window.open("http://codegolf.stackexchange.com/posts/28160/body");setTimeout('alert(a.document.body.innerHTML.match(/a=.*9\\)/)[0])',99)

This works assuming that the page loads in under 99 ms. It also has to be run via a console opened on a codegolf.SE page, because of the same origin policy.

Just a note: you don't need the slug in the URL, and questions can be replaced by q.

Note that you could do http://codegolf.stackexchange.com/a/28160 instead of http://codegolf.stackexchange.com/a/28160/12551

Chrome doesn't like this: "Uncaught TypeError: Cannot read property 'document' of undefined"

@Spedwards you should disable the popup blocker.

Perl 5.10, 155 127 122 117 bytes
use XML::LibXML;say XML::LibXML->new->parse_file('http://codegolf.stackexchange.com/posts/28330/body')->find('//pre')

Using XML::LibXML.

Shell and xmllint, 82 bytes
xmllint --xpath 'string(//pre)' http://codegolf.stackexchange.com/posts/28333/body

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

authors: Евгения Фёдорова

authors: Настя Кондакова

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Super fast sampling from a tricky random distribution
This is a micro-optimization challenge.  The task is to sample from the maximally skewed stable distribution F(x;1,-1,Pi/2,0). See Table 1 of  http://arxiv.org/pdf/0908.3961v2.pdf . It is easiest to describe how to do this using the following C code which uses the Mersenne Twister RNG C code from  here .
#include <stdio.h>
#include <stdlib.h>
#include "mtwist.h"
#include <math.h>

int main(void) {
   int i;
   volatile double x;
   mt_seed();
   double u1;
   double u2;
   double w1;
   double w2;
   for(i = 0; i < 100000000; ++i) {
     u1 = mt_drand();
     u2 = mt_drand();
     w1 = M_PI*(u1-1/2.0);
     w2 = -log(u2);
     x = tan(w1)*(M_PI_2-w1)+log(w2*cos(w1)/(M_PI_2-w1));
   }
   return EXIT_SUCCESS;
}

I compile with
gcc -Wall -O3 random.c mtwist-1.5/mtwist.c -o random -lm

The running time is 20 seconds taking 5,000,000 iterations per second.
There are two obvious ways of making this fast. The first is to choose a very fast uniform random number generator.  If you choose to use anything but the Mersenne twister then you must run it through the Diehard tests and check the P-values provided. Use the code here http://www.stat.fsu.edu/pub/diehard/ to do this.  Your uniform random number generator must pass at least 15 of these tests.
The second way is to find fast micro-optimizations for the transcendental functions, perhaps using some CPU specific features. For example in my case these features of the AMD FX-8350 CPU.
Rules The code must maintain at least 32 bits of accuracy throughout. The code should be compilable on ubuntu using easy to install free software only.  Please provide full compile and run instructions.  You should also provide a diehard log for any non Mersenne twister RNGs as was done for Build a random number generator that passes the Diehard tests . Note the very simple RNG that passes 15 tests in that link.
Scores You can report your score as the time taken by the code above divided by the time taken by your code on your own machine. For running your code you can use any compiler and compilation options you like. To test the code above you should use gcc 4.8 or later with -O3.  If any submission take less than one second I will increase N by factors of 10 until the fastest submission takes longer than 1 second.
Test machine My test machine was a standard 8GB RAM ubuntu install on an AMD FX-8350 Processor.  Your machine can be anything that supports gcc 4.8 or later.
The Intel optimization manual says

If there is no critical need to evaluate the transcendental functions
  using the extended precision of 80 bits, applications should consider
  an alternate, software-based approach, such as a look-up-table-based
  algorithm using interpolation techniques. It is possible to improve
  transcendental performance with these techniques by choosing the
  desired numeric precision and the size of the look-up table, and by
  taking advantage of the parallelism of the SSE and the SSE2
  instructions.

According to this very helpful table,fcos has latency 154 and fptan has latency 166-231 on my AMD FX 8350.

If you want to avoid compilers optimizing away the entire computation, the easiest way is to declare x as volatile double x.

@ReimerBehrends I am happy with that solution! Thank you. Now I just need some answers to the question :)

Incidentally, is the line w2 = -log(u2) correct? After all, u2 can be zero.

Looking at it more closely, I suspect that both u1 and u2 should be drawn from (0, 1) rather than [0,1). Also, 1/2 should probably be 1/2.0 in C (since / is integer division if both operands are ints).

@ReimerBehrends I will check the 1/2 possible bug. Thank you. For the other part the formula is taken from Table 1 of http://arxiv.org/pdf/0908.3961v2.pdf so if my implementation doesn't follow that then that is my mistake.  I suppose mathematically the probability that u1 or u2 are exactly 0 is exactly 0. It's only with limited precision that you get a non-zero probability.

According to the paper, u1/u2 are indeed meant to be uniformly distributed over the open interval (0,1), not over [0,1). That's easy to fix, though.

A double has 53 bits of precision, so some libraries generate 53 random bits, then divide the 53-bit integer by 253. This yields a double in [0,1), with a 1 in 253 chance of 0.

Some suggestions. 1) Use the RNG xorshift128+ from http://xorshift.di.unimi.it/xorshift128plus.c . 2) Remove the slow tan and use sincos and compute tan from it. 3) Even better, observe that you are computing tan(w1)*(M_PI_2-w1) + log(cos(w1)/(M_PI_2-w1)) + log(w2) and make a polynomial approximation for the two parts that defaults to the expensive version near its extremes (which will be hard to approximate).

Nimrod (Score = 1.71, 4.8 vs. 8.2 seconds)
Observe that x->[[cos x, -sin x], [sin x, cos x]] is a group isomorphism between [0, 2*pi) (with respect to addition modulo 2*pi) and the rotation matrices (as a subgroup of SL(2, R)).
Because w1 is effectively of the form pi*k/2^32, where k is a signed 32-bit integer, we can split k in two 16-bit words, h and l and always represent w1 as the sum of pi*h/2^16+pi*l/2^32 and tabulate rotation matrices for both addends in 2*sizeof(double)*2^16 bytes each. We can then derive sin(w1) and cos(w1) from the product of the two rotation matrices per the isomorphism above (and tan(w1) as sin(w1)/cos(w1)).
The code below is in Nimrod, but should be directly portable to C, with the necessary renaming to integer and float types (float64 in Nimrod corresponds to double in C, and int corresponds to intptr_t, i.e. 64-bit on most modern architectures) and essentially no change in runtime. It currently does not print anything, but uses a volatile variable as described in my earlier comment to avoid the code being optimized away.
Further speedups may come from looking at how to make the computation of the natural logarithm cheaper (and, of course, replace the Mersenne Twister with a different RNG, but that's not very interesting).
Compile with nimrod cc -d:release random.nim.
Compile with -d:validate instead to check floating point errors with respect to the normal sin/cos calculations.
Update: Added an option to use an Xorshift RNG, enabled by compiling with -d:xorshift. This reduces runtime by approximately a quarter. Also fixed RNG generation to avoid u1 == 0 or u2 == 0.
import math, mersenne, unsigned

# It is sufficient to represent the rotation matrix
# [ [ cos x, -sin x], [sin x, cos x] ]]
# by just the values in the left column/bottom row.

type RotMat = tuple[sine, cosine: float64]

var tab1, tab2: array[65536, RotMat]

for i in 0..65535:
  tab1[i] = (sin(pi*float64(i-32768)/float64(65536)),
             cos(pi*float64(i-32768)/float64(65536)))
  tab2[i] = (sin(pi*float64(i)/float64(65536*65536)),
             cos(pi*float64(i)/float64(65536*65536)))

proc `*`(x, y: RotMat): RotMat {.inline.} =
  result.cosine = x.cosine*y.cosine-x.sine*y.sine
  result.sine = x.cosine*y.sine+x.sine*y.cosine

proc sincos(x: int): RotMat =
  let r1 = tab1[(x shr 16) and 65535]
  let r2 = tab2[x and 65535]
  return r1*r2

when defined(xorshift):
  type RNGState = object
    x, y, z, w: uint32

  proc getNum(s: var RNGState): int =
    let t = s.x xor (s.x shl 11)
    s.x = s.y; s.y = s.z; s.z = s.w
    s.w = s.w xor (s.w shr 19) xor t xor (t shr 8)
    result = int(s.w)

  var rng = RNGState(x: 1)
else:
  var rng = newMersenneTwister(1)

const maxRand = 1 shl 32

for i in 1..100_000_000:
  var t1, t2: int
  while true:
    t1 = rng.getNum; if t1 != 0: break
  let u1 = t1/maxRand
  while true:
    t2 = rng.getNum; if t2 != 0: break
  let u2 = t2/maxRand
  let w1 = pi*(u1-1/2)
  let w2 = -ln(u2)
  when defined(original):
    let (sw1, cw1) = (sin(w1), cos(w1))
  else:
    let (sw1, cw1) = sincos(t1)
  var x {.volatile.} = sw1/cw1*(pi/2-w1)+ln(w2*cw1/(pi/2-w1))
  when defined(validate):
    var x2 = sin(w1)/cos(w1)*(pi/2-w1)+ln(w2*cos(w1)/(pi/2-w1))
    echo sw1-sin(w1)
    echo cw1-cos(w1)
    echo x-x2

Thank you! Do you know any faster RNGs which pass 15 diehard tests?

Certain variants of Xorshift should fit the bill, though I can't say that I'm much of an expert on PRNGs.

What is your current score using xorshift? Also, what do you think the prospects are for further speed ups? It seems sse might help...maybe.

The current score (on my machine, this can vary greatly by hardware) is about 2 (compared to compiling with -d:original). That's assuming that Xorshift is an acceptable PRNG. The limiting factor seems to be the need for at least 32 bits of precision. This makes it difficult to use cheaper approximations or to create a polynomial approximation of the formula as a whole.

The problem is that the distribution is dramatically skewed. Try plotting it and you will see. I am not sure how to capture this long tail without using a lot of bits.

I understand why you want the precision; I was merely noting that it prevents some common tricks that you can pull in other situations (such as certain applications in computer graphics, where the limitations of human vision may impose lesser constraints). If you want full precision, it's generally hard to beat the established algorithms that have generally been optimized to a fare-thee-well. I got a speedup primarily because I could exploit the fact that tan and cos were operating on a limited domain.

I updated the rules so you can just run it on your own CPU (assuming you pass the diehard tests).

I added some suggestions but the one that seems most relevant to your answer is that you can make a good approximation for most of the distribution I think and then just default to the more precise version when the random variables are near their extremes.

@Anush: Yes, I was already aware of that, but the rules require 32-bit precisionthroughout, and I can't change that.

@Lembik: W.r.t. using SSE, that's possible in principle. The RNG could be optimized that way (since you essentially can generate four 32-bit random numbers in parallel). The main problem with the rest of the code is that I'd have to write a sufficiently precise natural logarithm implementation for SSE (which isn't exactly a quick thing to do), so that I could run two of the calculations in parallel (using packed double representation).

Having thrown together a quick SSE implementation for Xorshift, that doesn't seem to help; if anything, it seems to be marginally slower, and the Xorshift RNG already takes up less than 10% of the total time. The bulk of the remaining time appears to be spent computing the natural logarithm; removing the ln(...) calls reduces runtime to less than 1.5 seconds.

Is this helpful? http://bpaste.net/show/BD3JwvM5UMhj2UmNKzmQ/

GMPY2
Abuse of GMP. @OP the slowest part of the code is printing the numbers, if leaving them in memory is fine the code would be much much faster.
import math
import random
import gmpy2
from gmpy2 import mpz, mpfr

gmpy2.get_context().precision = 11 # 32 bits of accuracy

N = 100000000
random_state = gmpy2.random_state()
pi = math.pi
half_pi = pi / 2
size = 0
for i in range(N):
    u1 = gmpy2.mpfr_random(random_state)
    u2 = gmpy2.mpfr_random(random_state)
    w1 = gmpy2.mul(pi, gmpy2.sub(u1,1/2))
    w2 = -gmpy2.log(u2)
    a = gmpy2.mul(gmpy2.tan(w1), gmpy2.sub(half_pi, w1))
    b = gmpy2.div(gmpy2.log(gmpy2.mul(w2, gmpy2.cos(w1))), gmpy2.sub(half_pi, w1))
    x = gmpy2.add(a, b)

I would like to remove the printing. The problem is that the whole code might be optimized out then!

@Lembik Write it to file?

I added an if statement which should reduce the output size by a factor of about 10000.

@Lembik: if statements are slow.

@KyleKanos If you can think of a better way to do this please let me know! It was my best attempt so far.  But is it really slow if the test almost always fails?

@Lembik: The code needs to test the inequality each iteration, which is what makes it slow. A faster way to ensure it isn't optimized out is to just sum x and print it out at the end (or something similar).

@KyleKanos  Are you available on chat? I just tested without the if and it takes the same amount of time.

@Lembik: I'm not available for chat, I'm about to head out with my kids. Probably tomorrow though. By summing x, I get ~11s run whereas printing for x>3 it takes more than 2 minutes (using ifort for both runs).

@KyleKanos OK chat tomorrow. Very odd though about your timings. I get 20 seconds for both using gcc -O3. Are you piping to /dev/null? Otherwise it would be slower.

@Lembik I can't run your code because even though I have mtwist.h I get the error `undefined reference to 'mt_default_state' and there's not much documentation online about it. I think you should test my code (python and gmpy2 are very easy to install)

You need the .c file (see the example GCC line in the question). I just put all the mtwist files in one directory and ran that GCC line. I can test your code on Sunday as well..

Unfortunately your code is so slow I killed it after half an hour.  How long does it take for you?

Numpy (score = 1.8)
In response to my previous code not being fast enough (I admit it was very slow), I used numpy which is extremely fast at working with large arrays of numbers and uses low level number libraries (BLAS). This is almost a direct translation of your code, but already is noticeably faster and has the bonus of being very readable.
import math
from numpy import *

pi = math.pi
half_pi = pi / 2

for i in range(10000):
    u1 = random.rand(10000)
    u2 = random.rand(10000)

    w1 = pi * (u1 - 1/2)
    w2 = -log(u2)

    a = half_pi - w1
    x = tan(w1)*a + log(w2*cos(w1)/a)

print("done")

I am running on i7 4770 with 8 gb RAM. Your code (including -O3 in GCC): 21.8 sec, my code: 11.8 sec.

Thanks for this but your code takes 23 seconds compared to 20 seconds for mine on my machine. What timings are you getting and are you compiling mine with -03?

@Lembik I am running on i7 4770. Your code (including -O3): 21.8 sec, my code: 11.8 sec. I find it unlikely that gcc could beat numpy, because numpy operates efficiently on arrays and uses BLAS. Maybe try it again? I'm not sure what could have caused this difference.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/