Pages

Tuesday, October 15, 2013

android, apps can't connect to internet, except browser

I came across this problem, that in my android phone, i was not able to connect o gtalk, whatsapp, maps etc, whereas  I was able to browse internet via browser.

The reason I found out was that I came across a wifi connection sometime that blocked my phone apps from connecting to internet. After that, even if I use data connection via sim, I was not able to use internet based apps.


The solution is:

go to

Settings->Wireless and Networks ->Mobile Networks-> Access point names

Now, right click and select 'Reset to default'.

That's it, now I was able to connect these apps to internet.

Monday, September 16, 2013

Ubuntu: wifi(wireless) connection fails?

In secured network setup like in your office, if you try to connect to office wifi, it will keep asking for proper 'authentication' popping up userid and password window forever, although credentials are correct!.

So, how to overcome this error and make your ubuntu laptop connect to wifi ?

While connecting to wifi, if you observe the syslog closely, you will find that target router keeps cancelling connection request with the reason ' unable to get local issuer certificate...'.

What is happening in the background is, the wireless service on ubuntu, eduroam, is forcing CA certification validation, from your client PC also. Usually your laptops are not CA certified, isn't it?.

So open your target wifi config file

sudo vim /etc/NetworkManager/system-connections/<wifi i want to connect to>

change 'system-ca-cert=true' to 'system-ca-cert=false'.

I hope it should start working for you now !.

Otherwise, go back to syslog and see what's messed up!.


Friday, August 30, 2013

boost your Linux running laptop's power savings - PowerTop, laptop-mode-tools

Often, people find their laptop running linux consuming more power compared to windows. Mostly this is so because, it a luxury that Linux offers you, to install on any kind of hardware. People would purchase  Windows installed Laptops, those that do not officially support Linux. But you will remove windows and Linux immediately and it works !!! , except few issues like more power consuption, or fan running with high speed etc..

Anyways, there are couple outstanding utilities out there to help you balance the power usage on your laptops(these utils work for desktops also, but relatively these are more helpful in tuning your laptops ).

PowerTOP
===============

How to Install:
------------------------

sudo apt-get install powertop

How to run:
------------------------

:~$ sudo powertop

the output is an interactive window that looks like below,


The Overview shows which process/device consuming how much power. With this you can make out which process/device is using the power most and take corrective actions accordingly.

Use arrow keys(left and right) to navigate between each of the tabs on the console.
The second tab, "idle stats' shows cpu wise and core wise (including hyperthreads) idle state.

The third tab 'frequency stats' shows frequency wise power usage statistics.

Fourth tab 'Device stats' shows which physical device is consuming power most.

Fifth tab 'tunables' shows configurable paramters that we can tune to improve the power savings. 

To get realistically what needs to be done to increase power savings, run

:~$ sudo powertop --html

This will create an html file called powertop.html. It looks like below

If you see the above window, it will exactly tell what you need to do. You have to update certain kernel config files with certain values as shown. Doing this will improve the power usage.

Also, if you don't want to take all that headache, you can keep the laptop running in battery mode(unplug the power cable) and run

:~$ sudo powertop --calibrate

This will calibrate the system by doing all the necessary tunings.



laptop-mode-tools:
=======================

This is another tool that lets you do efficient power management on the laptop. Run

$~: sudo apt-get install laptop-mode-tools

This will install the utility as startup app by default. Hence you do not have to worry about starting it everytime when you turn on the laptop. The configuration file will be in 

/etc/laptop-mode/laptop-mode.conf

If you make any update to this file, run 

$~: service laptop-mode reload

for the changes to take effect.

For more info on this tool, refer

 https://wiki.archlinux.org/index.php/Laptop_Mode_Tools





Sunday, August 25, 2013

add virtualbox guest to network domain

I have done this on a linux host and windows 7 guest.  The requirement was to put the windows 7 guest to office network.

1. create a bridged adapter for the guest, using virtualbox settings window.


2.  This will create an adapter on the guest that will have the IP picked from ntework domain in which your host exists. That means The IP will be looking similar to the host IP, that can be pinged from a different PC.

3. Now, go to your guest OS, Start-> My computer-> right click -> Properties

4. Click on 'change settings' that you see on the right bottom side. you will get below window.


