How to automatically restart tomcat after system reboot – Ubuntu Linux

First create a file in /etc/init.d/tomcat


sudo nano  /etc/init.d/tomcat

Then add the contents below

#!/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

start() {
 sh /home/server/tomcat/bin/startup.sh # Change this location to your tomcat directory
}

stop() {
 sh /home/server/tomcat/bin/shutdown.sh # Change this location to your tomcat directory
}

case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac

Change permissions

chmod 755 /etc/init.d/tomcat

Update symlinks

update-rc.d tomcat defaults

Test, if you did everything correctly by


sudo service tomcat <stop|start|restart>

edX_MITx_6.00.1x/Problem_Set_2/Paying_the_Minimum.py

def calculate_balance(balance, annualInterestRate, monthlyPaymentRate):

    totalPaid = 0
    remainingBalance = balance

    for month in range(1,13):
        monthlyInterestRate = annualInterestRate / 12.0
        minimumMonthlyPayment = round((monthlyPaymentRate * remainingBalance),2)
        totalPaid += minimumMonthlyPayment
        monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
        remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)

        print("Month: {}".format(month))
        print("Minimum monthly payment: {}".format(minimumMonthlyPayment))
        print("Remaining Balance: {}".format(remainingBalance))

    print("Total paid: {}".format(totalPaid))
    print("Remaining Balance: {}".format(remainingBalance))


calculate_balance(balance, annualInterestRate, monthlyPaymentRate)

edX_MITx_6.00.1x/Problem_Set_2/Paying_Debt_Off_in_a_Year.py

def calculate_balance(balance, annualInterestRate):

    monthlyInterestRate = annualInterestRate / 12.0
    remainingBalance = balance
    minimumMonthlyPayment = 0

    while True:
        minimumMonthlyPayment += 10

        for _ in range(0,12):
            monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
            remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)

        if remainingBalance < 0:
            break
        else:
            remainingBalance = balance

    print("Lowest Payment: {}".format(minimumMonthlyPayment))

calculate_balance(balance, annualInterestRate)

edX_MITx_6.00.1x/Problem_Set_2/Bisection_Search.py

def calculate_balance(balance, annualInterestRate):

    monthlyInterestRate = annualInterestRate / 12.0
    lowerBound = balance / 12
    upperBound = (balance * (1+ monthlyInterestRate)**12)/12
    minimumMonthlyPayment = (upperBound + lowerBound)/2.0

    while True:
        remainingBalance = balance

        for _ in range(0,12):
            monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
            remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)

        if remainingBalance <= 0 and remainingBalance >= -0.01:
            break
        else:
            if remainingBalance > 0:
                lowerBound = minimumMonthlyPayment
            else:
                upperBound = minimumMonthlyPayment
        minimumMonthlyPayment = (upperBound + lowerBound)/2.0

    print("Lowest Payment: {}".format(round(minimumMonthlyPayment,2)))

calculate_balance(balance, annualInterestRate)

Automate Facebook Login and Status Update with Python Selenium

You can download the source code from my GitHub page
https://github.com/bikrammann/web_crawler/blob/master/Automate_Facebook_Login_and_Status_Update.py

Step 1 – Required imports


import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

Step 2 – Create Firefox object and use get method then sleep for 5 seconds


driver = webdriver.Firefox() # Firefox Browser
driver.get('http://www.facebook.com')
time.sleep(5)

To use Google Chrome with Selenium, First install Google Chrome Driver from ‘https://sites.google.com/a/chromium.org/chromedriver/’. Then replace ‘C:/chrome/chromedriver.exe’ with your chrome driver path


# Replace
driver = webdriver.Firefox() # Firefox Browser
# With
driver = webdriver.Chrome('C:/chrome/chromedriver.exe') # Chrome Browser

Step 3 – Locate email address and password field on Facebook Login Page


username = driver.find_element_by_name("email")
password = driver.find_element_by_name("pass")

Step 4 – Add values to email address and password fields

 
username.send_keys("[email protected]")
password.send_keys("password123")

Step 5 – Sleep for 1 second, then press the login button


time.sleep(1)
driver.find_element_by_id("loginbutton").click()

Step 6 – Locate the text box where it says “What’s on your mind?”


message = driver.find_element(By.XPATH, "//textarea[@name='xhpc_message']")

Step 7 – Click the text box area to get it in focus where it says “What’s on your mind?”


ActionChains(driver) \
    .key_down(Keys.CONTROL) \
    .click(message) \
    .key_up(Keys.CONTROL) \
    .perform()

Step 8 – Message for status update


message.send_keys("Ha Ha")

Step 9 – Press the post button to submit the status update


driver.find_element(By.XPATH, '//button[text()="Post"]').click()
time.sleep(5)

Step 10 – Close the browser


driver.close()