Category Archives: Tech and Programming

Solving 5 mathematical Conjecture puzzles with Python code

There are many complex math puzzles that have stumped mathematicians and puzzle enthusiasts alike. Here are 5 mathematical conjecture puzzles that I have attempted to explain and solve using Python:

The Collatz Conjecture

The Collatz conjecture is a mathematical problem that involves a sequence of positive integers that are generated according to a specific rule. The conjecture states that for any positive integer, the sequence will eventually reach the number 1, regardless of the starting number.

Here is a simple Python function that generates the Collatz sequence for a given starting number:

def collatz(n):
    while n != 1:
        print(n, end=", ")
        if n % 2 == 0:
            n = n // 2
        else:
            n = 3*n + 1
    print(1)

To use this function, you would simply call it with a positive integer as the argument, like this:

collatz(10)

This would output the following sequence:

10, 5, 16, 8, 4, 2, 1

The conjecture has been verified for many starting numbers, but it has not been proven for all positive integers. Despite much effort, a general proof or counterexample has not yet been found.

Continue reading Solving 5 mathematical Conjecture puzzles with Python code

Python code to assess carbon contribution on surface temperature

To calculate the contribution of carbon dioxide (CO2) to the current surface temperature of the Earth, we will need to use a combination of physical principles and data on atmospheric concentrations of CO2 and other greenhouse gases. In this article we will try and understand the basics of calculating the carbon concentration affecting the surface temperature using Python programming. But, before let’s do a general outline of the steps we can follow:

  1. Determine the current atmospheric concentrations of CO2 and other greenhouse gases. We can find this information from various sources, including scientific papers, government agencies, and online databases.
  2. Calculate the global mean surface temperature of the Earth. This can be done by using temperature data from a large number of locations around the globe and averaging them.
  3. Determine the amount of energy being absorbed by the Earth’s atmosphere from the sun. This can be calculated using the solar constant, which is the amount of solar energy received by the Earth per unit area per unit time, and the Earth’s albedo, which is the fraction of solar energy reflected by the Earth’s surface and atmosphere.
  4. Calculate the amount of energy being emitted by the Earth back into space. This can be done using the Stefan-Boltzmann law, which states that the rate at which a blackbody (such as the Earth) emits energy is proportional to the fourth power of its temperature.
  5. Calculate the difference between the energy absorbed by the Earth and the energy emitted back into space. This will give us the net energy balance of the Earth, which is the excess energy that is trapped in the Earth’s atmosphere.
  6. Determine the contribution of CO2 and other greenhouse gases to the net energy balance. This can be done by using the absorption and emission spectra of these gases, which describe how they absorb and emit energy at different wavelengths. We can then calculate the amount of energy absorbed and emitted by each gas and add them up to determine the total contribution of all the gases.
  7. Calculate the warming effect of the gases by comparing the net energy balance with and without the contribution of the gases. The difference between the two will give us the warming effect of the gases.

This is a simplified version of the process that scientists use to calculate the warming effect of greenhouse gases. In practice, the calculations are more complex and may involve using advanced computer models and data from a wide range of sources.

Continue reading Python code to assess carbon contribution on surface temperature

Indian Traditional mathematics equations in Python Code

Indian mathematics has a rich history dating back thousands of years. Some of the key contributions of traditional Indian mathematics include the development of the decimal place-value system and the concept of zero, as well as the development of various equations, trigonometry and algebra. In this article we will attempt to reproduce these equations using Python code.

The Pythagorean theorem

The Pythagorean theorem which states that in a right triangle, the square of the length of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides:

a^2 + b^2 = c^2
Continue reading Indian Traditional mathematics equations in Python Code

High Level understanding of measuring wind speed with Python

In the following tutorial, you will learn how to use Python to infer wind speed based on anemometer data. Anemometers are devices that are used to measure wind speed and are connected to computers and other devices via USB connections. For instance, you can run a Python script to calculate the average wind speed over a given period of time. This is done by reading the anemometer data into a dataframe and then performing statistical calculations on the values.

Here is an example of how this could be done using Python:

import serial

# Open the serial port where the anemometer is connected
ser = serial.Serial('/dev/ttyUSB0', 9600)

# Read a line of data from the anemometer
line = ser.readline()

# Split the line into separate values
values = line.split(',')

# The wind speed is the first value in the list
wind_speed = float(values[0])

# Print the wind speed
print(wind_speed)

# Close the serial port
ser.close()

This code assumes that the anemometer is connected to a USB port on the computer and is sending data in the form of a comma-separated string. The wind speed is the first value in the string, and it is converted to a float so that it can be used in calculations.

Continue reading High Level understanding of measuring wind speed with Python

AIML in Public Safety & Disaster Scenario

The use of artificial intelligence and Machine Learning (AIML) systems can be an effective method for automating disaster response, but they need to be properly trained to interpret disasters for them to be useful.

Guest talk at the Indian Institute of Technology, Guwahati zoom-live session on the launch of the 2022 batch of AIML certification, addressed the questions like;

  1. How AIML is helping this world to be a safer planet for a living?
  2. How big is this disaster problem?
  3. How humans have become intelligent over years by using Artificial Intelligence and Machine Learning to handle Disasters?
  4. How the wildfire in technologically advanced countries is getting handled or maturing to get ready to handle?
  5. How drones are helping to fight disasters?
