Thursday, December 6, 2018

in use of hacker

this code is coped here for learning purpose!!!!!!!!!!!



# Basic File Info
# Bugs: Unknown.
# Author: Mickel Sánchez.
# Creation date: April 14, 2018.

# Disable warnings in Ruby.
# The interpreter complains
# if I redefine constants of some modules

$VERBOSE = nil

require 'open-uri'
require 'openssl'

# Deactivate verification of certificates.
# Code Playground does not allow me to
# make HTTPS requests by default.

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

# Since by default I can not use files in Sololearn
# I decided to create some test files
# and I uploaded them to my Dropbox.

# All the files are basically a 'Hello Sololearn!'
# In some random languages that I have installed on my PC.

files = [
    'https://dl.dropbox.com/s/bi1d8dwn3iki52w/Sololearn.cs',
    'https://dl.dropbox.com/s/0c1dcaye2e4j7j2/Sololearn.go',
    'https://dl.dropbox.com/s/unm8gyivxoe17ja/Sololearn.sh',
    'https://dl.dropbox.com/s/3ty3svm7jia2xvu/Sololearn.php',
    'https://dl.dropbox.com/s/w9kuudbrl64lyiy/Sololearn.html'
]

def get_file(url)
    # This is a little trick so that my files
    # keep the name with which I uploaded them to Dropbox.
    name = "#{url.split('/')[-1]}"
 
    # I create the file within the current directory.
    file = File.new(name, "w+")
    open(url) do |f|
        # The open (open-uri) block allows me to get
        # the content of the request line by line.
        # It's great to copy the content to a file.

        f.each_line {|line| file.write(line)}
    end
    file.close
    # Currently in the directory there are two files:
    # - Sololearn.*
    # - Source.rb

    # The first is the file that was
    # created in this method.
    # The second is the file corresponding to this code
    # which will be interpreted by the SL server.
    # So I return the first file.
    Dir["#{name}"][0]
end

def get_file_info(file_name)
    # I wanted to use the Pathname module
    # but I had problems with the execution time :(
 
    # In any case, I decided to obtain the basic information
    # of the file through the File class.
 
    # I decided not to include information about
    # the date of creation, modification and last access of the file.
    # Since they were created within the get_file() method
    # they all share the same values.
 
    # Also, I got complicated by specifying
    #which time zone should convert the dates, lol.
    puts "*** FILE INFORMATION ***"
    puts
    puts "Size:      #{File.size(file_name)} bytes"
    puts "Name:      #{File.basename(file_name, '.*')}"
    puts "Extension: #{File.extname(file_name)}"
    puts "Directory: #{File.absolute_path(file_name)}"
    puts "Writable:  #{File.writable?(file_name)}"
    puts
    puts "*** FILE CONTENT ***"
    puts
    File.foreach(file_name) { |line| puts line }
end


file = get_file(files.sample)
get_file_info(file)

No comments:

Post a Comment

form validation

function formsubmit ( ) { var empname = document .getElementById ( 'emp_name' ). value ; var email = document .getElem...