The Zen of Python



Abstract
    Long time Pythoneer Tim Peters succinctly channels the BDFL's
    guiding principles for Python's design into 20 aphorisms, only 19
    of which have been written down.


The Zen of Python

  1.     Beautiful is better than ugly.
  2.     Explicit is better than implicit.
  3.     Simple is better than complex.
  4.     Complex is better than complicated.
  5.     Flat is better than nested.
  6.     Sparse is better than dense.
  7.     Readability counts.
  8.     Special cases aren't special enough to break the rules.
  9.     Although practicality beats purity.
  10.     Errors should never pass silently.
  11.     Unless explicitly silenced.
  12.     In the face of ambiguity, refuse the temptation to guess.
  13.     There should be one-- and preferably only one --obvious way to do it.
  14.     Although that way may not be obvious at first unless you're Dutch.
  15.     Now is better than never.
  16.     Although never is often better than *right* now.
  17.     If the implementation is hard to explain, it's a bad idea.
  18.     If the implementation is easy to explain, it may be a good idea.
  19.     Namespaces are one honking great idea -- let's do more of those!

The Python logo is a trademark of the Python Software Foundation


Windows 3.1 is still being used in the most important networks and systems today

I was really surprised when I read this news from zdnet :
"A Paris airport was forced to shut down earlier this month after a computer running Windows 3.1, a prehistoric operating system from 23 years ago, crashed in bad weather."
But old is not necessary bad as the article says:
 "A few years ago we did a complete analysis of our entire network. Cyber engineers found out that the system is extremely safe and extremely secure on the way it's developed,"

"Those older systems provide us some, I will say, huge safety, when it comes to some cyber issues that we currently have in the world,"


Read the full report on the below given link.

Practical sed commands

I am posting a summary of my  commands after a bit of Googling and after playing on my CentOS VM with sed.

WARNING & ADVICE: 
1. Always backup your files before playing with sed

2.The -i option in sed will replace the original file. So I recommend you run your
sed commands without the -i option first. Once you get the desired results of your sed command you
can then use the -i option.



append after <body>

sed  '/<body>/a Hello World' sample.html
sed -i  '/<body>/a Hello World' sample.html

append contents of file header-js.txt after <body>

sed -i '/<body>/ r header-js.txt' sample.html
sed -i '/<\/body>/ r footer-js.txt' sample.html

