Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download and install docker for your platform.

Running Drupal in Docker

Drupal requires MySql to function. So before deploying docker you need to deploy a docker instance of MySql/MariaDB. To deploy a MySql Instance on Docker issue the following command

docker run --name mysql -e MYSQL_ROOT_PASSWORD=yourpassword -p 3306:3306 -d mysql:latest

This will deploy the MySql Docker instance

Deploy Drupal Container

docker run --name drupal --link MYSQL-NAME:mysql -p 8000:80 -e MYSQL_USER=root -e MYSQL_PASSWORD=yourpassword -d drupal

This will deploy the Drupal container. Match the MySql credentials to the above command. You can visit the container by visiting http://localhost:8000 or http://YOUR_IP_ADDRESS:8000

In Drupal during installation go to advanced options in Database setup and set the host to the container name of mysql, which in the above case is mysql

Explanation of switches

--name=the name of the instance. You can give it any name you want
-d Run in detached mode
-p Map ports of docker container to local ports
-e Set environment Variables

If you already have images of mysql and drupal

Create a Network by issuing the following command

docker network create drupalnet
docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 --net=netw -d mysql:latest
docker run --name drupal -p 8000:80 --net=netw -d drupal:latest

This will create a Network and connect the two containers together.

For learning more about Drupal Visit Getting Started with Drupal. For more information on Drupal on Docker visit Drupal in docker hub.

Hope you find it useful

test table

Pos Team Matches Points Rating
1 India 29 3434 118
2 Australia 30 3534 118
3 England 43 4941 115
4 South Africa 21 2182 104
5 New Zealand 23 2291 100
6 Pakistan 25 2304 92
7 Sri Lanka 27 2123 79
8 West Indies 28 2154 77
9 Bangladesh 19 873 46
10 Zimbabwe 7 223 32

Apache Rewrite What It Is and How to Use It

Apache Rewrite: What It Is and How to Use It

If you have been working with Apache web server for a while, you may have heard of the term "rewrite". Apache rewrite is a powerful module that allows you to manipulate URLs as they are requested by clients, and it can be used for a variety of purposes such as redirecting old URLs to new ones, enforcing SSL on certain pages, or even customizing URLs for SEO purposes.

In this post, we will go over what Apache rewrite is, how it works, and provide examples of common use cases.

What is Apache Rewrite?

Apache rewrite is a module that is included with the Apache web server. It is used to manipulate URLs as they are requested by clients. It can be used to redirect URLs, add or remove query string parameters, and even modify the contents of a URL.

How Does Apache Rewrite Work?

Apache rewrite works by using regular expressions to match the requested URL against a set of rules. These rules are defined in a configuration file, usually called ".htaccess", which is placed in the root directory of your website.

When a client requests a URL, Apache checks the rules in the .htaccess file to see if any of them apply to the requested URL. If a rule matches, Apache applies the rewrite and sends the new URL back to the client.

Common Use Cases for Apache Rewrite

Redirecting Old URLs to New Ones

One of the most common use cases for Apache rewrite is to redirect old URLs to new ones. This can be useful if you have changed the structure of your website and want to ensure that users can still find the content they are looking for.

For example, let's say you had a page on your website with the URL "http://www.example.com/products.php?id=123". You have now changed the structure of your website, and the same page is now located at "http://www.example.com/products/123". To redirect users who have bookmarked the old URL, you can use the following rule in your .htaccess file:



 ZEENUX

This rule will match any URL that contains the query string parameter "id=123" and redirect it to the new URL "/products/123".

Enforcing SSL on Certain Pages

If you have pages on your website that require a secure connection, you can use Apache rewrite to enforce SSL on those pages. This can be useful if you are collecting sensitive information from users, such as credit card numbers or personal information.

To enforce SSL on a specific page, you can use the following rule in your .htaccess file:
This rule will match any URL that contains the string "/checkout" and redirect it to the same URL with "https://" instead of "http://".

Customizing URLs for SEO Purposes

