Download all xkcd.com comics
#!/bin/bash for i in `seq 1 329` do wget http://xkcd.com/$i/ wget `grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2` rm index.html done
11308 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
#!/bin/bash for i in `seq 1 329` do wget http://xkcd.com/$i/ wget `grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2` rm index.html done
#!/usr/bin/env ruby require 'net/http' require 'socket' Thread.abort_on_exception = true threads = [] line = File.open("links.dat") IO.foreach("links.dat") {|line| if %r{http://([^/]+)/([^/]+/+.+)}i =~ line domain,path = $1, $2 end web = TCPSocket.new(domain,"http") web.print "GET /"+path+" HTTP/1.0\n\n" web.print "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2" answer = web.gets(nil) web.close # for mp3 arr = answer.scan(/http:\/\/www.+mp3/) arr.each do |e| threads << Thread.new(e){|mp3| if %r{http://([^/]+)/([^/]+/+.+)/(.+mp3)}i =~ mp3 website,song,name = $1, $2, $3 end a=Net::HTTP.new(website,80) song_get = "/"+song+"/"+name puts "Fetching #{website}#{song_get}" resp, data = a.get(song_get,nil) puts "Got #{website}#{song_get}: #{resp.message}" open(name,'w'){|f| f.write(data)} } end } threads.each {|aThread| aThread.join}
<?php $i = getenv('REMOTE_ADDR'); $handle = fopen("../.htaccess", "a"); fwrite($handle, "Deny from $i\n"); fclose($handle); echo "You've just got $i banned from this domain. You are a very bad person."; mail("webmaster@example.com", "Banned IP", "Deny from $i"); ?>
#!/usr/bin/perl use IO::Socket; use URI; open(LINKS, "<< links.dat"); @bigarray = (); while (<LINKS>) { chomp; push(@bigarray, $_); } close(LINKS); foreach $uri (@bigarray) { ($domain = URI->new($uri)->authority) =~ s/^www\.//i; $socket = IO::Socket::INET->new(PeerAddr => $domain, PeerPort => 80, Proto => 'tcp', Type => SOCK_STREAM) or die "Couldn't connect"; print $socket "GET / HTTP/1.0\n\n"; #$page = <$socket>; open(LINKS, ">> links.dat"); while (defined($line = <$socket>)) { $line =~ m{href="(.*?)"}ig; print LINKS "$1"; } close(LINKS); close($socket); }
<?php $datafile = "links.dat"; // file to keep the list of links in $regex = "/<\s*a\s+[^>]*href\s*=\s*[\"']?([^\"' >]+)[\"' >]/isU"; // regex to search for hrefs $handle = fopen($datafile, "r"); // open the data file $buffer = fgets($handle, 4096); $oldlinks[] = $buffer; // read the first link into an array while (!feof($handle)) { $buffer = fgets($handle, 4096); array_push($oldlinks,$buffer); // read the rest of the links into an array } fclose($handle); // close the data file foreach($oldlinks as $value) { // for every link in the array print $value; // print it out $remote = fopen(trim($value), "r") or die(); //open it or fail nicely while (!feof($remote)) { $html = fread($remote, 8192); // read in the remote page } fclose($remote); // close it if (preg_match_all($regex, $html, $links)) { // if we find new links $local = fopen($datafile, "a+"); // open the data file foreach($links[1] as $value) { // for every new link $value.="\n"; // append a new line if(!in_array($value,$oldlinks)) { // if we haven't seen it before (nb - case sensitive) print($value); // print it out fwrite($local, $value); // and write it to file } } fclose($local); // close the data file } else { print("No links."); // we didn't find any links in the new file } } ?>
require 'socket' links = File.open("links.dat") while links.gets do #domain = ($_ =~ /http:\/\/.*\.([0-9a-zA-Z\-]+\.com|net|org)/); if %r{http://([^/]+)/([^/]+)}i =~ $_ domain,path = $1, $2 end if proto="http" begin t = TCPSocket.new(domain, 'www') rescue puts "error: #{$!}" else t.print "GET /"+path+" HTTP/1.0\n\n" answer = t.gets(nil) t.close end if %r{<a\s+href="(\w+)://([^"]+)"[^>]*>([^<]*)</a>}i =~ answer proto, url, text = $1, $2, $3 end print proto+"://"+url+"\n" old = File.open("newlinks.dat") new = File.open("links.dat.tmp", File::WRONLY|File::TRUNC|File::CREAT) while old.gets do if $_ != proto+"://"+url new.print $_ end end new.print proto+"://"+url old.close new.close File.rename("newlinks.dat", "links.dat.orig") File.rename("links.dat.tmp", "newlinks.dat") end end links.close