Monday 2 April 2018

How to Play Audio on the Raspberry PI

PLAYING AUDIO ON THE RASPBERRY PI

To play an MP3 file, navigate to the location of the .mp3 file in the terminal using cd and then type the following command:
omxplayer example.mp3
This will play the audio file example.mp3 through either your monitor's built-in speakers or your headphones, connected via the headphone jack.
If you need an example file you can download one from here using the following command:
wget http://rpf.io/lamp3 -O example.mp3 --no-check-certificate
If you cannot hear anything, make sure your headphones or speakers are connected correctly. Note that omxplayer doesn't use ALSA and so ignores the audio configuration set by raspi-config or amixer.
If omxplayer's auto-detection of the correct audio output device fails, you can force output over HDMI with:
omxplayer -o hdmi example.mp3
Alternatively, you can force output over the headphone jack with:
omxplayer -o local example.mp3
You can even force output over both the headphone jack and HDMI with:
omxplayer -o both example.mp3

Python urllib2: Receive JSON response from url

import urllib2
response = urllib2.urlopen('https://api.instagram.com/v1/tags/pizza/media/XXXXXX')
html=response.read()
print html


import json
import urllib2
class Website(object):
    def __init__(self,name):
        self.name = name 
    def dump(self):
     self.data= urllib2.urlopen(self.name)
     return self.data

    def convJSON(self):
         data=  json.load(self.dump())
     print data

domain = Website("https://example.com")
domain.convJSON()

Python Script execute commands in Terminal

import os
os.system("ls -l")


import subprocess
test = subprocess.Popen(["ping","-W","2","-c", "1", "192.168.1.70"], stdout=subprocess.PIPE)

I prefer usage of subprocess module:
from subprocess import call
call(["ls", "-l"])
Reason is that if you want to pass some variable in the script this gives very easy way for example take the following part of the code
abc = a.c
call(["vim", abc])

How to Kill Process in ubuntu by Process Name ?

pkill firefox

pkill -f "Process name"

kill -9 `pidof firefox`


Reference :
https://stackoverflow.com/questions/160924/how-can-i-kill-a-process-by-name-instead-of-pid

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...