Apache rewrite can also be used to customize URLs for SEO purposes. For example, you may want to remove query string parameters from your URLs, or add keywords to your URLs to improve search engine rankings.

To remove query string parameters from your URLs, you can use the following rule:

This rule will match any URL that does not contain a query string and remove it.

 

Permanent Revolution Theory

The theory of Permanent Revolution is a key aspect of Marxist thought that was developed by Leon Trotsky. It challenges the traditional Marxist belief that socialist revolution could only occur in advanced capitalist countries, such as England, France, or Germany. Instead, Trotsky argued that socialist revolution could also occur in underdeveloped countries, such as Russia, where the capitalist class was weak and the working class was large.


First developed during the Russian Revolution of 1905. Trotsky, who played a leading role in the revolution, began to question the traditional Marxist view that socialist revolution could only occur in advanced capitalist countries. He believed that the weakness of the capitalist class in Russia meant that the working class would have to carry out a socialist revolution, rather than a bourgeois revolution, which was necessary to create the conditions for socialism in advanced capitalist countries.


In his 1906 pamphlet "Results and Prospects," Trotsky argued that the working class in underdeveloped countries could not rely on the bourgeoisie to carry out a bourgeois revolution. Instead, the working class would have to carry out a socialist revolution, which would involve the expropriation of the capitalist class and the establishment of a workers' state.


The theory of Permanent Revolution challenged the view of Vladimir Lenin, who believed that socialist revolution could only occur after a bourgeois revolution had taken place in underdeveloped countries. Lenin argued that the working class in underdeveloped countries had to first carry out a bourgeois revolution, which would create the conditions for socialism. Only after the bourgeois revolution was completed could the working class carry out a socialist revolution.


Despite his disagreements with Trotsky, Lenin recognized the significance of the theory of Permanent Revolution. He wrote that "the idea of permanent revolution… contains a great deal of indisputable truth" and that "it is in essence an anticipation of the further development of the revolution."


Trotsky continued to develop the theory of Permanent Revolution over time. In 1915, he argued that the First World War had created the conditions for socialist revolution. He claimed that the war had exposed the contradictions of capitalism and had created a revolutionary situation in which the working class could carry out a socialist revolution.


In 1920, Trotsky published "Terrorism and Communism," in which he laid out his ideas on the stages theory of Permanent Revolution. According to the stages theory, the working class would first carry out a bourgeois revolution, which would expropriate the feudal and capitalist classes and establish a democratic republic. The working class would then use this democratic republic to carry out socialist measures, such as the nationalization of the means of production and the establishment of workers' control over the economy.


The theory of Permanent Revolution had a significant impact on the history of socialist thought. It challenged the traditional Marxist view that socialist revolution could only occur in advanced capitalist countries. It argued that the working class in underdeveloped countries could play a leading role in the struggle for socialism. The theory of Permanent Revolution remains an important aspect of Marxist theory and continues to be debated and developed by Marxist thinkers today.


Importance of Theory of Permanent Revolution

The theory of Permanent Revolution is a significant aspect of Marxist thought that has had a lasting impact on socialist theory and practice. It challenged the traditional Marxist view that socialist revolution could only occur in advanced capitalist countries, and instead argued that the working class in underdeveloped countries could play a leading role in the struggle for socialism.


One of the key contributions of the theory of Permanent Revolution was its recognition that the working class in underdeveloped countries could not rely on the bourgeoisie to carry out a bourgeois revolution. Instead, the working class would have to carry out a socialist revolution, which would involve the expropriation of the capitalist class and the establishment of a workers' state. This was a significant departure from the traditional Marxist view, which saw the bourgeois revolution as a necessary precondition for socialist revolution.


The theory of Permanent Revolution also challenged the idea that socialist revolution could only occur after a period of capitalist development had taken place. Trotsky argued that the contradictions of capitalism were present in all societies, regardless of their level of development. He believed that the working class could use these contradictions to create a revolutionary situation, regardless of the level of capitalist development in their society.