5. Click on 'Change' button in the above window. (see 'To rename this computer or domain...'). you will get below window.


6. You will see 'Workgroup' enabled. Change it to 'Domain'(see under 'Member of'). Add your domain name here and click okay. This will make the OS to contact DNS server and register itself . Here on you will be able to login to domainname/username in your Guest OS.



enable telnet on non default port, allow root login

Telnet deamon listen to port 23 by default. If you want to enable make it listen on different port(for example 2233), perform following steps:



For BusyBox telnet:

=> start telnetd on server as "telnetd -p 2233". This will run the deamon in background making it listen on port 2233.
=> from client, login as 'telnet <server ip> 2233'
=> Note that busybox telnet does not allow root login.


For ineutil telnet:

=>You will have a config file 'telnet' in /etc/xinetd.d/ directory
=> The file looks like 


# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE IPv4
socket_type = stream
only_from = 0.0.0.0
wait = no
server = /usr/sbin/in.telnetd
instances = 5
log_on_failure += USERID
disable = no
}

=> to this file, add entry

port = 2323

to change listening port. Also edit /etc/services file and modify 

telnet          23/tcp

to 

telnet          2323/tcp

To allow root login, add entry

user = root
If you want to restrict only certain clients to be able to login, modify 

only_from = <ip range>








Wednesday, August 14, 2013

subtitle and video synchronization in vlc player

Sometimes, the subtitles we download from internet do not sync with the video we are playing. Either it will be little ahead or behind, resulting in a different subtitle appearing for a different picture frame.

By knowing how much is the lag between video and the subtitle, we can sync these two, to play it proper.

to know the lag, play the video, try to listen to most commonly recognizable word. Not down the time stamp at that moment. Now, you have to find out at what timestamp actually that word being played from the subtitle file. Either you open the file with a word processor and see around that time or while playing the video itself you will know what time the subtitle was/is being played.

For example, In my video, I hear a sound 'Hey Macho' that i can clearly recognize. I note that it is played at 4 min 11 sec. From the file, the subtitle 'Hey Macho' is being played at 4 min 5 sec. So the lag is around 6 seconds.

To overcome this lag, on your VLC player, go to Tools->Track synchronization


The track synchronization window looks like below:

the Subtitle track synchronization window shows 1.7 seconds value which means the subtitle will be played 1.7 second late compared to how it would have played without this synchronization.





Tuesday, July 16, 2013

count number of blank lines in a file using grep



To count number of blank lines in a file, we use following grep expression.

$grep -c '^$' filename

=> this will try to extract lines starting and ending with nothing in between.

Saturday, July 13, 2013

how to debug bash shell script

 Unlike C/C++ applications, wherein you will you have to printf messages to debug, there is an easier and more detailed way of debugging shell scripts, specially in bash.

In your shell script, you can add

set -x

at the top of the script, this will make bash to print each command line it parse in your shell script, plus the result of the command as well.

Doing this permanently enable tracing, until you remove it or put "set +x" which is the default.

If you just want to see how it goes once, you can run your script "myscript.sh", try

$ bash -x myscript.sh

output looks like

+ var1=hi
+ var2='how are you'
++ paste hi how are you
paste: hi: No such file or directory
+ var3=
+ echo

"+" means, the sublevel of the command from the main shell script. i.e one + indicates the exact line of command as written in shell script, 2 +s indicate another command within the line of code you have written inside the script.

There is another, lesser debug info method.

$ bash -v myscript.sh

output looks like

#!/bin/bash
var1="hi"
var2="how are you"
var3=`paste $var1 $var2`
paste $var1 $var2
paste: hi: No such file or directory
echo $var3

This will just echo each line of the script as it parses, plus errors or echos from script if any.

Upgrade Java Runtime (JRE) on Debin/Ubuntu

Its high time you upgrade your JRE on your linux, as any version before Java 7 update 11 has serious security flaws. 

Firefox, by default blocks java based on the version you have installed. It means it doesn't allow you to run any java application using these security-issue-ridden java versions.

But, not the same with other browsers or your OS. You got to update it immediately.

