Write your first python module
If you are planning to build a mid to enterprise size project/product then you should consider object oriented coding practice. This benefits in many ways. For eg, your code remains tidy and you can reuse components of your code in other projects. Module is essentially a collection of several classes and class functions. These functions […]
Python filter function
This is an interesting feature in python. Suppose you have a list of items and you want to apply quick filters such as “greater than x”, “less than x”, “above average”, “below average” on list items, then filter() method makes it quite handy. Typical syntax of filter function is like filter(some_func_name, list_of_items) You can also […]
Python reduce function
This is an interesting short cut function when you want to process list items recursively. This function takes two arguments in as input, one function name that you want to apply on list and second the list itself. In python3 reduce is available in func_tools module. Typical syntax to invoke this is reduce(function_name, list_of_items) and […]
Python map function
Think of a situation, where you want to perform same operation on a group of objects. For eg, you want to run same commands on a family of network devices. Traditionally, to achieve this you have to iterate device objects one by one and then apply required function to run commands on devices. In python, […]
Lambda functions in python
Traditionally, most programmers use functions and macros to write re-usable routines. In Python there is a simple way write quick one liner functions which can be used throughout your program. Lambda functions are also known as anonymous functions. Syntax of lambda function is like: Here are few examples. A few more practical use cases to […]
Python Netmiko – network automation
If you have been using expect on Linux or paramiko with python, then you will feel the ease of programing with netmiko. Netmiko really simplifies ssh session management on network devices. To install netmiko use pip3 or pip installer Netmiko currently supports many network operating systems, including Cisco IOS variants, JunOS, Linux etc. You can […]
Apache access and error logs in Fluentd
To parse and add Apache2 access and error logs add this section to your /etc/td-agent/td-agent.conf Fluend config file Restart td-agent Now, access apache web pages and you will see logs going into elastic database. In Kibana management, create new index pattern like apache-* to visualize apache logs in kibana
Getting CCTV streams in Python
I have basic CCTV setup at home with two bullet cameras on 4 channel hikvision DVR. Hikvision DVR does not offers face detection, vehicle detection or any other image processing functions with basic cameras. I thought it will be worth to get CCTV feeds in python and then do try out face detection etc on […]
Programming nodemcu on micropython firmware
NodeMCU board is based on ESP8266 wifi chip. It is an affordable board for IoT, robotics and other embedded programming projects. So far I have used NodeMCU with Arduino to build IoT relays, IoT doorbell and program a number of sensors. NodeMCU and micropython together make embedded programming really simple and easy. To start with, […]
Monitor power usage and other parameters of Linux server
This weekend I decided to exchange my 8 year old i3 laptop with a desktop. I was offered an HP elite 8300 small form factor desktop in exchange of laptop and 7000 Rs. So far I was using raspberry pi 3 for hosting web based apps and running some other programs 24×7. I mainly opted […]