Posts

Showing posts from 2016

How To Install Golang compiler on Ubuntu

Image
$ sudo curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz $ sudo tar -xvf go1.6.linux-amd64.tar.gz $ sudo mv go /usr/local $ sudo vim ~/.profile At the end of the file, add this line: export PATH=$PATH:/usr/local/go/bin $ export GOROOT=$HOME/go $ export PATH=$PATH:$GOROOT/bin $ source ~/.profile Create a new directory for your Go workspace, which is where Go will build its files. $ mkdir $HOME/work $ export GOPATH=$HOME/work $ mkdir -p work/src/github.com/user/hello $ vim work/src/github.com/user/hello/hello.go Inside your editor, paste in the content below, which uses the main Go packages, imports the formatted IO content component, and sets a new function to print 'Hello World' when run. package main import "fmt" func main() {     fmt.Printf("hello, world\n") } compile it invoking the Go command install. $ go install github.com/user/hello The file compiled, you can run it by simply referring to the file at your Go path. $ sudo $GOPATH...

How to use bluetooth speaker in ubuntu

Image
Restart the bluetooth service   sudo /etc/init.d/bluetooth restart Pair your blue-tooth  speaker again and connect it Go to sound settings. From the output device tab you should now see the blue-tooth  speaker listed along with internal speakers Choose it as the sound output device, play music with blue-tooth  speaker.

How to get href value of each a tag from the html using python Beautiful Soup

Image
import requests from bs4 import BeautifulSoup link = "http://www.flipkart.com/mobiles?otracker=hp_header_nmenu_sub_Electronics_0_Mobiles" doc = requests.get(link) soup = BeautifulSoup(doc.text, 'html.parser') main_div = soup.find(id="list-tagcloud") div2=main_div.find_all('div')[1] links = div2.find_all('a') for link in links:     print link.attrs.get('href') OUTPUT ====== /mobiles/motorola~brand/pr?sid=tyy,4io /mobiles/lenovo~brand/pr?sid=tyy,4io /mobiles/samsung~brand/pr?sid=tyy,4io /mobiles/leeco~brand/pr?sid=tyy,4io /yu-yunicorn/p/itmejeuf7egdedar?pid=MOBEJ3MF23Q9MGMH /mobiles/honor~brand/pr?sid=tyy,4io /mobiles/mi~brand/pr?sid=tyy,4io /mobiles/asus~brand/pr?sid=tyy,4io /mobiles/apple~brand/pr?sid=tyy,4io /mobiles/intex~brand/pr?sid=tyy,4io /mobiles/sony~brand/pr?sid=tyy,4io /mobiles/alcatel~brand/pr?sid=tyy,4io /mobiles/lava~brand/pr?sid=tyy,4io /gionee-store /mobiles/pr?sid=tyy,4io

How to dispaly data from html tags using python Beautiful Soup

Image
import requests from bs4 import BeautifulSoup link = "http://www.flipkart.com/mobiles?otracker=hp_header_nmenu_sub_Electronics_0_Mobiles" doc = requests.get(link) soup = BeautifulSoup(doc.text, 'html.parser') main_div = soup.find(id="list-tagcloud") div2=main_div.find_all('div')[1] for x in div2.strings:     print x OUTPUT ====== Motorola Lenovo Samsung LeEco Yunicorn Honor Mi Asus Apple Intex Sony Alcatel Lava Gionee All

Find all the URLs found within a page’s using python

Find all the URLs found within a page’s from bs4 import BeautifulSoup html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> """ soup = BeautifulSoup(html_doc, 'html.parser') for link in soup.find_all('a'):     print link.get('href...

How to use BeautifulSoup in python

BeautifulSoup 4 in Python.Beautiful Soup is a Python library for pulling data out of HTML and XML files. html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> """ from bs4 import BeautifulSoup soup = BeautifulSoup(html_doc, 'html.parser') #prin...

Status Codes

Note     1xx: Informational - Request received, continuing process     2xx: Success - The action was successfully received, understood, and accepted     3xx: Redirection - Further action must be taken in order to complete the request     4xx: Client Error - The request contains bad syntax or cannot be fulfilled     5xx: Server Error - The server failed to fulfill an apparently valid request         Available Formats Value     Description    100     Continue 101     Switching Protocols 102     Processing 103-199     Unassigned     200     OK 201     Created 202     Accepted 203     Non-Authoritative Information 204     No Content 205     Reset Content 206     Parti...

How to write simple unit test in django

