4, ఆగస్టు 2025, సోమవారం

python lab-3 implementation ........................

 # Initializing three numbers

num1, num2, num3 = 10, 20, 30


# Calculating sum and average

sum_numbers = num1 + num2 + num3

average = sum_numbers / 3


# Displaying the result

print(f'Sum: {sum_numbers}, Average: {average}')



print ('argument list', sys.argv)

first = int(sys.argv[1])

second = int(sys.argv[2])

print ("sum = {}".format(first+second))


C:\ramu>python hello.py 10 20

argument list ['hello.py', '10', '20']

sum = 30




def get_employee_data(): """Reads employee data from the keyboard.""" employee_id = input("Enter Employee ID: ") employee_name = input("Enter Employee Name: ") employee_salary = input("Enter Employee Salary: ") employee_department = input("Enter Employee Department: ") employee_info = { "ID": employee_id, "Name": employee_name, "Salary": employee_salary, "Department": employee_department } return employee_infodef print_employee_data(employee_data): """Prints the provided employee data.""" print("\n--- Employee Details ---") for key, value in employee_data.items(): print(f"{key}: {value}")if __name__ == "__main__": employee_details = get_employee_data() print_employee_data(employee_details)




import math# Get the radius from the usertry: radius = float(input("Enter the radius of the circle: "))except ValueError: print("Invalid input. Please enter a numerical value for the radius.") exit()# Check if the radius is non-negativeif radius < 0: print("Radius cannot be negative. Please enter a positive value.")else: # Calculate the area area = math.pi * (radius ** 2) # Display the result print(f"The area of the circle with radius {radius} is: {area}")






3, ఆగస్టు 2025, ఆదివారం

UNIT 2 RUBY ADVANCED END..........................S L For B.Tech C.S.E FINAL YEAR

 Embedding a Ruby interpreter within another scripting language is not a typical direct integration model. Ruby, being a scripting language itself, is more commonly embedded within applications written in lower-level compiled languages like C or C++.

However, the concept of "embedding" Ruby in a broader sense can be interpreted as:

·         Embedding Ruby in Compiled Languages (like C/C++):

·         This is the most common form of embedding. The Ruby interpreter, which is primarily written in C, can be integrated into C/C++ applications.

·         This allows the C/C++ application to execute Ruby code, call Ruby methods, and interact with Ruby objects, effectively using Ruby as a scripting layer for the compiled application.

·         Functions like ruby_init(), ruby_cleanup(), and rb_eval_string() are used to initialize the interpreter, execute Ruby code, and manage resources.

·         Using Ruby for Templating in Web Applications:

·         Technologies like Embedded Ruby (ERB) allow Ruby code to be embedded within other files, most notably HTML.

·         This is a form of "embedding" where Ruby acts as a templating engine to generate dynamic content within a web context.

·         The Ruby code within <% ... %> or <%= ... %> delimiters is executed, and its output or value is inserted into the surrounding content.

·         Cross-Language Interaction via APIs or Bridges:

·         While not a direct "embedding" of the interpreter, Ruby can interact with other languages through various mechanisms.

·         For example, JRuby allows Ruby to run on the Java Virtual Machine (JVM), enabling seamless interaction with Java code.

·         Similarly, other language-specific bridges or APIs might exist to facilitate communication and data exchange between Ruby and other scripting languages.

In summary, if the goal is to execute Ruby code directly within another scripting language's environment, it's more likely to involve using a bridge or a shared runtime environment (like the JVM for JRuby) rather than directly embedding the Ruby interpreter's C-based core. The direct embedding is primarily a feature for compiled languages.

 

2, ఆగస్టు 2025, శనివారం

web servers..........................

 Oracle WebLogic Server is a Java application server used for developing, deploying, and running enterprise Java applicationsIt provides a robust, scalable, and highly available environment for deploying Java EE (or Jakarta EE) applications. WebLogic Server acts as a platform for various services like web serving, business logic execution, and access to backend systems

WebSphere Application Server (WAS) is an IBM application server used to host Java-based web applicationsIt provides a runtime environment for enterprise Java applications, enabling developers to build, deploy, and manage them. WAS is a core component of IBM's WebSphere software suite and has been available since 1998


JBoss, now primarily known as WildFly in its open-source community version, and Red Hat JBoss Enterprise Application Platform (EAP) in its enterprise-supported version, is an open-source, Java-based application server. It is developed and maintained by Red Hat

Apache Tomcat is an open-source web server and Servlet container developed by the Apache Software Foundation. It provides a "pure Java" HTTP web server environment in which Java code can run, making it a popular choice for hosting Java-based web applications.




Ruby CGI Scripts for my class...................................

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// Servlet implementation class FormDataHandle
// Annotation to map the Servlet URL
@WebServlet("/FormData")
public class FormDataHandle extends HttpServlet {
    private static final long serialVersionUID = 1L;

    // Auto-generated constructor stub
    public FormDataHandle() {
        super();
    }

    // HttpServlet doPost(HttpServletRequest request, HttpServletResponse response) method
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        // Get the values from the request using 'getParameter'
        String name = request.getParameter("name");
        String phNum = request.getParameter("phone");
        String gender = request.getParameter("gender");
        
        // To get all the values selected for 
        // programming language, use 'getParameterValues'
        String progLang[] = request.getParameterValues("language");
      
        // Iterate through the String array to 
        // store the selected values in form of String
        String langSelect = "";
        if(progLang!=null){
            for(int i=0;i<progLang.length;i++){
                langSelect= langSelect + progLang[i]+ ", ";
            }
        }
        
        String courseDur = request.getParameter("duration");
        String comment = request.getParameter("comment");
                
        // set the content type of response to 'text/html'
        response.setContentType("text/html");
        
        // Get the PrintWriter object to write 
        // the response to the text-output stream
        PrintWriter out = response.getWriter();
        
        // Print the data
        out.print("<html><body>");
        out.print("<h3>Details Entered</h3><br/>");
        
        out.print("Full Name: "+ name + "<br/>");
        out.print("Phone Number: "+ phNum +"<br/>");
        out.print("Gender: "+ gender +"<br/>");
        out.print("Programming languages selected: "+ langSelect +"<br/>");
        out.print("Duration of course: "+ courseDur+"<br/>");
        out.print("Comments: "+ comment);
        
        out.print("</body></html>");
        
    }

}

 Ruby is a programming language with wide use; it does not only work in web development language; however, Ruby development is also common in web applications and web tools. In addition to using Ruby to write your own SMTP server, FTP program, or Ruby web server, you can also use Ruby CGI programming.

Configuration and support of Webserver

Before you go ahead to use CGI programming, ensure your web server has been configured to work with CGI and CGI handlers.

Apache supports CGI configuration:

Set up the CGI directory:

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

The HTTP server for the execution of CGI programs is saved in a pre-configured directory. The name of the directory is the CGI directory and conventionally called /var/www/CGI-bin directory.

The file extension for CGI is .cgi, and ruby extension (.rb) can also be used.

The default Linux server configuration to run the cgi-bin directory is /var/www

If you want to run the CGI scripts with another directory, you can change the configuration file (httpd.conf) as follows:

<Directory "/var/www/cgi-bin">

AllowOverride None

Options +ExecCGI

Order allow,deny

Allow from all

</Directory>

Add .rb suffix AddHandler, so that we can access the .rb end of the Ruby script file:

AddHandler cgi-script .cgi .pl .rb

Writing CGI Scripts

Basically, Ruby CGI scripts will look like the following:

#!/usr/bin/ruby

puts "HTTP/1.0 200 OK"

puts "Content-type: text/html\n\n"

puts "<html><body>This is a test</body></html>"

If you call the test.cgi script and uploaded it to a web hosting provider based on Unix with the right permissions; you can utilize it as a CGI script.

For instance, if your site https://www.upstack.com/ is hosted by a Linux web hosting provider and you upload test.cgi in your home directory and give execution permission, go to https://www. Example.com/test.cgi should return an HTML page, indicating that it is a test.

When a Web browser requests the test.cgi, the webserver searches for test.cgi on the website and executes through the Ruby Interpreter. The Ruby script sends a simple HTTP header and returns an HTML document.

