Author: Amisha

Title of Lovely Blog hidden under Description

Baar Baar Din Yah Aaye, Baar Baar Dil Yah Gaaye
Tu Jiye Hazaaron Saal, Yah Meri Arazu Hai
Happy Birthday To You…

I am sure you are also rhyming this song with me. Moreover you are thinking why I have written over here. So, it’s time to reveal the surprise.

It’s my Hundredth Happy Blog Day. ūüėČ

All thanks to OpenStreetMap, Linux  and most import Great Developers Team to be a part of this journey.

Coming to non-technical Stuff, today, I heard news

After Train Departs 20 Seconds Early, Japan Railway Issues ‘Deep Apology’

You might be wondering why I have mentioned especially this news over here.

While reading this news many thoughts came to my mind. Previous year while receiving HVPE lecture my Sir said the main reasons how Japanese has a rapid economic growth.

[His Experience- During the departure of bus, In India people catch it by poking others but in Japan they act like civilized person.]

More precisely, they care for people whether it would be their family, employees, or even a person not belong to them in anyway.

They are dedicated to the work assigned to them.

They have spiritual sense of awareness in their social and economic life.

Overall, The Japanese have a practical outlook and believe in showing results in their work, even if this meant trial and error methods.

Now, it’s to time to have a break. Meet you soon with crispy technical stuff. ūüôā

Advertisements

Pip freeze outputs a list of python globally installed packages

Few days back, I got to know the actual meaning of virtualenv from my friend Amrit.

Virtualenv

virtualenv <name>

The above command will create a new directory with <name> which create new python executable path, set up tools like pip, wheel etc through which we can install new python packages even without sudo power and independent of global python packages.

source /<name>/bin/activate

It will activate the virtualenv you have created now. Make sure to activate before you install new package under it.

deactivate                                   //deactivate the virtualenv.

pip freeze                                  //list all the packages installed under that environment.

Before the installation of any package under it, it should output none. But in my it was listing global python packages installed.

On browsing the error, I came to know that there was one file existing named “pip.conf”

[global]
target=/usr/local/lib/python3.4/dist-packages

Either you can remove the file or move it at other place. This seems to be a small problem but in actual it was destroying the real power of having virtualenv. So, solve it ASAP otherwise it gonna create chaos.

PDF Editor

Apart from that, I edited pdf with the online tool https://www.sejda.com/

Seriously it’s too flexible and interest seeking tool because of the features like Add your signature, tick the check box and many more.

 

Publish Post on Page through Facebook API

So, here comes very interesting task. As I mentioned in my previous blog about #LuvLdh Event, this blog is related to that only.

Me and my friend Amrit was given a task to make a web app which will allow user to login through facebook, upload images or document and automatically publish it on page.

This blog will cover very small part of the problem i.e. how user can publish post on a page. We used Facebook SDK for Python.

We followed following links to  solve it.

https://facebook-sdk.readthedocs.io/en/latest/api.html

http://nodotcom.org/python-facebook-tutorial.html

https://stackoverflow.com/questions/24052651/python-facebook-sdk-post-to-page

Installation

Install facebook module of Python as given in https://facebook-sdk.readthedocs.io/en/latest/install.html

Generate Access Token

  1. Login to facebook account.
  2. In new tab, browse to https://developers.facebook.com/
  3. Go to “Tools and Support” and then “Graph API Explorer”.
  4. Click “Get Token” and then “Get User Access Token”. It will prompt out permission options.
  5. In order to publish post on your account, Check box “publish actions” permission and then click “Get Access Token”. It will ask for whom should see the post(preferably public). To know more about permissions browse to https://developers.facebook.com/docs/facebook-login/permissions

Congratulations, you have generated your long string of access token.

import facebook

graph = facebook.GraphAPI(access_token="your_generated_token", version=2.10)

 

The above command will create new object “graph” with your own access token.

graph.put_photo(image=open('img.jpg', 'rb'),
                message='Look at this cool photo!')

This will publish photo on your account. Likewise to publish text or anything follow given links.

Publish Post as a Normal User into a Page.

Now recreate Token with more permissions. This time check box

Scopes user_location, user_likes, user_events, user_photos, user_about_me, user_posts, email, publish_actions, manage_pages, pages_show_list, publish_pages, public_profile

 

Here “public_profile” means to view your post to public. This permission is must. This is obtain when we click “get access token” it ask for to show the post to [public, friends,¬† only me]. Select Public. It took complete one day to debug the problem.:P

Now check the Page_id of the page in which you want to publish. It is displayed in URL or you also see in the “About” Section of the page.