The theory of Permanent Revolution had a significant impact on the history of socialist thought and practice. It played a key role in the Russian Revolution of 1917, which saw the working class take power and establish a socialist state. Trotsky's ideas also influenced the development of socialist movements in other parts of the world, such as China, Cuba, and Vietnam.


The theory of Permanent Revolution also had implications for the way that socialist revolution was understood. It challenged the traditional view that socialist revolution was a one-time event that occurred after a period of capitalist development. Instead, it argued that socialist revolution was a process that involved the transformation of social relations and the establishment of a new mode of production.


Finally, the theory of Permanent Revolution remains an important aspect of Marxist theory and continues to be debated and developed by Marxist thinkers today. It offers a powerful critique of traditional Marxist thought and provides an alternative vision of socialist revolution that emphasizes the importance of the working class and the struggle for socialism in underdeveloped countries.





Redirect to public directory laravel .htaccess

Redirect all requests to laravel public directory

Create a file .htaccess in the root of the website. For e.g http://www.example.com points to /home/example/public_html then create the .htaccess file in the /home/example/public_html directory and paste the above code in it. This will redirect all requests to the public folder of Laravel

Classification in Machine Learning

Basic Concepts of Classification in Machine Learning


Classifier: An algorithm to map the input data to a specific category

Classification Model: Predicts or draws a conclusion to the input data given for training. It will predict the class or category for the data

Feature: Individual measurable property of the phenomenon being observed


Types of Classification

  • Binary Classification
  • Multi-class Classification

 

Binary Classification: is a type of Classification with two outcomes. I.e a Binary outcome, true/false, 0/1 etc


Multi-class Classification: Classification with more then two classes. Each sample is only assigned to a single label or target. 


Multi-label classification: Each sample is assigned to a set of labels or targets.

Initialize: Used to design the classifier for classification.

Train: Used to fit the model for training the train label X and label Y

Predict: Predict the target for an unlabelled Y

Evaluate: Evaluate the model

 

Types of Learners

Lazy Learner: Stores the training data and wait until testing data is provided. It has more time to predict then eager learning. K-Nearest Neighbor (KNN) or K based reasoning.

Eager Learner: Constructs a classification model based on the given training data before getting data for predictions. For e.g Decision Tree Naive Bayes 

 

Classification Algorithms

 Classification is supervised learning which categories a set of data into classes. For e.g Handwriting detection, Speech Recognition, Face Recognition, Document Classification etc. 

  • Logistic Regression
  • Decision Tree
  • K-Nearest Neighbor
  • Support Vector Machine
  • Naive Byes
  • Stochastic Gradient Descent
  • Random Forest
  • Artificial Neural Network

Logistic Regression