IIT-Guwahati Talk: Artificial Intelligence & Machine Learning in Public Safety & Disaster Scenario
Continue reading AIML in Public Safety & Disaster Scenario

Python Password validator complying GDPR, ISO 27001/27002, PCI DSS, and NIST 800-53

There are several requirements that a password validator should meet in order to be compliant with various standards such as GDPR, ISO 27001/27002, PCI DSS, and NIST 800-53. Here are some general guidelines for creating a strong and compliant password:

  1. Length: A password should be at least 8 characters long. Some standards may require longer passwords, up to 12 or 16 characters.
  2. Complexity: A password should contain a mix of uppercase and lowercase letters, numbers, and special characters. Avoid using easily guessable information such as your name, address, or common words.
  3. Uniqueness: Each password should be unique and not used for any other accounts.
  4. Change frequency: It is recommended to change passwords at regular intervals, such as every 90 days or every year. Some standards may require more frequent changes.
  5. Storage: Passwords should be stored in a secure, encrypted format. They should not be written down or shared with anyone.
  6. Multi-factor authentication: It is recommended to use multi-factor authentication (MFA) in addition to a password, such as a code sent to your phone or a biometric factor like a fingerprint.
Continue reading Python Password validator complying GDPR, ISO 27001/27002, PCI DSS, and NIST 800-53

Configuring redirections with apache htaccess for www, non-www, http and https | All patterns

There could be 10 different reasons to have a specific pattern of domain name considering brand value, technical architecture, personal liking, search engine optimizations, etc. And you might encounter a requirement of http redirections where you may need to do add/edit the htaccess of your webserver.

 Understand, this blog is just to help you achieve the results and not about explaining each bit of code. 

Prerequisites

  • This tutorial assumes that you have enough technical knowledge about setting up a website on apache.
  • If you are using Linux make sure you have superuser privileges, i.e. sudo or root, on the server that is running Apache.
  • It is assumed that you have Apache installed.
  • You must be able to add records to the DNS that is managing your domain. If you do not already have a domain, you may purchase one from a domain registrar, and manage it with the registrar’s DNS.
  • Enable Rewrite Module: In order to perform the 301 redirect, we will use the Apache mod_rewrite, or Rewrite, module. Doing so will ensure that your users can access your site with or without the www. prefix, and be redirected to the domain that you prefer.
  • Created an .htaccess file on the web server root folder for http redirections.

Apache htaccess configurations for http redirections from www to non-www and vice-versa with https options on/off.

If you are reading this post, it means you are technical enough to understand about this topic. So let me quickly jump to specific solutions to different requirements:

Condition 1: To get www without https

Example:

  1. http://example.com ⇨ http://www.example.com
  2. https://example.com ⇨ http://www.example.com
  3. https://www.example.com http://www.example.com

Result: http://www.example.com

Continue reading Configuring redirections with apache htaccess for www, non-www, http and https | All patterns

Post Launch Challenges: A guide for startup companies to minimize risk with server infrastructure plan

World knows how to be cruel and becomes more cruel when you have no answers in adverse situations. For product companies, this is no myth. You should consider this article as a guide for startup companies running internet business who face a lot of post launch risk due to inefficient server infrastructure plan.

NOTE: This article does not belong to big data administrators and developers who are working with distributed systems, Hadoop, Hbase or other such technologies.

Businesses run with high inspirations and on huge costs. Even the smaller setups need to maintain a lot of trust and breakthrough service so that customers can be pleased. When a business is starting on pre-defined rules everything goes smoothly as planned. However one’s the business multiplies or let’s say the traffic on website or application increases, uncertainties creates doom days for stakeholders.

If you are reading this article I assume you to be a business owner or a product manager or a product developer who knows how an internet business works and the meaning of an internet product.

Continue reading Post Launch Challenges: A guide for startup companies to minimize risk with server infrastructure plan

Setting up Python framework Django and no-sql database Cassandra for web development – Step by Step Tutorial

Setting up environment for God sake

Guys, I will be blunt. I am not teaching 100s of available ways to install Python, Django and Cassandra and to develop applications around it. My development environment is just defined below and everything is practiced around it. Because there are many ways to do things using these languages I have chosen the favorites that made me think is good for beginners to start with.

  • OS: UBUNTU 14.+ or 15.+
  • Python: 2.7
  • Level: Beginners Guide
  • Type: Getting Started
  • IDE: Brackets 1.5 (Experimenting with this one these days)
  • Environment: VirtualEnv 13.1.2
  • Framework: Django 1.8.6

 This content has been updated and tested with the versions defined above. I have been periodically updating the content to match the pace of new releases. 

Continue reading Setting up Python framework Django and no-sql database Cassandra for web development – Step by Step Tutorial

50 Python Libraries and Add-ons programmers cannot live without

There are plenty of Python libraries who really counts in projects and dramatically help-out programmers to reach a standard maturity level.

The list below is with my over all experience with python. I fond these 50 libraries to be basic for a programmer to use and build efficient applications. Many of these are now industry standards, and others are some nice geek stuffs. Just explore all of these and I am sure if you have these on your tips than you are among the best developers out there. And yeah you are fabulously costly priced 😀

Continue reading 50 Python Libraries and Add-ons programmers cannot live without