Some tests before proceeding further (tip: don't ignore the single quote)

[root@localhost mydir]# find . -name '*.html'
./sample2.html
./sample3.html
./sample.html


combine find with sed for mass modifications

find . -iname '*.html' -exec sed -i '/<body>/ r header-js.txt' '{}' \;
find . -iname '*.html' -exec sed -i '/<\/body>/ r footer-js.txt' '{}' \;

append at beginning of file

sed -i '1s/^/my script goes here\n/' file

Bandwidth vs Speed Part 2

In one of my earlier posts I wrote about bandwidth vs speed using the road and car analogy.

This post has been written by Chandan Singh Takuli from CISCO.

Too fast Too furious - who doesn't like speed, especially when we talk about the internet or network connectivity? But the real question is, which is better to have: fast speed or more bandwidth? Although these terms are inter-related, they're not same. As an internet or network user, "fast speed" means a faster rate of data communications. That sounds good, because who doesn't want a fast network connection? But when we start thinking about it as network engineers, things change a little bit as we talk about bandwidth over WAN and speed over LAN. Many network engineering friends of mine ask me, "What’s the difference?" So let’s dive into it.

The data traveling speed over media is a different concept than the speed of network we are talking about here. When we say "high speed network," we are not talking about data signals' traveling speed over network media, but we are talking about data transfer speed or rate across the network. Seem a little confusing? 

Let’s look at an example of water flowing through a tap. If a bucket can be filled with water from the tap in 5 minutes, that means we can fill 12 buckets of water in 1 hour, which gives us a rate/speed of 12 buckets/hour. Now if you double the width of the tap pipe and mouth, you will notice that the time taken to fill a single bucket is shortened by almost half and we can fill 24 buckets/hour. So our rate is doubled. (Remember that the water is flowing at the same speed inside the pipe as it was earlier.) The same concept applies in networking: the tap pipe is your link or media, the width of the pipe is your bandwidth, and the water is your data. The rate of data transfer depends on many factors, among which bandwidth is one of them.


“Bandwidth is the capacity and speed is the transfer rate”

More bandwidth does not mean more speed. Yep, you read that right. Suppose you have double the width of the tap pipe, but the water rate is still the same as it was when the tap pipe was half as wide. It will not result in any improvement in speed. When we talk about WAN links, we mostly talk about bandwidth; when we talk about LAN, we mostly talk about speed. This is because we are most limited by costly cable bandwidth over WAN rather than hardware and interface data transfer rates (or speed) over LAN.



I think the main confusion lies in the fact that we were users before we were network engineers. ISPs advertise their high bandwidth services as faster speeds, which gives users a wrong perception of bandwidth. So later on when we see things as network engineers, we get really confused. But I hope this helps clear up for you the difference between bandwidth and speed. Thanks for taking your valuable time to read this.

Cisco - Sending Syslog Messages As SNMP Traps and Informs

The following is an extract from the book Cisco IOS Cookbook,2nd edition (available online)

Problem

You want to send syslog messages as SNMP traps or informs.

Solution

You can configure the router to forward syslog messages to your network management server as SNMP traps instead of syslog packets with the following configuration commands:
Router#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#logging history informational
Router(config)#snmp-server enable traps syslog
Router(config)#snmp-server host 172.25.1.1 ORATRAP syslog
Router(config)#end
Router#
To forward syslog messages as SNMP informs, use the following configuration commands:
Router#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#logging history informational
Router(config)#snmp-server enable informs 
Router(config)#snmp-server host 172.25.1.1 informs version 2c ORATRAP syslog
Router(config)#end
Router#

Discussion

Cisco routers normally forward syslog messages via the syslog facility by using UDP port 514. However, in networks that support SNMP traffic only, Cisco routers can encapsulate their syslog messages into SNMP traps before sending them.
This feature is most useful if your network management software doesn’t support the syslog protocol. However, since routers can produce many more syslog messages than SNMP traps, we recommend using syslog when possible. 

fail2ban - a tool for linux security

From the official website of fail2ban:

Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs that show the malicious signs -- too many password failures, seeking for exploits, etc. Generally Fail2Ban is then used to update firewall rules to reject the IP addresses for a specified amount of time, although any arbitrary other action (e.g. sending an email) could also be configured. Out of the box Fail2Ban comes with filters for various services (apache, courier, ssh, etc).
Fail2Ban is able to reduce the rate of incorrect authentications attempts however it cannot eliminate the risk that weak authentication presents. Configure services to use only two factor or public/private authentication mechanisms if you really want to protect services.

Good uses of fail2ban:
Your linux server has SSH and is exposed to the internet.
The bad guys there will try to break into your system by brute-forcing/dictionary attacks.
fail2ban will block 3 unsuccessful login attempts for a certain period of time. fail2ban dynamically
updates IPTABLES rules to achieve this.
Note that it's always your responsibility to use a strong/complex password.
Neither fail2ban nor any other firewall will be able to protect you if you use simple passwords.



Demystifying the FREE command in LINUX

The free command is used in LINUX to give stats about MEMORY/SWAP usage.
Others may have blogged about this simple command before but most important is HOW to understand & interpret the results.

Beginners might be confused the first time they run the command.
A little theory on MEMORY USAGE in LINUX: “In Linux, unused memory is wasted memory”

That’s why memory is used for caching whenever possible.

I got the following nice illustration from Linux Performance and Tuning Guidelines by IBM (RedPaper)



The amount of FREE MEMORY is calculated by the formula:
FREE = free + buffers + cached

Another website dedicated completely to  the FREE command is :

What Software Defined Networking (SDN) is all about?

I have been hearing a lot on SDN for quite a long time.
There are many articles on the web which talks about it but does not adequately explain what IS SDN really. I finally decided to write on SDN from my perspective.
Let’s start with a simple example. We have CISCO Router (I like cisco).

I want to check whether my CISCO Router can ping an IP on the Internet.

To do this I will carry the following steps:
1. telnet or ssh into the router
2. ping an IP address on the internet (8.8.8.8)

If I have to do this regularly it becomes a boring thing.

What if I can write an Application which can telnet/ssh into my router, then perform a ping and check whether the ping was successful or not?

This is where SDN comes into play. SDN allows you to programmatically configure or run commands on your switches and routers.
I think that the right word for this should have been Programmable Networks (I have seen this on some networking vendor’s website)
To make SDN happen, the network vendors should provide some API or SDK to allow access to their routers and switches. In the case of CISCO, the SDK/API is called onePK.

I can see the following important benefits in using SDN:
Centralization – You can manage your routers and switches from a central point. No need to go into each router or switch.

Abstraction – We don’t need to care whether we are running CISCO, HP or BROCADE. As long as we have the SDK or API, our application is going to talk to them regardless of vendor or make.

Automation – Automation of repetitive tasks like in the example given above.

In the following last 2 sections I will dive deeper into the details and technical architecture of onePK (contents taken from Cisco’s website).

Cisco's One Platform Kit (onePK)

onePK is an element within Cisco's software defined networking (SDN) strategy. onePK is an easy-to-use toolkit for development, automation, rapid service creation, and more.
Build or extend applications from your routers and switches to servers and new business platforms. Automate current services or create new ones on demand, when and where you need them and faster 
than ever. onePK makes your network more powerful and flexible while giving you the control you need. Users also have access to an all-in-one development environment that includes simulated network elements.

Designed for Flexibility 

onePK has the capability to:
·         Integrate with PyCharm, PyDev, Eclipse, IDLE, NetBeans, and more
·         Support commonly used languages, including C, Java, and Python
·         Run on any server or directly on your network elements
·         Use APIs to extend, modify, and tailor your network to your business needs
·         Tie in easily with third-party tools and workflows

 

Unlimited Possibilities

Use onePK for new application-enablement, service automation, and more. With onePK you can orchestrate and enhance your network elements. You can also:
·         Customize route logic
·         Create flow-based services such as quality of service (QoS)
·         Adapt applications for changing network conditions such as bandwidth
·         Automate workflows spanning multiple devices
·         Empower management applications with new information

Technical Overview


At a high level, the onePK architecture is composed of three major elements:
·         the presentation layer
·         the onePK API infrastructure
·         the communication channel
These elements combine to provide a consistent and adaptable architecture that enables multiple languages and multiple deployment models for applications that work across the network.

Presentation Layer: What the Programmer Sees

The presentation layer consists of the API libraries that programmers can use within their applications. With onePK, application programmers get a universal network programming toolkit. The onePK Libraries are initially available in C, Java, and Python. The libraries were designed with very few dependencies, so it can be easily integrated with existing tools and development requirements.

onePK API Infrastructure: One API for Many Devices

The API Infrastructure provides access to functions that are internal to a router or switch. One of its primary values is that it abstracts underlying differences between operating systems and platforms. For example, if your application uses a onePK function call to read interface statistics, that same function call will work across all Cisco networking software platforms (Cisco IOS® Software, Cisco IOS XR Software, Cisco IOS XE Software, and Cisco NX-OS Software).

Communication Channel: Security and Flexibility

The communication model provides a fast, safe, extensible channel between the application and the network element. (Applications are required to authenticate before being allowed to access the functions of the API Infrastructure layer.)

SOURCE & FURTHER REFERENCE:

Play all file formats in Windows Media Player

Windows 8 Codec Pack is a FREE software which allows you to play lots of file formats such as flv and mkv in your Windows Media Player.

The name of the software is misleading I think…it supports not only windows 8/8.1 but also 7, Vista, XP, 2000, 2008, & 2003.

The software is compatible with Microsoft Windows Media Player 9, 10, 11, & 12.


Now you can relax and play all your files in Windows Media Player. You don’t need any separate player for playing video files such as flv and mkv.


Compression types that you will be able to play include:x265 | h.265 | HEVC | 10bit x264 | x264| h.264 | AVCHD | AVC | DivX | XviD | MP4 | MPEG4 | MPEG2 and many more.

File types you will be able to play include:.bdmv | .evo | .hevc | .mkv | .avi | .flv | .webm | .mp4 | .ts | .m4v | .m4a | .ogm | .ac3 | .dts | .flac | .ape | .aac | .ogg | .ofr | .mpc | .3gp and many more.

Codec's Explained:A codec is a piece of software on either a device or computer capable of encoding and/or decoding video and/or audio data from files, streams and broadcasts. The word Codec is a portmanteau of 'compressor-decompressor'


Official Website of Windows 8 Codec : http://www.windows8codecs.com

Today March 31 is World Backup Day

The world backup day is an initiative to make people aware on the importance of backup.


The official website of World Backup Day is at http://www.worldbackupday.com/en/



Your hard disk, smartphone or laptop may not be always loyal to you.
Computers get infected with viruses, smartphones are lost and your hard disk gets fried.

“Remember backup is a continuous process not a one off process. You must always backup your data not only on 31 March.”

WHAT IS BACKUP?
Let’s quote exactly from the website:

A backup is a second copy of all your important files — for example, your family photos, home videos, documents and emails.
Instead of storing it all in one place (like your computer), you keep another copy of everything somewhere safe.

WHY SHOULD YOU BACKUP ?
Your data is valuable.
It’s important because you might need it for personal and professional reasons.
Your ebooks, your final year dissertation, your source codes, your customer list, your child’s photos, etc


SOME STATISTICS


SO HOW DO I BACKUP?
Some people think of backup as a complicated process and believe that they just can’t do it.
While some believe they need expensive software.

The truth is:
You backup your files on an External Drive or somewhere on the Internet (Example Google Drive, DropBox).

Please note that am not endorsing any service provider am just giving some examples. There are other cloud backup providers as well.

1.Buy an External Drive (USB)
2.Connect it to your computer.
3.Copy all your important files to the External Drive (Right Click > Select Copy, then Paste on the External Drive)  or Copy all your important files to a Cloud backup Provider.
4.Congrats. That’s the simplest backup according to me.

SOME TIPS
1.Always keep your backup away in a safe place.
2.Don’t forget to backup
3.Check that your backup is OK

DISCLAIMER: Everything in this post is for informational purpose only. I am not responsible for any loss of data through improper backup procedures.

Remember: Your data won’t make jokes – It will be for real if it’s lost. So Backup !


Best practices for virtual machine snapshots in the VMware environment (KB1025279)

The following has been taken from VMware Knowledge Base - KB 1025279

  • Snapshots are not backups. A snapshot file is only a change log of the original virtual disk. Therefore, do not rely on it as a direct backup process. The virtual machine is running on the most current snapshot, not the original vmdk disk files.
  • Snapshots are not complete copies of the original vmdk disk files. Taking a snapshot does not create a complete copy of the original vmdk disk file, rather it only copies the delta disks. The change log in the snapshot file combines with the original disk files to make up the current state of the virtual machine. If the base disks are deleted, the snapshot files are useless.
  • Delta files can grow to the same size as the original base disk file, which is why the provisioned storage size of a virtual machine increases by an amount up to the original size of the virtual machine multiplied by the number of snapshots on the virtual machine.
  • The maximum supported amount of snapshots in a chain is 32. However, VMware recommends that you use only 2-3 snapshots in a chain.
  • Use no single snapshot for more than 24-72 hours. Snapshots should not be maintained over long periods of time for application or Virtual Machine version control purposes.

    • This prevents snapshots from growing so large as to cause issues when deleting/committing them to the original virtual machine disks. Take the snapshot, make the changes to the virtual machine, and delete/commit the snapshot as soon as you have verified the proper working state of the virtual machine.
    • Be especially diligent with snapshot use on high-transaction virtual machines such as email and database servers. These snapshots can very quickly grow in size, filling datastore space. Commit snapshots on these virtual machines as soon as you have verified the proper working state of the process you are testing.


  • If using a third party product that takes advantage of snapshots (such as virtual machine backup software), regularly monitor systems configured for backups to ensure that no snapshots remain active for extensive periods of time.




InstalledDriversList Tool - View Installed Drivers

About 5 minutes ago I found a nice freeware tool (InstalledDriversList) which can be used to view the installed drivers on your PC.

From the official website of InstalledDriversList:

InstalledDriversList is a simple tool for Windows that lists all device drivers that are currently installed on your system. For every device driver, the following information is displayed: Driver Name, Display Name, Description, Startup Type, Driver type, Driver Group, Filename, File Size, Modified/Created Time of the driver file, and version information of the driver file. If the driver is currently running on Windows kernel, the following information is also displayed: Base Memory Address, End Address, Memory Size, and Load Count.


This tool may be used to identify which drivers are causing trouble on Windows.

Again quoting the original text:

  • Green Icon - The driver is running on Windows kernel.
  • Yellow Icon - The driver is not running on Windows kernel.
  • Red Icon - The driver is not running on Windows kernel, but it should be loaded automatically when Windows starts. When you see a red icon, it's possible that something is wrong with the driver. Be aware that on Windows 8, there are 2 drivers of the operating system that are normally displayed with red icon.

Visit http://www.nirsoft.net/utils/installed_drivers_list.html  for more information on this tool.

Murphy's computers laws

I found the following “laws” from Murphy's computers laws.  I selected the best ones which I think are true, funny and interesting.
Read them and have a nice day.

If a program is useless, it will have to be documented 
Bugs will appear in one part of a working program when another 'unrelated' part is modified.
Adding manpower to a late software project makes it later.
A working program is one that has only unobserved bugs.
No matter how many resources you have, it is never enough.
Any cool program always requires more memory than you have.
When you finally buy enough memory, you will not have enough disk space.
Disks are always full. It is futile to try to get more disk space. Data expands to fill any void.
If a program actually fits in memory and has enough disk space, it is guaranteed to crash.If such a program has not crashed yet, it is waiting for a critical moment before it crashes. 
No matter how good of a deal you get on computer components, the price will always drop immediately after the purchase.
The hard drive on your computer will only crash when it contains vital information that has not been backed up.
Whenever you need a crucial file from the server, the network will be down. Whenever you need a crucial file from your hard drive, your computer will crash. 
E-mailed tasking will always come just before you log off. 
The faster you need a hardcopy, the more people will be using the only office printer.
 A patch is a piece of software which replaces old bugs with new bugs. 
The probability of forgetting your password is directly proportional to the frequency of changing it. The longer it takes to download a program the more likely it won't run.
Failure is not an option, it's included with the software.
A program is good when it's bug free - which is impossible.
The only program that runs perfectly every time, is a virus
The troubleshooting guide contains the answer to every problem except yours.
The boss will always come to your workspace when you accidentally open an adult link


The full list can be read from murphys-laws.com website at http://www.murphys-laws.com/murphy/murphy-computer.html