Advertisement
vivex42

Server 3.0 update

Dec 10th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #http://localhost:4567/url_num/%5Burl_here%5D
  2.  
  3. =begin
  4.  
  5. ########PERL 5 CODE###########
  6. #use warnings;
  7. #use strict;
  8. #use HTTP::Server::Simple;
  9. #my $server = HTTP::Server::Simple->new();
  10. #$server->run();
  11. ##############################
  12. =end
  13.  
  14. =begin
  15.     Before you fully understand this, you ought to learn Perl, at least a little, but I will try to help in every way, shape, and form.
  16. =end
  17.  
  18. require 'sinatra'
  19.  
  20.  
  21. =begin
  22. THIS PART OF THE SCRIPT WORKS FINE ON ITS OWN.
  23. $accumulator=0
  24.  
  25. #words=IO.readlines("numerology_chase.txt")
  26.  
  27. words=open("code.txt",&:read).split("")
  28.  
  29. #File.open("numerology_chase.txt").each_line do |line|
  30.  
  31. for i in words
  32. $accumulator += i.to_i
  33. end
  34.  
  35. accumulator_data = $accumulator.to_s
  36.  
  37.  
  38. numerology=accumulator_data.split("")
  39. $i=0
  40. for i in numerology
  41.     $i+=i.to_i
  42. end
  43.  
  44. puts "And the number is: #{$i}"
  45.  
  46. =end
  47.    
  48. before do #do this before anything happens, just to be certain
  49.     content_type :text
  50.     require 'mechanize'
  51. end
  52.  
  53.  
  54. #for require 'mechanize'
  55. def numerology(url) #mechanize has the capability of logging into websites,
  56.                     #data mining, among other things, especially downloading using "read=agent.get(url)"
  57.         agent=Mechanize.new
  58.         read = agent.get(url)
  59.         save_as = read.save_as("webpage_#{Random.rand(0..(10**100+10*100)).to_s}_.html") #save this as a random webpage    
  60.         return save_as   #everyone will understand this, but you don't even need to return anything, all you need in a single line is "save_as"    
  61. end
  62.  
  63. #$page_counter=0
  64. get '/url_num/*' do
  65.     a=numerology("#{params[:splat].shift}".sub!(/\//,'//')) #convert the wrong url back into http:// from http:/,
  66.                                                             #as far as I can remember.
  67.     file_name=a
  68.     $accumulator=0 #global variable
  69.    
  70.     words=open("#{file_name}",&:read).split("") #open, read, then split the downloaded file into individual bytes
  71.    
  72.     for i in words
  73.         $accumulator += i.to_i #add up all the char bytes; ascii==numbers
  74.     end
  75.  
  76.     accumulator_data = $accumulator.to_s #convert to string
  77.  
  78.  
  79.     numerology=accumulator_data.split("")
  80.     $i=0
  81.     for i in numerology
  82.         $i+=i.to_i
  83.     end
  84.  
  85.     "And the number is: #{$i}"
  86.    
  87.     #numerology_proc=$agent.get("#{params[:splat]}")
  88.     #"You passed in #{numerology_proc.inner_html}"
  89. end
  90. =begin
  91. {loading spaghetti code}
  92. set :views, File.dirname(__FILE__) + '/public' #set views to ./html (current directory/html)
  93. def load_pictures
  94.     Dir.glob("#{File.dirname(__FILE__)}/*.{jpg,JPG,gif,GIF,PNG}")
  95. end
  96.  
  97. get '/' do
  98.    
  99.     @pictures = load_pictures
  100.    
  101.     erb :index
  102. end
  103. =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement