Results found for ""
- How to Install OEL (Oracle Enterprise Linux) on Virtualbox?
This blog article focuses on configuring Virtualbox to create a new VM for Oracle Linux 7 (OEL) and installing Oracle Linux 7 from the ISO image as a guest operating system. The Oracle Linux 7 ISO image can be downloaded from edelivery.oracle.com – Oracle Software Delivery Cloud. You must have a valid Oracle Account (free) to download the Linux ISO. Link: edelivery.oracle.com (downloaded platform x86 64 bit for this post, check your system configuration before you download) Configuring Virtual Box To create a VM, click on the New button on the top left corner and provide a descriptive name for the VM, type of OS and Version. The name that is specified will be used to identify the VM configuration: Once the required information is provided, click on the Next button. Specify how much RAM you want to designate to your virtual machine. I have allocated 20 GB. Click on Next button, lets keep Hard disk as default size. Hit Create button, now keep Hard disk file type as VDI. We can change this later. Hit Next button, keep storage as dynamic allocation. Hit Next button and configure file location and size. For this post lets go with 20 GB. Hit Create button. Once the VDI disk is created with the specified size, you will be re-directed back to the main screen. You will be able to see all the details as shown below: Go to Settings and select Network tab, change configuration to "Bridged Adapter" and Promiscuous Mode to "Allow All" as shown below: Go to System tab and assign number of processors. I have selected 4 processors for this example: Now go to Storage tab and click on disk image to choose Virtual Optical Disk ISO image file which you downloaded initially from Oracle Cloud. Click on OK and now you will be able to see Optical Drive ISO image file as highlighted below (it was empty before, refer old previous screenshots). Ignore the name as it depends on which ISO image you download from Oracle cloud. Installing Oracle Linux From the Oracle VM VirtualBox Manager screen, select your VM that you just created and click on the green Start icon on the top of the screen. Select the language as English (United States). Hit Continue button. Now select Installation Destination as Local Standard Disks. Now go back and select Network & Host Name (currently it's shown as not connected). Turn ON the connection. Now setup the ROOT password: Create another User if you need. For instance I have created Hadoop user: Let post-installation setup tasks finish. Once it's done, you can click on the Software Selection button and choose to install a “Server with GUI” option and choose the KDE desktop. Click on the Done button after you select all the options that you want installed. From the Configuration screen, click on the Reboot button. Once the VM reboots, you will be directed to the login prompt. Since we did a bare minimal installation, we will not enter into a GUI mode. Login with root user and password which we setup earlier. Install net-tools package, Type: yum install net-tools Once net-tools installs, Type: ifconfig inet shown above will tell your IP address. That's it !!! To check your Linux version, Type: uname -a , you will get something like below: [root@localhost anonymous]# uname -a Linux localhost.localdomain 4.1.12-112.16.4.el7uek.x86_64 #2 SMP Mon Mar 12 23:57:12 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux If you have any question please mention it in the comments section below. Thank you! #RedhatLinux #OracleLinuxInstallation #Installing #Oracle #Linux #on #Virtual #Box
- How to Install Apache HTTP Server on CentOS
yum install httpd Apache is most popular HTTP Server which runs on Linux & Windows based operating system. Let's see how to install and configure Apache HTTP Web Server on CentOS. 1. First update yum package sudo yum -y update 2. Next, install Apache HTTP server sudo yum install httpd 3. Start & Enable HTTP server (to start automatically on server reboot) [centos@ ~]$ sudo systemctl start httpd [centos@ ~]$ sudo systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. 4. Now check the status of Apache server [centos@ ~]$ sudo systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2018-08-02 18:32:00 UTC; 6min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 10235 (code=exited, status=0/SUCCESS) Aug 02 18:32:00 dataneb.com systemd[1]: Starting The Apache HTTP Server... Aug 02 18:32:00 dataneb.com httpd[10235]: httpd (pid 10202) already running Aug 02 18:32:00 dataneb.com kill[10237]: kill: cannot find process "" Aug 02 18:32:00 dataneb.com systemd[1]: httpd.service: control process exited, code=exited status=1 Aug 02 18:32:00 dataneb.com systemd[1]: Failed to start The Apache HTTP Server. Aug 02 18:32:00 dataneb.com systemd[1]: Unit httpd.service entered failed state. Aug 02 18:32:00 dataneb.com systemd[1]: httpd.service failed. 5. If server does not start, disable SELinux on CentOS [centos@]$ cd /etc/selinux [centos@]$ sudo vi config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. # SELINUX=enforcing SELINUX=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted 6. Reboot the system to make SELinux changes effective [centos@ ~]$ sudo reboot debug1: channel 0: free: client-session, nchannels 1 Connection to xx.xxx.xxx.xx closed by remote host. Connection to xx.xxx.xxx.xx closed. Transferred: sent 16532, received 333904 bytes, in 1758.1 seconds Bytes per second: sent 9.4, received 189.9 debug1: Exit status -1 7. Now check the status of Apache server again [centos@ ~]$ sudo systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2018-08-02 18:40:18 UTC; 35s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 855 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─855 /usr/sbin/httpd -DFOREGROUND ├─879 /usr/sbin/httpd -DFOREGROUND ├─880 /usr/sbin/httpd -DFOREGROUND ├─881 /usr/sbin/httpd -DFOREGROUND ├─882 /usr/sbin/httpd -DFOREGROUND └─883 /usr/sbin/httpd -DFOREGROUND Aug 02 18:40:17 dataneb.com systemd[1]: Starting The Apache HTTP Server... Aug 02 18:40:18 dataneb.com systemd[1]: Started The Apache HTTP Server. 8. Configure firewalld (CentOS is built by default to block Apache traffic) [centos@ ~]$ firewall-cmd --zone=public --permanent --add-service=http [centos@ ~]$ firewall-cmd --zone=public --permanent --add-service=https [centos@ ~]$ firewall-cmd --reload 9. Test your url by entering Apache server ip address in your local browser Thank you!! If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Google or Facebook. Refer the links below. Also click on "Subscribe" button on top right corner to stay updated with latest posts. Your opinion matters a lot please comment if you have any suggestion for me. #install #apache #httpserver #centos #howtoinstallapacheoncentos Learn Apache Spark in 7 days, start today! Main menu: Spark Scala Tutorial 1. Apache Spark and Scala Installation 1.1 Spark installation on Windows 1.2 Spark installation on Mac 2. Getting Familiar with Scala IDE 2.1 Hello World with Scala IDE 3. Spark data structure basics 3.1 Spark RDD Transformations and Actions example 4. Spark Shell 4.1 Starting Spark shell with SparkContext example 5. Reading data files in Spark 5.1 SparkContext Parallelize and read textFile method 5.2 Loading JSON file using Spark Scala 5.3 Loading TEXT file using Spark Scala 5.4 How to convert RDD to dataframe? 6. Writing data files in Spark 6.1 How to write single CSV file in Spark 7. Spark streaming 7.1 Word count example Scala 7.2 Analyzing Twitter texts 8. Sample Big Data Architecture with Apache Spark 9. What's Artificial Intelligence, Machine Learning, Deep Learning, Predictive Analytics, Data Science? 10. Spark Interview Questions and Answers
- What is the difference between Python 2 and Python 3?
Below are the key differences which I have observed and encountered frequently while working on Python 2 and Python 3. Integer division Python2 : The return type of a division (/) operation depends on its operands. If both operands are of type int, floor division is performed and an int is returned. If either operand is a float, classic division is performed and a float is returned. The // operator is also provided for doing floor division no matter what the operands are. >>> 3/2 1 >>> -3/2 -2 >>> 3//2 1 >>> -3//2 -2 Python3 : Division (/) always returns a float. To do floor division and get an integer result (discarding any fractional result) you need to use // operator. >>> 3/2 1.5 >>> -3/2 -1.5 >>> 3//21 >>> -3//2-2 Input function Python2 : When you use input() function, Python dynamically converts the data type based on your input. So input() function can return anything int, str, float, bool, list etc based on your input. For instance, >>> val = input("Enter any value: ") Enter any value: 7 >>> type(val) int >>> val = input("Enter any value: ") Enter any value: 7.0 >>> type(val) float >>> val = input("Enter any value: ") Enter any value: 'abc' >>> type(val) str >>> val = input("Enter any value: ") Enter any value: True >>> type(val) bool >>> val = input("Enter any value: ") Enter any value: [1,2,3,4,5] >>> type(val) list When you use raw_input(), Python will simply return string irrespective of your input value data type. >>> val = raw_input("Enter any value: ") Enter any value: 7 >>> type(val) str >>> val = raw_input("Enter any value: ") Enter any value: 7.0 >>> type(val) str >>> val = raw_input("Enter any value: ") Enter any value: 'abc' >>> type(val) str and so on.. Python3 : In Python 3, input() function returns string type (acts like raw_input()). It’s confusing sometimes when you are transiting from Python 2 to Python 3. >>> val = input("Enter any value: ") Enter any value: 7 >>> type(val) str Note when you are using input() in Python 3 : If you are using Python 2.7, it’s good idea to use raw_input() when you are getting user inputs. In Python 3, you would use input(). Both the functions interprets all input as a string based on which version of Python you are using. Sometimes, I feel instead of Python doing type change dynamically it’s always safe to handle it manually. In Python 3, when you use the input() func, every input will be interpreted as string and sometimes it creates unexpected results. Consider the below example, >>> a = input("Enter first number: ") Enter first number: 3.4 >>> b = input("Enter second number: ") Enter second number: 5.7 >>> print a + b 3.45.7 # It's because >>> type(a), type(b) (str, str) # In order to fix this you need to apply float() function when user is prompted for input. Round function Python2 : Return the floating point value number rounded to n digits after the decimal point. If n digits is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus n digits; if two multiples are equally close, rounding is done away from 0 (so, for example, round(0.5) is 1.0 and round(-0.5) is -1.0). >>> round(3.5) 4.0 Python3 : Return number rounded to n digits precision after the decimal point. If n digits is omitted or is None, it returns the nearest integer to its input. >>> round(3.5) 4 Print function Python2 : Extra pair of parenthesis was not mandatory. >>> print "Hello" Hello >>> print 'Hello' Hello >>> print ("Hello") Hello >>> print ('Hello') Hello Python3 : Extra pair of parenthesis is now mandatory. >>> print "Hello" SyntaxError: Missing parentheses in call to 'print'. >>> print 'Hello' SyntaxError: Missing parentheses in call to 'print'. >>> print ("Hello") Hello >>> print ('Hello') Hello ASCII, Unicode and Byte types (Please ignore below question if you already have this understanding) What is ASCII, Unicode and Byte type in simple english? ASCII defines 128 characters, which map to the numbers 0–127. ASCII uses 7 bits to represent a character. By using 7 bits, we can have a maximum of 2^7 (= 128) distinct combinations. Which means that we can represent 128 characters maximum. The last bit (8th) is used for avoiding errors as parity bit. Most ASCII characters are printable characters of the alphabet such as a, b, c, A, B, C, 1, 2, 3, ?, &, ! etc. ASCII was meant for English only. The others are control characters such as carriage return, line feed, tab, etc. Binary representation of a few characters will be like: 1000001 -> A (ASCII code - 65) or 0001101 -> Carriage Return (ASCII code - 13) ASCII (including ASCII extended 2^8=256 characters) solves the problem for languages that are based on the Latin alphabet. But what about the others needing a completely different alphabet? Russian? Hindi? Chinese? We would have needed an entirely new character set, that's the rational behind Unicode. Unicode defines (less than) 2^21 characters, which, similarly, map to numbers 0–2^21 (though not all numbers are currently assigned, and some are reserved). Unicode is a superset of ASCII, and the numbers 0–127 have the same meaning in ASCII as they have in Unicode. For example, the number 65 means "Latin capital 'A' ". Because Unicode characters don't generally fit into one 8-bit byte, there are numerous ways of storing Unicode characters in byte sequences, such as UTF-32 and UTF-8. Python2 : It has ASCII string type, a separate unicode type, but there is no byte type. >>> type(unicode('a')) unicode >>> type(u'a') unicode >>> type(b'a') str Python3 : We have unicode strings, and byte type. >>> type(unicode('a')) NameError: name 'unicode' is not defined >>> type(u'a') str >>> type(b'a') bytes Range function Python2 : It has range and a separate xrange function. When you need actual list use range and when you need to iterate one object at a time use xrange like a generator which will be faster and save memory. >>> %timeit [i for i in range(1000)] The slowest run took 4.72 times longer than the fastest. This could mean that an intermediate result is being cached. 10000 loops, best of 3: 45.3 µs per loop >>> %timeit [i for i in xrange(1000)] 10000 loops, best of 3: 40.1 µs per loop Python3 : Here, range does what xrange used to do and xrange does not exist separately. If you want to write code that will run on both Python 2 and Python 3, you can't use xrange. >>> %timeit [i for i in range(1000)] 42.6 µs ± 1.23 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) >>> %timeit [i for i in xrange(1000)] NameError: name 'xrange' is not defined Exception handling Python2 : Syntax is little different for Python3. You need to include as keyword. try: BlahBlah except NameError, error: print error, " => ERROR IS HERE!" # output name 'BlahBlah' is not defined => ERROR IS HERE! try: BlahBlah except NameError as error: print error, " => ERROR IS HERE!" # output name 'BlahBlah' is not defined => ERROR IS HERE! Python3 : You need to include “as” keyword. try: BlahBlah except NameError as error: print (error, " => ERROR IS HERE!") # output name 'BlahBlah' is not defined => ERROR IS HERE! Global Namespace Leak Python2 : Consider below example, how global variable changes. num = 7 print (num) mylist = [num for num in range(100)] print (num) # output 7 99 Python3 : It’s fixed now, there is no namespace leak. num = 7 print (num) mylist = [num for num in range(100)] print (num) # output 7 7 Functions and methods that don’t return lists anymore in Python3 zip() map() filter() dictionary’s .keys() method dictionary’s .values() method dictionary’s .items() method List Comprehensions Python2 [item for item in 1,2,3,4,5] [1, 2, 3, 4, 5] Python3 : You need to use extra pair of parenthesis [item for item in (1,2,3,4,5)] [1, 2, 3, 4, 5] I just mentioned 10 differences. Please add in comments if you can recall other differences.
- Interesting and Unknown facts about Python programming
Python has gained more popularity in past 1 year! Actually, it’s the most popular programming language now. JAVA is the second most popular language after Python according to Google Trends. Python is the most popular programming language in United States of America! Do you know Monty Python? Why Python is called Python? Absolutely nothing to do with the snakes! It was named after this comedy group called Monty Python. When Guido van Rossum began implementing Python, he was also reading the published scripts from “Monty Python’s Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. The Python Logo - “Two Snakes”! Projects and companies that use Python are encouraged to incorporate the Python logo on their websites, brochures, packaging, and elsewhere to indicate suitability for use with Python or implementation in Python. Use of the "two snakes" logo element alone, without the accompanying wordmark is permitted on the same terms as the combined logo. According to Python Community, "Python is powerful... and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open." Import This! There is actually a poem written by Tim Peters named as THE ZEN OF PYTHON which can be read by just writing import this. import this #OutputThe Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently.Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! Wiki Python is best source of learning Python PythonBooks - Python Wiki. Tuple Unpacking with Enumerate. To get the index of elements. It is very useful for me when I look for indexes. for a,b in enumerate([1,2,3,4,5]): print a,b #Output 0 1 1 2 2 3 3 4 4 5 Chain comparison For example, if you want to check if a number is between 1000 to 10000, you can code like this if 1000<=num<=10000: print True You can work with infinity in Python import math math.isinf # Python 2 math.inf # Python 3 You can use else with for loop as well as while loop! What about this unpacking? x,y = 1,2 x,y = y,x+y print x,y #Output 2 3 It’s over 38 years now Van Rossum started developing the new script in the late 1980s and finally introduced the first version of that programming language in 1991. This initial release has module system of Modula-3. Later on, this programming language was named 'Python'. Van Rossum answer to why was Python created in first place? I had extensive experience with implementing an interpreted language in the ABC group at CWI, and from working with this group I had learned a lot about language design. This is the origin of many Python features, including the use of indentation for statement grouping and the inclusion of very-high-level data types (although the details are all different in Python). I had a number of gripes about the ABC language, but also liked many of its features. It was impossible to extend the ABC language (or its implementation) to remedy my complaints – in fact its lack of extensibility was one of its biggest problems. I had some experience with using Modula-2+ and talked with the designers of Modula-3 and read the Modula-3 report. Modula-3 is the origin of the syntax and semantics used for exceptions, and some other Python features. I was working in the Amoeba distributed operating system group at CWI. We needed a better way to do system administration than by writing either C programs or Bourne shell scripts, since Amoeba had its own system call interface which wasn’t easily accessible from the Bourne shell. My experience with error handling in Amoeba made me acutely aware of the importance of exceptions as a programming language feature. It occurred to me that a scripting language with a syntax like ABC but with access to the Amoeba system calls would fill the need. I realized that it would be foolish to write an Amoeba-specific language, so I decided that I needed a language that was generally extensible. During the 1989 Christmas holidays, I had a lot of time on my hand, so I decided to give it a try. During the next year, while still mostly working on it in my own time, Python was used in the Amoeba project with increasing success, and the feedback from colleagues made me add many early improvements. In February 1991, after just over a year of development, I decided to post to USENET. The rest is in the Misc/HISTORY file. Roundoff Error 0.1 + 0.2 - 0.3 is not equal to zero in Python (roundoff error) 0.1 + 0.2 - 0.3 #output 5.551115123125783e-17 Packages There are over 160K packages in PyPI repository I think most of us are aware of this but still.. I love this one. def superhero(x,y): return x*y , x+y, x-y, x/y , x**y mul, add, sub, div, power = superhero(7,2) print (mul, add, sub, div, power) #Output (14, 9, 5, 3, 49) Google "Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language." said Peter Norvig, director of search quality at Google, Inc. YouTube "Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers," said Cuong Do, Software Architect!!
- How can I get the source code of the Python Packages?
You can find source code on Github. Under cpython you will be able to find all the modules and python objects (written in C). You can also find which file (using __file__ attribute) on your system is used for respective module. For example math and random module, >>> import math >>> import random >>> math.__doc__ 'This module is always available. It provides access to the\nmathematical functions defined by the C standard.' >>> math.__file__ '/Users/Rajput/anaconda/lib/python2.7/lib-dynload/math.so' >>> random.__file__ '/Users/Rajput/anaconda/lib/python2.7/random.pyc' Now, you can get source code for objects written in python (not C) with inspect get source code. You can also refer Python docs for “inspect” library. >>> import inspect >>> inspect.getsourcelines(random) (['"""Random variable generators.\n', '\n', ' integers\n', ' --------\n', ' uniform within range\n', '\n', ' sequences\n', ' ---------\n', ' pick random element\n', ' pick random sample\n', : so on..
- What does // mean in python?
It’s floor division. Python docs has very nice documentation on this. Python3: Mathematical division that rounds down to nearest integer. The floor division operator is //. For example, the expression 11 // 4 evaluates to 2 in contrast to the 2.75 returned by float true division. >>> 11//4 2 >>> 11/4 2.75 Note that (-11) // 4 is -3 because that is -2.75 rounded downward. >>> -11//4 -3 >>> -11/4 -2.75 Python2: True division returns round integer in older version of python. Floor division is same. >>> 11//4 2 >>> 11/4 2 >>> -11//4 -3 >>> -11/4 -3
- What programming language is famous amongst Russians?
According to Google Trends it seems like Javascript. However, I didn’t except Python as least popular language amongst Russians. First of all, it’s little difficult to cover all the programming languages used by Russians (or used in Russia). But we can find what are the most popular programming languages in Russia and then drill down geographically. Javascript, Java, Python, PHP and C++ are the most popular languages according to Google Trends. I didn’t include Swift, Ruby, Rust, Scala, PERL etc because they are comparatively less popular to show on charts. Geographically, it looks like Javascript is most popular programming language across Russia. Did you notice the blue color in above chart? I didn’t expect this for Python. Interesting. Drilling down just for Javascript “Saint Petersburg” is the most popular location with Javascript in Russia. I haven’t heard this place before, sorry my geography is not very good.