Success Run test file ============== tests.py ===== from django.test import TestCase # Create your tests here. class TestStringMethods(TestCase):     def test_upper(self):         self.assertEqual('foo'.upper(), 'FOO')     def test_isupper(self):         self.assertTrue('FOO'.isupper())         self.assertFalse('Foo'.isupper()) Success Run test file ============== $./manage.py test Creating test database for alias 'default'... .. ---------------------------------------------------------------------- Ran 2 tests in 0.664s OK Destroying test database for alias 'default'... --------------------------- Failed Run test file ============ tests.py ===== from django.test import TestCase # Create your tests here. class TestStringMethods(TestCase):     def test_upper(self):      ...

How to write logging in django

settings.py ------------------ # https://docs.python.org/2/library/logging.html#logrecord-attributes   LOGGING = {     'version': 1,     'disable_existing_loggers': False,     'formatters':{         'details':{             'format':'%(asctime)s %(process)d %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s'         },     },     'handlers': {         'file': {             'level': 'DEBUG',             'class': 'logging.FileHandler',             'filename': 'location for/ log file/debug.log',             'formatter': '...

How to copy files from remote to home machine using scp

$ scp <domain name>:/home/file.txt /home/sanu/Videos/

NameError: name 'logging' is not defined

logger = logging.getLogger(__name__) NameError: name 'logging' is not defined this error is occurs due to you are not import loggin >>>import logging

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer `PfleSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'.

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer ` PfleSerializer `. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'. >>> p=Pfle.objects.all() >>> seri=PfleSerializer(p,many=True) >>> seri.data

How to rename folder using command prompt

mv oldfolder/ newfolder/

How to use SSH for webfaction

Linux systems, you can start and SSH session with the command line program ssh . At the command line, enter $ ssh username @ server_name .webfaction.com   and press Enter

show databases and tables in MySQL

mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | django_db          | | mysql              | | performance_schema | | sys                | | test               | +--------------------+ 6 rows in set (0.52 sec) mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +----------------------------+ | Tables_in_test             | +----------------------------+ | auth_group         ...

How to set settings.py for MySQL in django

use the password you entered when installing MySql $ mysql -u root -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.12-0ubuntu1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE test; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | django_db          | | mysql              | | performance_schema | | sys           ...

Error: That port is already in use.

$ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$ python manage.py runserver Performing system checks... System check identified no issues (0 silenced). May 09, 2016 - 11:12:08 Django version 1.9.5, using settings 'empl.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Error: That port is already in use. $ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$   Solution    $ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$ ps aux | grep -i manage root       106  0.0  0.0      0     0 ?        S<   May08   0:00 [charger_manager] root       855  0.0  0.0  38328  2344 ?        Ss   May08   0:00 /sbin/cgmanager -m name=systemd root   ...

How install httpie and send POST request through terminal

$ pip install httpie $ http -f POST http://127.0.0.1:8000/login/ imei=123 mac=987

Use Python Lists as Stacks

Image
>>> stack =[] >>> stack.append(1) >>> stack.append(2) >>> stack.append(2) >>> stack [1, 2, 2] >>> stack.append(3) >>> stack [1, 2, 2, 3] >>> stack.pop() 3 >>> stack.pop() 2 >>> stack [1, 2] >>>

Python List and Method

Create empty list : >>> list = [] 1) Add an item to the end of the list >>> list.append(1) 2) Extend the list by appending all the items in the given list >>>list1[1,2,3,4,5] >>>list.extend(list1) 3) Insert an item at a given position. The first argument is the index of the element before which to insert. >>>list.insert(0,3) 4) Remove the first item from the list whose value is 4. It is an error if there is no such item. >>>list.remove(4) 5) Remove the item at the given position in the list, and return it. If no index is specified, list.pop() removes and returns the last item in the list. >>>list.pop(1) 6) Return the index in the list of the first item whose value is x. >>> list.index(3) 7) Return the number of times x appears in the list. >>> list.count(3) 8) Sort the items of the list. >>>list.sort() 9) Reverse the elements of the list >...

How to create a new repository on the command line

Image
$ echo "# my-shop" >> README.md     $ git init   $ git add .   $ git commit -m "first commit"   $ git remote add origin https://github.com/sanuptpm/my-shop.git   $ git push -u origin master    

How to Creating the Django app

Image
make sure you’re in the same directory as manage.py $ python manage.py startapp myshopApp 

How to run your Django project

Image
Go to the manage.py file present folder $ cd myshop $ python manage.py runserver  Right click and open link Or copy and past link into browser   http://127.0.0.1:8000/

How to Creating a Django project

Image
$ django-admin startproject myshop

How to check current version of Django

Image
$ python -c "import django; print(django.get_version())"    

How to install Django in ubuntu

Image
$ pip install Django

jQuery to hide current showing text in HTML

$(document).ready(function(){     $("p").click(function(){         $(this).hide();     }); }); jQuery Examples <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script> /*hide all <p> tage content*/ $(document).ready(function(){     $("p").click(function(){         $(this).hide();     }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> <p>Click me away!</p> <p>Click me too!</p> </body> </html>