Create the new object just like “graph” object created with new access token.

graph.put_wall_post(message=’Really Worked!!’, profile_id=’your_page_id’)

Likewise, an admin of the page can also publish the post. Rather an admin can select any option among [public, friends,  only me].

Make sure in the General settings of the page there is no bar for a normal user and everything is set to public(if applicable).

Now check post to the page Community section. You will be able to see the post.:)

For any kind of doubt feel free to comment.

Integral

This blog is an integration of small small tasks done few days back.

Steps to install Google chrome in Ubuntu.

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

Gh-Pages

Following this link I tried to make Github Pages

https://pages.github.com/

LuvLdh Website

Then TCC Team created website for the event #LuvLdh located at https://amisha2016.github.io/LuvLdh/

Source code

You can clone the source code from https://github.com/amisha2016/LuvLdh

The actual theme was picked from http://markups.io/demo/eventoz/

Common Ubuntu Commands

The purpose of this blog is to inculcate the readers with some of the important network related commands and other command used on daily basis.

Rename multiple files in the same directory with extension phps to php.

$ rename ‘s/.phps$/.php/’ *.phps

History Command in Ubuntu

$history  //This command maintains history of the commands you applied

The output of this command displays serial number and command only. What if you want to know when that command is applied and at what time? What to do so that your history command always display date and time also?

Here is the answer of all questions.

HISTTIMEFORMAT="%d/%m/%y %T "

Or, to make the change permanent for the current user:

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc

Then

history

Command which tells which ports are open by firewall is.

$ nmap  127.0.0.1

Output

