Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: vivex42 on Dec 10th, 2013  |  syntax: Ruby  |  size: 2.42 KB  |  views: 54  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. =begin
  3.  
  4. ########PERL 5 CODE###########
  5. #use warnings;
  6. #use strict;
  7. #use HTTP::Server::Simple;
  8. #my $server = HTTP::Server::Simple->new();
  9. #$server->run();
  10. ##############################
  11. =end
  12.  
  13. =begin
  14.         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.
  15. =end
  16.  
  17. require 'sinatra'
  18.  
  19.  
  20. =begin
  21. THIS PART OF THE SCRIPT WORKS FINE ON ITS OWN.
  22. $accumulator=0
  23.  
  24. #words=IO.readlines("numerology_chase.txt")
  25.  
  26. words=open("code.txt",&:read).split("")
  27.  
  28. #File.open("numerology_chase.txt").each_line do |line|
  29.  
  30. for i in words
  31. $accumulator += i.to_i
  32. end
  33.  
  34. accumulator_data = $accumulator.to_s
  35.  
  36.  
  37. numerology=accumulator_data.split("")
  38. $i=0
  39. for i in numerology
  40.         $i+=i.to_i
  41. end
  42.  
  43. puts "And the number is: #{$i}"
  44.  
  45. =end
  46.        
  47. before do #do this before anything happens, just to be certain
  48.         content_type :text
  49.         require 'mechanize'    
  50. end
  51.  
  52.  
  53. #for require 'mechanize'
  54. def numerology(url) #mechanize has the capability of logging into websites,
  55.                                         #data mining, among other things, especially downloading using "read=agent.get(url)"
  56.                 agent=Mechanize.new
  57.                 read = agent.get(url)
  58.                 save_as = read.save_as("webpage_#{Random.rand(0..(10**100+10*100)).to_s}_.html") #save this as a random webpage        
  59.                 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"        
  60. end
  61.  
  62. #$page_counter=0
  63. get '/url_num/*' do    
  64.         a=numerology("#{params[:splat].shift}".sub!(/\//,'//')) #convert the wrong url back into http:// from http:/,
  65.                                                                                                                         #as far as I can remember.
  66.         file_name=a
  67.         $accumulator=0 #global variable
  68.        
  69.         words=open("#{file_name}",&:read).split("") #open, read, then split the downloaded file into individual bytes
  70.        
  71.         for i in words
  72.                 $accumulator += i.to_i #add up all the char bytes; ascii==numbers
  73.         end
  74.  
  75.         accumulator_data = $accumulator.to_s #convert to string
  76.  
  77.  
  78.         numerology=accumulator_data.split("")
  79.         $i=0
  80.         for i in numerology
  81.                 $i+=i.to_i
  82.         end
  83.  
  84.         "And the number is: #{$i}"
  85.        
  86.         #numerology_proc=$agent.get("#{params[:splat]}")
  87.         #"You passed in #{numerology_proc.inner_html}"
  88. end
  89. =begin
  90. {loading spaghetti code}
  91. set :views, File.dirname(__FILE__) + '/public' #set views to ./html (current directory/html)
  92. def load_pictures
  93.         Dir.glob("#{File.dirname(__FILE__)}/*.{jpg,JPG,gif,GIF,PNG}")
  94. end
  95.  
  96. get '/' do
  97.        
  98.         @pictures = load_pictures
  99.        
  100.         erb :index
  101. end
  102. =end
clone this paste RAW Paste Data