Tech
Infected

Linux, OpenSource, Programming And Hacks

Dec 9, 2017

How to install Apache2 Server in AWS EC2 Linux

Dec 9, 2017
After you have created and launched your EC2 instance you must be wondering what to do next?
if you enter your instance ip in your web browser nothing will show because you need to install a server to see some action!

It's quite simple too!

I am showing all the steps on the Ubuntu EC2 instance but it will be same on any Linux instance.


Dec 5, 2017

Place a static file in root directory in Apache Server

Dec 5, 2017
Sometimes you are required to place files like sitemaps or other files in the root location.

Specially while using frameworks like Django, It can be bit tricky to do so within the framework.. So this method will flawlessly irrespective of which framework you are using.

So, If you are running Apache server, it's quite easy

Just open up your Apache Config file and add the following line at the bottom of that file.

Alias /example.txt /path/to/example.txt

Now restart your apache server.

After this you can access the file kept at /path/to/example.txt as /example.txt

Quite easy!

In ubuntu 16.04 you can find the config file here: /etc/apache2/apache2.conf



Sep 27, 2017

How to Install and use FFmpeg in Ubuntu 16.04

Sep 27, 2017
FFmpeg is a command line tool for video and audio conversion. It can also capture from a live audio or video source. It is cross-platform, available for Linux, Mac OS X, windows and more

Install ffmpeg in Ubuntu by entering these commands in the terminal (Ctrl +Alt + T):

sudo apt update
sudo apt install ffmpeg


Sep 16, 2017

Merge Sort Program in Python

Sep 16, 2017
We will look at the Merge Sort Algorithm which is used to sort an unsorted list. The input list is divided into two parts and they are solved recursively and then they are merged.

Worst Case Time Complexity: O(n log n)

Worst Case Space Complexity: O(n)


Merge sort is a divide and conquer algorithm.

1. We are given an unsorted list of n numbers 
2. Divide it into two array of equal size
3. Again Divide those two into another two array of equal size
4. Keep on dividing it until one element is left in each array.
5. Keep Merging the sub arrays to produce sorted arrays until there is only one array remaining.. This will be our sorted array.


Aug 10, 2017

Install guvcview (webcam recorder) in ubuntu 16.04 / Linux Mint

Aug 10, 2017
Guvcview is a webcam recorder software for Linux. Its the best recorder I have come so far.
Its simple and uses less resources compared to other webcam applications like Cheese or KDE Kamoso.


It has a two window interface one for just displaying the video and the other for different controls and settings.


Aug 9, 2017

Python Program to Generate Fibonacci Series using Recursion

Aug 9, 2017
Fibonacci Series: A sequence of numbers in which each number is the sum of the previous two numbers.

First 10 Fibonacci numbers: 0,1,1,2,3,5,8,13,21,34,...

In the following python program we have used recursive function to find out the Fibonacci series up to a given term.


Jul 21, 2017

Understand Python Dictionary (key-value pair / Hash Map)

Jul 21, 2017
This tutorial is about Python dictionary which is data-structure representing  key-value pairs, you can also call it a HashMap.

One of the very common use of hashmap is finding frequency of characters in a string

Basically a dictionary is like a list but instead of integer index it can be of any type

to define a dictionary we use a key-value pair with a colon between them.

in the example below, "one" maps to 1

also note that a dictionary is un-ordered, it may not show the items in the order it was defined. 


Jul 20, 2017

Python Program for Linear Search using For loop

Jul 20, 2017
In linear search algorithm we match the element to be searched with the entire list of elements. Therefore its a brute force approach.

time complexity: O(n)

Linear Search implementation in Python:

list_of_elements = [4, 2, 8, 9, 3, 7]

x = int(input("Enter number to search: "))

found = False

for i in range(len(list_of_elements)):
 if(list_of_elements[i] == x):
  found = True
  print("%d found at %dth position"%(x,i))
  break
 
if(found == False):
 print("%d is not in list"%x)


Also check out Binary Search Algorithm for a better Time complexity O(log n)

Python Program to find frequency of Characters in a String


We will find the count of repeating characters in a string using python3.

Here we have used dictionary data structure to make a key-value pair for all alphabets and numbers, where the key is the alphabet or number and value is its count.

so this is a kind of hashing algorithm as we are mapping keys and values.

first we initialize all counts to 0

and on scanning the string we increment the count on getting the same character again.

s = input("Enter a string: ") #use raw_input for python2

alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
d1 = {letter: 0 for letter in alphabets} #initializing all alphabets, numbers to count 0

for ch in s:
 d1[ch] += 1 #incrementing count on repeat

for key in d1:
 print(key,d1[key])

Python Program to Convert Decimal to Binary


Using Loop


To convert Decimal to binary we check if the number is divisible by 2, if yes then we take a string and append 0 to and and if not then append 1 to it and divide the number by 2 and do the same again.

finally we reverse the string and print the result

numb = 121
binary = '' 

while(numb):
 if(numb % 2 == 0):
  binary += '0'
 else:
  binary += '1'
 numb = numb//2

''.join(reversed(binary))

print(binary)

Using Inbuilt function

 converting decimal to binary is quite easy

a = bit(121)
print(a[2:])

Jul 19, 2017

Create a Simple FTP Server and Client in Python

Jul 19, 2017

FTP stands for File transfer protocol, it's used to transfer files between server and client.

Here we will see how to make a simple FTP server in python and we will do some basic example tasks like listing directories of the server and uploading and downloading files to and from the server.

we will be running both the server and client on the same local machine.


Jul 18, 2017

Python Program to find HCF and LCM

Jul 18, 2017
HCF is also called Greatest Common divisor (GCD).
the HCF of two or more number is the largest of all the common factors.

for example:
if we take two numbers, 12 and 18
their common divisor are 1,2,3 and 6. therefore 6 being the biggest is the HCF of 12 and 18.


Here, we are using loop method to find HCF of two numbers. It can also be calculated using recursion.


Jul 16, 2017

Passing argument from Command-line in Python

Jul 16, 2017
Sometimes it's required to use arguments passed from cli to use in our program. Its very simple to do so..

we just need to use sys module's argv method.

import sys

print(sys.argv[1])
print(sys.argv[2])








Note that using sys.argv[0] will just give program.py, which is in fact the first argument. 

Jun 10, 2017

How to install and use package control in sublime text 3

Jun 10, 2017
Package Control is the Sublime text package manager with which we can easily search and install thousands of packages thus extending sublime text functionality.

Since Sublime text is cross platform so these instruction will work with all Operating Systems: Linux, Windows and OS X.


Jun 7, 2017

Responsive Iframe / youtube videos embed with Bootstrap

Jun 7, 2017
Hi guys, today we will see how to make iframe videos responsive using bootstrap framework.

Since the embed code for a youtube video is a iframe code, this is work for youtube videos too.

Have a look at this bootstrap link

http://getbootstrap.com/components/#responsive-embed

all you got to do is wrap your iframe code in a embed-responsive like shown below


<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>

<!-- 4:3 aspect ratio -->
<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>