Starting Nmap 7.01 ( https://nmap.org ) at 2017-10-13 14:09 IST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000077s latency).
Not shown: 991 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http
110/tcp open pop3
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
3306/tcp open mysql
5432/tcp open postgresql

Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds

Command to print network connections, routing tables.

$ sudo netstat -nutlap | grep 25

tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 14277/master
tcp 0 0 172.20.10.3:47056 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:47596 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:47424 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:47618 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:47576 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:59342 54.251.241.152:443 TIME_WAIT –
tcp 0 0 172.20.10.3:47530 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp 0 0 172.20.10.3:38490 54.251.58.133:443 TIME_WAIT –
tcp 0 0 172.20.10.3:51642 198.252.206.25:443 ESTABLISHED 2956/firefox
tcp6 0 0 :::25 :::* LISTEN 14277/master

SMTP Secure listen to port 465 and TLS listen to port 587

Command to open port

sudo ufw allow <port number>

eg:- sudo ufw allow 8082

To know more about Ubuntu commands read blogs under the same category.

Stay tuned! ūüôā

 

Test PR Before Merge in Github

Today, I got a task to test the PR https://github.com/GreatDevelopers/TCC/pull/2 

Steps to test the PR in separate branch before merge

1. Create and switch to new branch

$git checkout -b <new_branch_name> <remote_name/existing_branch_name>

Here second parameter is optional. If not mentioned then it will create a new branch exact copy of current branch.

In second parameter you have to give two values remote_name and branch name existing in that remote.

If no remote name is mentioned then by default it will account remote_name=origin.

If I am having more than one remotes as shown below.

$ git remote -v
amisha https://github.com/amisha2016/TCC (fetch)
amisha https://github.com/amisha2016/TCC (push)
origin https://github.com/GreatDevelopers/TCC.git (fetch)
origin https://github.com/GreatDevelopers/TCC.git (push)

Now, I want to create a new branch exact copy of existing branch of remote amisha.

$git checkout -b new amisha/master

2. Pull the PR to the new branch

$git pull <remote_URL> <branch_name>

Here remote_URL is the URL of the repository who has opened/send that PR and branch_name is the name of branch where he has committed that changes. In the image the branch _name is HTML_files.

bran

But in my case the situation was not that easy. Actually the person who has send that PR has deleted the fork of that repository.

bran1

Here branch name is unknown repository. So, the solution is below.

$git checkout master

$ git fetch -f origin pull/2/head:new

Second command means to fetch the changes from PR #ID(here ID is 2) to the newly created branch new. Remember this command won’t work if you are in the same branch where changes to be applied(here branch name is new). That is why I checkout to master branch initially.

My senior Mandeep Singh helped in it.

Now test the PR and enjoy while merging ūüėõ

Connect to Wifi through Terminal

Today, I learned various new commands of ubuntu.

Command to connect to wifi through terminal.

nmcli d wifi connect <WiFiSSID> password <WiFiPassword>

If you have to login for wifi through browser. You can follow steps listed below.

$nmcli d wifi connect <WifiSSID>                              //WifiSSID means name of Wifi

Then install elink through

$sudo apt install elink

If already done then type

$elink

Enter URL of login page and password. Congratulation you are connected through Wifi from terminal. It may seem tedious task but if you know the real power of terminal than this long procedure is worth in.

Inspite of this I used to online tool to edit the properties  like aspect ratio, height and width of image through online tool http://resizeyourimage.com/ . I have used it to fill GATE examination form.

 

 

 

 

 

 

 

 

 

 

 

 

Mutt- Mail User Agent

Mutt is apowerful program for reading and sending electronic mails.

I followed two references to install mutt.

http://nickdesaulniers.github.io/blog/2016/06/18/mutt-gmail-ubuntu/

https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-configure-mutt-email-client-4175513968/

Mutt Installation

$sudo apt install mutt

$ sudo touch $MAIL
$ sudo chmod 660 $MAIL
$ sudo chown `whoami`:mail $MAIL

Create the ~/.muttrc file

set imap_user = "userName@gmail.com"
set imap_pass = "password"

set smtp_url = "smtp://userName@smtp.gmail.com:587/"
set smtp_pass = "password"

set from = "userName@gmail.com"
set realname = "Sender Name"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"

set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set move = no

For furthur usage of Mutt keep in touch with me.

 

 

 

Learn Javascript

Hie everyone and welcome to the Javascript Tutorial. Here I will not hardcode each and every thing. Rather will introduce with the important concepts which you should know about the respective language.

We will start with the concept debugger. What do you mean by debugger in lay-men language. Think about it!

So, bug means fault and debug means to correct fault. Here, debugger is the program(code) which will help to correct errors. I think it is as easy as to understand.

In JS you can debug code in various ways. Here they are illustrated in two ways.

  1. Using Debugger Keyword
  2. Using Console.log

Using Debugger

<!DOCTYPE html>
<html>
<head>
</head>

<body>

<p id=”demo”></p>

<p>With the debugger turned on, the code below should stop executing before it executes the third line.</p>

var x = 15 * 5;
document.getElementById(“demo”).innerHTML = x;
debugger;
x = 15 + 5;
document.getElementById(“demo”).innerHTML = x;
debugger;
x = 15 + 7;
document.getElementById(“demo”).innerHTML = x;

</body>
</html>

The execution will be stopped whenever the keyword debugger will be encountered. In the above code it will stop three times. You can check value of x at every breakpoint.

Using console.log

<!DOCTYPE html>
<html>
<body>

<h2>My First Web Page</h2>

<p>
Activate debugging in your browser (Chrome, IE, Firefox) with F12, and select “Console” in the debugger menu.
</p>

a = 5;
b = 6;
c = a + b;
console.log(c);

</body>
</html>

You will see the value of variable c in the console window. In firefox and  chrome open console window with F12.

Another Case

While doing experiments on JS forms I got to know very interesting thing.

<!DOCTYPE html>
<html>
<body>

<form name=”myForm” action=”/action_page_post.php”
onsubmit=”return false” method=”post”>
Name: <input type=”text” name=”fname”>
<input type=”submit” value=”Submit”>
</form>

</body>
</html>

In the “onsubmit” attribute of <form> tag we call some function in the value part. But if return false Boolean value as shown above then the form would not submit. We can use this benefit in some condition like if any field of the form is empty by adding JS code as illustrated below.

<!DOCTYPE html>
<html>
<head>

function validateForm() {
var x = document.forms[“myForm”][“fname”].value;
if (x == “”) {
alert(“Name must be filled out”);
return false;
}
}

</head>
<body>

<form name=”myForm” action=”/action_page_post.php”
onsubmit=”return validateForm()” method=”post”>
Name: <input type=”text” name=”fname”>
<input type=”submit” value=”Submit”>
</form>

</body>
</html>

 

That’s all for today. Thank-you for bearing me.:)

WordPress Installation

Well the purpose of this blog is clear from the title only. But it’s not just that. Actually, I want to make my OSM_installation_script just like it or better than it. Moreover, my mentor¬†Dr. H. S. Rai asked me to do so.

I followed the below link to install WordPress.

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lamp-on-ubuntu-16-04

When done all the steps mentioned on browsing to the http://localhost I got the  error illustrated below.

word_error

 

On googling to solve the error I got to know about installing the following package.

$ sudo apt install php7.0-mysql

It’s all done. Really it’s a job of 5 minutes.