Friday, 14 September 2018

Perl to download mp3 from the html page using wget

The script I have tried to get the mp3 files from the web.

#!/usr/bin/perl

die "Usage: $0 <url of page> \n" if @ARGV < 1;

sub getLineFromFile
{
my @outArray;
my $in = shift;
open (my $inf,"<",$in) or die "can't reader the $in";
while(my $row = <$inf>)
{
chomp $row;
#print $row."\n";
push (@outArray,$row);
} 
return @outArray;
}

my $url = shift;
`wget $url`;

$url =~ /([^\/]+\.html)/; #Regex to look for last / and token next with .html 
my$filename = $1;

my @lines = getLineFromFile($filename);

foreach my $line (@lines)
{
my $command;
$line =~/<a .*href="(.*download.*\.mp3)">/; #modify if you find any different href url
my $mp3url = $1;
if($mp3url =~ /\.mp3$/){
#print "get me ".$mp3url."\n";
`wget $mp3url`;

}
}
unlink $filename;


hope it helps and save your time 👍

Monday, 27 August 2018

Install cv2 or opencv-python module in MACos

It took a while to figure out the issues during installing the OpenCV to my mac machine.
Here are the steps that I followed to fix it. maybe it could help you too...

I have opened the Terminal and gave "pip install OpenCV-python". Here the problem starts...


$ sudo -H pip install opencv-python
Password:
Collecting opencv-python
  Downloading https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (42.2MB)
    100% |████████████████████████████████| 42.3MB 244kB/s 
Collecting numpy>=1.11.1 (from opencv-python)
  Downloading https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
    100% |████████████████████████████████| 24.5MB 569kB/s 
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: numpy, opencv-python
  Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
oops, here 😈 starts...
But no worries I got your back.

Here are the few steps that could solve it.

1) Install the tornado package.


$ sudo -H pip install tornado
Collecting tornado
  Downloading https://files.pythonhosted.org/packages/45/ec/f2a03a0509bcfca336bef23a3dab0d07504893af34fd13064059ba4a0503/tornado-5.1.tar.gz (516kB)
    100% |████████████████████████████████| 522kB 1.5MB/s 
Collecting futures (from tornado)
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Collecting singledispatch (from tornado)
  Downloading https://files.pythonhosted.org/packages/c5/10/369f50bcd4621b263927b0a1519987a04383d4a98fb10438042ad410cf88/singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting backports_abc>=0.4 (from tornado)
  Downloading https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado) (1.4.1)
Installing collected packages: futures, singledispatch, backports-abc, tornado
  Running setup.py install for tornado ... done
Successfully installed backports-abc-0.5 futures-3.2.0 singledispatch-3.4.0.3 tornado-5.1

2) Then install the nose package. "sudo -H pip install nose"

3) Actually, this should be the final step but as I have the older version of numpy. It has thrown a stone against 💣💣.

$sudo -H pip install opencv-python

Collecting opencv-python
  Using cached https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting numpy>=1.11.1 (from opencv-python)
  Using cached https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: numpy, opencv-python
  Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

4) So to solve the above issue the numpy need to be updated.

$ sudo -H pip install --ignore-installed numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
    100% |████████████████████████████████| 24.5MB 642kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.15.1

5) Now we are ready to install OpenCV

$ sudo -H pip install opencv-python
Collecting opencv-python
  Using cached https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: numpy>=1.11.1 in /Library/Python/2.7/site-packages (from opencv-python) (1.15.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.2.17


Hope this helps 👍 .....





Tuesday, 19 June 2018

Substring implementation in C

small code snippet of substring implementation in C, may save you time ..


 char *substring(int start, int finish, const char *inString) {

  int inlen = strlen(inString);
    char result[inlen];
    char tmp[2];
    int i,k;
    for (i=start,k=0;i<finish;i++,k++)
    {
    result[k]=inString[i];
    }
    return result;
}



Happy coding 👍😉

Thursday, 4 January 2018

Operation not permitted in MAC OS for delete and move

While trying the delete or move operation in the command prompt, we faced a issue that even root user can't delete or move or rename the folder or file.

was 👀  looking in the found a solution.

May save your time too ...

Steps to resolve:

1) open a Terminal.
2) go to the previous directory in which you face issue. IN my cases ~/Download is the folder in which i can remove any, due to Operation not permitted issue.  So I have moved to /users/xxxx
3)  run the following command in sudo.

     sudo chflags -R nouchg,nouappnd ~/Downloads/ 

replace the folder in which you are facing issue in instead of ~/Downloads/  in above command.

Hope will this helped you 👍



Tuesday, 1 August 2017

Format a new disk and add it to Linux machine

Most of the time when we purchase a new disk for adding to the Linux server or machine, we may face partition issues or mounting issues.


Following are the steps that helped me to get rid of those issue.

Step 1:
Connect the disk to the Linux machine or server. In my scenario Linux flavor CentOS 5.2

Step 2:
Open a terminal in administrator mode or please add sudo for following commands.
  • Run the fdisk -l command. the output will like 
    Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       13067   104856255   83  Linux
/dev/sda3           13068       26121   104856255   83  Linux
/dev/sda4           26122       60801   278567100    5  Extended
/dev/sda5           26122       32648    52428096   83  Linux
/dev/sda6           32649       33170     4192933+  82  Linux swap / Solaris

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  • Here the /dev/sdb is disk that I have to add to my server.
  • To work on the specific disk open that disk in using fdisk.
  • sudo fdisk /dev/sdb and give option p to print the partition table.
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): p

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

  • In same fdisk console give option n to create new partition. and select primary partition(P)or extended (e). I have used +512000M for creating partition of 500GB

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):<Press Enter to choose default>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 
121601): +512000M

  • Follow the above step to create next partition too.
  • After creating the partition, that must be written to disk. 
Command (m for help): w

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylinders

  • Next primary step is to mount it to local file system .
  • Before mounting the fdisk should be give extension type , like ext2 or ext3 etc..
  • Run 
mkfs -t ext3 /dev/sdb1
  • then Create local for mounting like /storage01
mkdir storage in home of any mount location.
  • Mount the /dev/sdb1 to /storage01
mount -t ext3 /dev/sdb1 /storage01
  • Follow the same steps to the partitions you have created like sdb2 , sdb3.....

Hope it helped you. Happy storage :)

Tuesday, 25 July 2017

How to change message center number in Moto mobiles


  • First step call the network operator and get the alternative message center number.
  • Then Dial *#*#4636#*#*.
  • Test Run Menu will appear,
  • Select Phone Information.
  • Scroll down for "SMSC". Add the new number and submit/refresh it. 
  • Then the problem must be resolved.

You are done........... 😉

Thursday, 9 February 2017

How to transfer contact to Nokia 130

How to import contacts to Nokia 130 (Dual SIM)
export contacts from google or old phone as a one vcf file (contacts.vcf)
rename it to backup.dat and copy to root of memory card of phone
Menu -> Contacts -> Settings -> Restore contact.


Hooray.......