NOTE: openjdk jre is also similar to oracle java, hence you can expect same issues with open jdk too. Until you get an update on openjdk, I suggest you use oracle java, well it is not too complex to install oracle java as it looks like on the surface.

Here is how to be done: (OS: Ubuntu)


  1. Download latest java from oracle site http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
  2. if you are using 32 bit linux(most likely intel, x86 arch), choose the right file to download(rpm type for redhat based, .gz for debian based)
  3. untar using command 'sudo tar -xzvf jre-7u25-linux-x64.tar.gz -C /usr/java/
  4. To enable this java on Firefox, create soft link for a lib libnpjp2.so from your java directory to firefox plugin directory. It looks something like this:                                                                 "sudo ln -s /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so /usr/lib/firefox/plugins/"
  5. to verfiy, restart firefox, go to "about:plugins" in address bar,  see if you have following information: "

    Java Plug-in 1.7.0_25

    File: libnpjp2.so
    Path: /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so "

    that's it, you are upgraded!

    For google-chrome, you don't have to do anything if you have untarred the jre under /usr/java. To verify, restart your chrome, go to 

    chrome://plugins/

    Look for 

    Java(TM) Download Critical Security Update
    Java plug-in for NPAPI-based browsers.
    Name:Java Plug-in 1.7.0_25
    Description:Java plug-in for NPAPI-based browsers.
    Version:
    Location:/usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so

    (don't forget to remove older versions of java)

Saturday, July 6, 2013

convert images to pdf


to convert one or multiple images to pdf file, use the command

$convert scan_*.jpg scanned_docs.pdf

convert command comes with package imagemagick

Monday, June 17, 2013

code complexity tool pmccabe

whenever we write code, it is advisable to test the complexity of the code we are writing.  This will help in source code maintainability, readability etc.

The best algorithm to do the same is cyclomatic complexity. (http://en.wikipedia.org/wiki/Cyclomatic_complexity)

One of the utility implementing this algorithm is pmccabe.

This ain't any IDE also! A simple CLI utility.


install:
sudo apt-get install pmccabe

usage:
<username>@<hostname>:~~$ find ./ -name *.c | xargs pmccabe  | sort -nr | head -10
49    49    116    361    134   <file>(362):<function>

The first column indicates the complexity score of each of the functions mentioned.
The wiki suggests that the complexity score should be kept below 10, and in inevitable cases, it can go upto 15. 

vlc player, enable en queue(add to playlist) on right click

By default, on double clicking on a song in folder, the song is opened in new vlc player session. There is no "add to playlist" option. To change this settings,


  1. On the vlc player, go to tools->preferences
  2. click on 'interface' (default) on the left menu,  on the  right, click on 'instances'
  3. check both 'allow only one instance' and 'enqueue when in one instance mode'

Tuesday, June 11, 2013

blogger can't import wordpress posts!

I was on wordpress before. Thought of moving to blogger, as wordpress want me to pay for each and everything more than what they consider 'basic'.


  1. I went my wordpress dashboard->settings->export
  2. exported an xml file (selected all as an option, to include posts, tags comments etc)
  3. Then I created a blogger, went to settings->other->import blog
  4. my xml files was just in Kbs, nevertheless, the blogger went on taking hours to import
  5. What I noticed is that it was stuck on first post itself to import. Then I learnt that to import from wordpress to blogger, a conversion is needed.
  6. So, go to wordpress to blogger convertor and get your xml file converted.
  7. Try repeating step #3. 
  8. It should work!

linux: search grep all man pages

If you would like to perform some operation on linux, and is not aware of utility that need to be run, you can search all available commands man pages to search.

There is a fine utility to do so, called apropos.

For example, I want to know all commands that operate on pdf files, like conversion from pdf to something else and vice versa, I will run
uid@host:~/apropos pdf
acroread (1)         - Adobe PDF Viewer for viewing PDF files on X Window System.
dvipdf (1)           - Convert TeX DVI file to PDF using ghostscript and dvips
evince-thumbnailer (1) - create png thumbnails from PostScript and PDF documents
fix-qdf (1)          - repair PDF files in QDF form after editing
foomatic-ppdfile (1) - Generate a PPD file for a given printer/driver combo
ghostscript (1)      - Ghostscript (PostScript and PDF language interpreter and previewer)
gs (1)               - Ghostscript (PostScript and PDF language interpreter and previewer)
gsnd (1)             - Run ghostscript (PostScript and PDF engine) without display
pdf2dsc (1)          - generate a PostScript page list of a PDF document
pdf2ps (1)           - Ghostscript PDF to PostScript translator
pdffonts (1)         - Portable Document Format (PDF) font analyzer (version 3.00)
pdfimages (1)        - Portable Document Format (PDF) image extractor (version 3.00)
pdfinfo (1)          - Portable Document Format (PDF) document information extractor (version 3.00)
pdfopt (1)           - Ghostscript PDF Optimizer
pdfseparate (1)      - Portable Document Format (PDF) page extractor
pdftocairo (1)       - Portable Document Format (PDF) to PNG/JPEG/PDF/PS/EPS/SVG using cairo
pdftohtml (1)        - program to convert PDF files into HTML, XML and PNG images
pdftoppm (1)         - Portable Document Format (PDF) to Portable Pixmap (PPM) converter (version 3.00)
pdftops (1)          - Portable Document Format (PDF) to PostScript converter (version 3.00)
pdftotext (1)        - Portable Document Format (PDF) to text converter (version 3.00)
pdfunite (1)         - Portable Document Format (PDF) page merger
ps2ascii (1)         - Ghostscript translator from PostScript or PDF to ASCII
ps2pdf (1)           - Convert PostScript to PDF using ghostscript
ps2pdf12 (1)         - Convert PostScript to PDF 1.2 (Acrobat 3-and-later compatible) using ghostscript
ps2pdf13 (1)         - Convert PostScript to PDF 1.3 (Acrobat 4-and-later compatible) using ghostscript
ps2pdf14 (1)         - Convert PostScript to PDF 1.4 (Acrobat 5-and-later compatible) using ghostscript
ps2pdfwr (1)         - Convert PostScript to PDF without specifying CompatibilityLevel, using ghostscript
qpdf (1)             - PDF transformation software

run "man apropos" for extra features with it.

Sunday, June 9, 2013

ssh login without password

Generate ssh key for your host pc

=> $ssh-keygen<enter>

Copy the key generated to remote pc to where you wish to login via ssh.

=>ssh-copy-id -i ~/.ssh/id_rsa.pub <userid>@<remote ip>

that's it! you should be able to login without prompting for password.

virtualbox arch linux access via ssh

to access virtualbox guest via ssh from your host,

  1. on host do modprobe on following modules - vboxdrv, vboxnetadp, vboxnetflt
  2. If any of the modules not found, you should have installed linux-headers and virtualbox-host-dkms before on your host.
  3. keep your guest shutdown
  4. open virtualbox GUI
  5. go to file->preferences->network
  6. add a host-only network , this will add interface called vboxnet0 on your host.
  7. once added vboxnet0, on the same window, click edit , which will show you default ip settings (start ip, netmask, gateway etc)that you can make use of , to set ip manually/dynamically. If you plan to ssh to guest later, you probably want to disable dhcp server, as the ip keeps changing if dhcp is enabled. on the 2nd tab in the edit window, uncheck dhcp server.
  8. Now, go to individual guest settings on virtualbox gui
  9. go to network option
  10. You should already be seeing a NAT adapter being added. Add adapter2 as host-only network adapter.
  11. chose vboxnet0 as the interface.
  12. click ok and exit.
  13. start your guest.
  14. when you do ifconfig -a, you will observe that one more network interface is added to the existing list. if you did not find., perform step #1 and #2 on guest also.(reboot if necessary).
  15. you can assign a static ip like on any other linux host, for example, "ifconfig eth1 192.168.56.99 netmask 255.255.255.0 up".
  16. To make it work across reboot, you may need prepare a file called /etc/network/interfaces. google for format of the file.
  17. If you are using arch-linux, you will have to add file called /etc/systemd/system/network.service. Look for the format of this file in wiki.archlinux/networking
  18. usually the commands used are /usr/bin/ip addr .. etc. I installed net-tools and and added ifconfig command as in #15. Keep in mind that you wil lhave to provide full binary path for ifconfig.
  19. once added, you need to enable it. perform "systemctl enable network".  This will enable the service across reboot.
  20. if this fails, perform "systemctl status network.service" to check what's going wrong.

 

On a technical explanation side, virtualbox provides 3 types of networking facilities to guests.

  1. NAT(default). With this, any network packets from the guest is treated as a packet pumped from any process(virtualbox here) by host. Advantage is you don't need any tweaking to get this work, by default you will get IPs in the range 10.x.x.x... You will be able to access any network that your host is able to acess. Disadvantage is that the guest itself as a physical machine, is not accessible to external world(even to the host).
  2. host-only adapter: here, you will need to create an interface on host(vboxnet0). Need to load a driver vboxnetflt, that will acts as netowork filter to seprate out guest interface from host interface. virtualbox will internally create a router between guest and host, which makes host to see guest as a different machine all toghether(you can ssh to guest from host). advantage as well as disadvantage is that, guest will be visible only to host and other VMs but not to the external world as the IP is obtained form dhcp server of the host.
  3. bridged adapter: this will expose the guest as a remote PC to the external world also. Ip is obtained from the same dhcp server from which host is getting it.
  4. internal network: Only to connect VMs on the same host.
  5. bridged ad

Monday, June 3, 2013

Shell script: IF file/string operators

Shell script: IF file/string operators

bash Shell script: IF statement file/string operators

Shell script : IF file/string operators

Shell script : IF file/string operators

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

Shell script: IF file/string operators

comment multiple lines in vim


  1. keep the cursor on the first letter of first line to comment

  2. in command mode, press ctrl + v

  3. move cursor down until last line to comment

  4. press I (you may not see vim going to insert mode, don't worry, you will see cursor moving to first line)

  5. press # (you may not see # inserted yet, don't worry)

  6. press Escape ( you should see lines commented out, otherwise, press escape two times)

Wednesday, May 29, 2013

"For example, I...

"For example, I was taught in college that one ought to figure out a program completely on paper before even going near a computer. I found that I did not program this way. I found that I liked to program sitting in front of a computer, not a piece of paper. Worse still, instead of patiently writing out a complete program and assuring myself it was correct, I tended to just spew out code that was hopelessly broken, and gradually beat it into shape. Debugging, I was taught, was a kind of final pass where you caught typos and oversights. The way I worked, it seemed like programming consisted of debugging.
For a long time I felt bad about this, just as I once felt bad that I didn't hold my pencil the way they taught me to in elementary school. If I had only looked over at the other makers, the painters or the architects, I would have realized that there was a name for what I was doing: sketching. As far as I can tell, the way they taught me to program in college was all wrong. You should figure out programs as you're writing them, just as writers and painters and architects do. "    

 

 

"Universities and research labs force hackers to be scientists, and companies force them to be engineers"

- Paul Graham

"For example, I...

"For example, I was taught in college that one ought to figure out a program
completely on paper before even going near a computer. I found that I did not
program this way. I found that I liked to program sitting in front of a computer,
not a piece of paper. Worse still, instead of patiently writing out a complete
program and assuring myself it was correct, I tended to just spew out code that
was hopelessly broken, and gradually beat it into shape. Debugging, I was
taught, was a kind of final pass where you caught typos and oversights. The way
I worked, it seemed like programming consisted of debugging.
For a long time I felt bad about this, just as I once felt bad that I didn't hold my
pencil the way they taught me to in elementary school. If I had only looked over
at the other makers, the painters or the architects, I would have realized that
there was a name for what I was doing: sketching. As far as I can tell, the way
they taught me to program in college was all wrong. You should figure out
programs as you're writing them, just as writers and painters and architects do.
"
- Paul Graham

Monday, May 27, 2013

Ubuntu: youtube downloader

 

 

To download youtube videos or any embedded videos from websites,

  1. Install firfox if you don't have it on your system.

  2. open firefox web browser

  3. go to Tools->Add Ons

  4. search for video downloadHelper

  5. the "video downloadHelper" add on will appear in search results.

  6. install the add on.

  7. restart the firefox.

  8. open youtube.

  9. click on some video.

  10. to the left of address bar in firefox, you will see one animated bubbles playing, which means the particular website has an embedded video to download.

  11. click on it and download the video.

  12. DONE.