Using CGI.RB

Ruby features a special library known as CGI, and it enables a more advanced interaction greater than the preceding CGI script.

With the cgi, you can create a simple CGI script:

#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new

puts cgi.header

puts "<html><body>This is a test</body></html>"

Form Processing

There are two ways to access HTML query parameters using CGI classes. Suppose we have URL like /cgi-bin/test.cgi?FirstName = Emmanuel&LastName = Mario.

When you use CGI#[] directly as illustrated below, you will have access to the FirstName and LastName parameters.

#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new

cgi['FirstName'] # =>

["Emmanuel"]

cgi['LastName'] # => ["Mario"]

You can also access the form variables using another way. This code will provide the hash for all keys and values:

#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new

h = cgi.params # => {"FirstName"=>["Emmanuel"],"LastName"=>["Mario"]}

h['FirstName'] # => ["Emmanuel"]

h['LastName'] # => ["Mario"]

You can find below the code to use for retrieving all keys:

#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new

cgi.keys # => ["FirstName", "LastName"]

If there are multiple fields in a form with the same name, the corresponding values ​​are returned to the script will in the form of an array. The [] accessor only returns the result of the first such .index params method to get them.

In the code illustration below, as an assumption, the form contains three fields known as “name” and we input three different names “Maria” “Jude” “Jason”:

#!/usr/bin/ruby

require 'cgi'

cgi = CGI.new

cgi['name'] # => "Maria"

cgi.params['name'] # => ["Maria", "Jude", "Jason"]

cgi.keys # => ["name"]

cgi.params # => {"name"=>["Maria", "Jude", "Jason"]}

Ruby will automatically handle the GET and POST methods. And the treatment for the two methods is the same and not in any way separate.

A basic and associated data capable of sending the correct data will have the HTML code like the following:

<html>

<body>

<form method = "POST" action = "http://www.example.com/test.cgi">

First Name :<input type = "text" name = "FirstName" value = "" />

<br />

Last Name :<input type = "text" name = "LastName" value = "" />

<input type = "submit" value = "Submit Data" />

</form>

</body>

</html>

Creating Forms and HTML Form

There are many ways to create HTML in CGI, and each HTML tag contains a corresponding method. Prior to using these methods, the report must be CGI to create a CGI.new object. To facilitate the label nesting, these methods are included as blocks of code; code blocks return strings as a content tag. Following is an example:

#!/usr/bin/ruby

require "cgi"

cgi = CGI.new("html4")

cgi.out{

cgi.html{

cgi.head{ "\n"+cgi.title{"This Is a Test"} } +

cgi.body{ "\n"+

cgi.form{"\n"+

cgi.hr +

cgi.h1 { "A Form: " } + "\n"+

cgi.textarea("get_text") +"\n"+

cgi.br +

cgi.submit

}

}

}

}

String escape

While working with parameters in the URL or HTML form data, it is necessary that you specify special characters for the escape; some of them are quotation marks ( "), slash (/).

In the Ruby CGI object, you will be given CGI.escape CGI.unescape and methods to handle escaping these characters:

#!/usr/bin/ruby

require 'cgi'

puts CGI.escape(Emmanuel Mario/ Serious & Intelligent")

The execution of the above code is as follows:

#!/usr/bin/ruby

require 'cgi'

puts CGI.escape(Emmanuel Mario/ Serious & Intelligent")

Some examples include:

#!/usr/bin/ruby

require 'cgi'

puts CGI.escapeHTML('<h1>Emmanuel Mario/Serious & Intelligent</h1>')

The execution of the above code is as follows:

&lt;h1&gt;Emmanuel Mario/ Serious & Intelligent&lt;/h1&gt;'

Some CGI methods

  • CGI::new([level=”query”])
  • CGI::escape (str)
  • CGI::unescaped (str)
  • CGI::escapeHTML (str)
  • CGI::unescapeHTML (str)
  • CGI::escapeElement( str[,element…])
  • CGI::unescapeElement( str[,element…])
  • CGI::parse(query)
  • CGI::pretty(string[, leader=””])
  • CGI::rfc1123_date(time)