Skip to main content

Posts

Showing posts with the label chamodh

Create a URL Shortener app with Python and Django Easily. Part-1

Create a URL Shortener app with Django  Part 1. How to set up and activate the virtual environment & installing Django. READ PART 2:   https://blogofchamodh.blogspot.com/2022/07/create-url-shortener-app-with-python-part2.html READ PART 3:  https://blogofchamodh.blogspot.com/2022/08/create-url-shortener-app-with-python.html As promised in the previous post ( How to generate a random string with Python. ), I am starting a post series on creating a URL Shortener app with Django and Python. Photo by LinkedIn Sales Solutions on Unsplash Getting Started INFO: I am using GitBash CLI and if anyone uses it please download and install it following the link below.  https://gitforwindows.org/ First, we have to create a virtual environment so that we can isolate our project. Even if there are too many ways to do it,  I am going to use virtualenv to do it. To create a virtual environment, follow the instructions below. 1. Create a new folder. To make things easier, we ...

Flip a coin million times w/ Python

Photo by ZSun Fu on Unsplash Welcome everyone to my blog. I could not write a new blog post for the last year because of my heavy work schedule. So I thought to write an article on a recent project done by me. Let's get started. Imagine that you want to flip a coin. Perhaps you don't need a complex python script to flip and find a result but what if you're going to flip a coin 2 million times and check the results. Then you have to invite Python to do all the hard work for you. If you are not interested to dive deep, just go ahead and check my project on Github. And also don't forget to follow my profile for the latest fun projects. and if you are a Python expert please feel free to fork.  🍴🍴 Link: https://github.com/chamodhk/coin-flipper Import the libraries you want! If you aren't using a GUI all you have to import is the random module. If you are an expert you don't have to import it too because you can write a function to get the random part done. im...

Generate all possible phone numbers with Python | Generates Crores of Phone Numbers within minutes.

Recently,  I learned about itertools in python. Especially, about the functions permutations, combinations, and products and I tried to make a script that generates all phone numbers in our country. I bet your phone number is too on the list. let the hack begin!!! First, you need to install itertools in your computer  Simply open your terminal and type                sudo apt-get  install  -y python-more- itertools Then Write the code below from itertools import product file_name = "phonebook.txt" phonebook = open (file_name, 'a' ) prefixes = [ '+9471' ] product_a = product([ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' ], [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' ], [ '1' , '2' , '3' , '4' , '5...

Create a simple Digital Clock for Your website with Javascript.

Create a Unordered list in HTML You have to create a unordered list using <ul> and</ul> tags in your HTML file. And inside it include 3 <li> elements for Hours, Minutes and Seconds . ul > < li id = 'hours' ></ li > < li id = 'minutes' ></ li > < li id = 'seconds' ></ li > </ ul > Write The Script With Javascript Then you can place your script inside head tags. < script > function newfunc () { a = new Date (); day = "AM" hours = a . getHours (); if ( hours > 12 ){ hours = hours - 12 ; day = 'PM' } else { } document . getElementById ( "hours" ). innerHTML = ( "0" + hours ). slice (- 2 )+ ':' ; document . getElementById ( "minutes" ). innerHTML = ( "0" + a . getMinutes ()). sli...

Version 1.1 of RESULTANT FINDER is released!

A few weeks before I released my first version of Resultant finder which helps you to calculate the resultant of two vectors using a formula. When I wanted to find the resultant of a big number of vectors I built software with a different logic to find the size and its direction. In this version: the software divides the vector into two components along the y-axis and x-axis and lists them into two lists. after the user finished entering inputs; Python calculates the sum of all x components and y components and  calculate the results of all vectors given with the support of the Pythagoras Theorem and Triangle of vectors. As the vector triangle is right angled we can simply calculate the tan ratio of the angle, between the resultant and x-axis t hat is all here is the code: https://github.com/ChamodhNethsara/resultant/blob/main/resultant.py Hope You Like it :-) Happy coding Kavindu Chamodh Nethsara   

Find the Resultant vector of two Vectors With PYTHON!!

NEW ARTICLE:  How to Find the resultant of multiple vectors with Python! Using Python We can do many complex calculations. I learned how to calculate Resultant Vector using a formula with its size and direction in my Physics class. Then, I simply developed a CLI software to calculate the resultant of given two vectors Hope you like it :>) Follow me... Step :1 You need to install python on your computer. No matter what the operating system is you can find the ideal version of python from the official website of Python org And you will need a code editor like VS code and can download it with a simple Google search. (Hope you hate the first step Haha ) Step 2: we use the math module to calculate our resultant vector. The method I used as follows math.radians() : converts degrees to radians math.degrees() : converts radians to degrees math.sqrt()  : find the square root of a number math.atan() :find the tan inverse Step 3: the formula I used to calculate the size of the resulta...