It is a classification algorithm in machine learning that uses one or more independent variables (a variable that stands alone and isn't changed by the other variables you are trying to measure) to determine an outcome. The outcome is measure with a dichotomous variable (A dichotomous variable is one that takes on one of only two possible values when observed or measured) meaning that it will have only two possible outcomes. For e.g 1 or 0. The goal is to find a best fitting relationship between a dependent variable and a set of independent variables. It quantitatively explains the factors leading to the classification. Only works if the predicted variable is binary in nature. In Logistic Regression it is assumed that there is no missing data and the predictors are independent of each other. For e.g Predicting the risk factor for diseases, word classification, weather prediction, voting application etc.

Naive Bayes

It is a classification algorithm based on Bayes theorm which gives an assumption of independence among predictors. In simple terms Naive Bayes classifier assumes that the presence of a feature in a class is unrelated to the presence of any other feature. This model is easy to make and used for comparatively large datasets.

Pros

  • Requires a small amount of training data to estimate the necessary parameters to get the results. 
  • Extremely fast in nature compared to other classifiers

Cons

  • Bad estimator

Use cases

Disease detection, spam detection or sentiment analysis.

Stochastic Gradient Descent

It is an effective and simple approach to fit linear models. SGD is particularly useful when the sample data is in large numbers. It supports different loss functions and penalties for classification. It calculates the derivatives from each training data instance and calculate the update immediately. 

Pros

  • Ease of implementation
  • Efficiency

Cons

Requires a number of hyper parameters and is very sensitive to feature scaling. 

Use Cases

IOT, Upating the weights in Neural Networks and Linear Regression.

K-Nearest Neighbors

Lazy learning algorithm that stores all instances corresponding to training data in n-dimensional space. It is a lazy learning model as it works on storing instances of training data and not construction of a general internal model. Classification is done by a simple majority vote of K-Nearest neighbor at each point. It is supervised learning and takes a bunch of label points and uses them to label other points. To label a new point it looks at the closest label point (its nearest neighbor). It has the neighbor's vote so whichever label most of the labels have is a label for new point. The K is the number of nearest neighbors it checks. 

Pros

  • Simple in implementation
  • Robust noisy training data
  • Very efficient even if the training data is large

Cons

  • Computation cost is high. 
  • No need to determine the value of K

Use cases

Handwriting detection, image recognition, Stock Analysis etc.

Decision Tree

The decision tree algorithm builds the classification model in the form of a tree structure. it utilizes the if-then rules which are equally exhaustive and mutually exclusive in classification. It breaks down the data into smaller structures and eventually implementing it in a decision tree.

Pros

  • Simple to understand and Visualize
  • Requires very little data preparation

Cons

  • Can create complex trees that may not be efficient in categorization
  • Very unstable model, since a small change can render the whole classification incorrect

Use Cases

Pattern recognition, identify diseases

Random Forest Algorithm

Random decision tree or random forest are an ensemble learning method for classification, regression etc. It operates by constructing a multitude of decision trees at training time and outputs the class that is the mode of the classes or classification or mean prediction(regression) of the individual trees. I

Pros

More accurate then the decision tree

Cons

Complex in implementation and is slow in real time prediction

Use cases

industrial application (If a particular individual applying for loan is high risk or low risk) Mechanical failure of automotive parts, predicting social media share scores, performance scores etc. 

Artificial Neural Networks. 

A neural network consists of neurons that are arranged in layers they take some input vector and convert it into an output. The process involves each neuron taking input and applying a function which is often a non-linear function to it and then passes the output to the next layer. 

Pros

  • It has a high tolerance to noisy data and is able to classify untrained data
  • performs better with continuous inputs and outputs. 

Cons 

  • Poor interpretation
  • Handwriting data, colorization of images and captioning photos based on faces. 

Support Vector Machine 

The support Vector Machine is a classifier that represents the training data as points in space separated into categories by a gap as wide as possible. New points are then added to space by predicting which category they fall into and which space they will belong to. 

Pros

  • Uses a subset of training information making it memory efficient
  • Very effective in high dimensional spaces

Cons

Doesn't provide probability estimates

Use cases

Business application for comparing the performance of a stock over a period of time. Investment suggestions. 

 

Some Machine Learning Concepts

Heuristic: A heuristic is a guiding principle, or best guess, at how to solve a problem. Each attempt made is considered a candidate solution. Sometimes those solutions work, and sometimes they fail


Enable Internet Sharing with IPTABLES and forwarding in Ubuntu Server

This setup assumes the following setup.

  1. Any Linux Distribution (Debian/Ubuntu Preferred since it uses Iptables
  2. The Inteface wlo1 is connected to the Wan
    • wlo1--> WAN
  3. The Interface enp3s0 is connected to the Local Network
    • enp3s0-> LAN

Step 1

Enable IPv4 Forwarding

Assume super user privileges


sudo su


sysctl -w net.ipv4.ip_forward=1

Then issues the following commands

iptables -A FORWARD -o wlo1 -i enp3s0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE

On the Client

  1. Provide an IP Address in the series of 192.168.0.X
  2. Provide the gateway 192.168.0.1
  3. Provide DNS Server 8.8.8.8

And that's it. It should connect

Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download a...