Wednesday, November 7, 2012

How to disable USB storage mode on Android

If you are annoyed with the continuous popup of the SD card and the phone internal storage on your computer each time you connect your Android phone to the system, here is how you can disable it.

Once you connect your phone to the system and this happens, you'll notice a small USB icon at the top of the phone screen. Drag the top bar down and you'll find an option on the top that says, "USB connection Select to manage your USB connection."

Once you click (tap) on that, you can select the mode you want. To disable storage mode, select "Charge only". To enable, select USB Mass storage.

Your phone should remember the mode you selected last time.

Wednesday, August 31, 2011

Bash: copy directory structure without the files

Here's a one-liner to do that. Go to the source directory and say

user@host:source$ find * -type d -exec mkdir destination/\{\} \;

Tuesday, August 9, 2011

Changing display resolution on Ubuntu when the resolution option doesn't show up

It is very annoying when you have a good monitor (an NEC MultiSync LCD1970NX in my case), capable of supporting 1280x1024 or some such high resolution, whereas Ubuntu simply cannot see beyond 832x624.

Earlier versions of Ubuntu had the xorg.conf file which is no longer present, although if you craft it by hand it is still going to be used. That seems like a dangerous proposition, though - a simple mistake could screw up at least something that is working.

I found the savior in the command xrandr, thanks to X/Config/Resolution page on the ubuntu wiki. And here is what I have done so far:

1. I first ran the command xrandr to make sure that the VGA1 indeed existed. As it turns out, that command can also tell you what is the highest resolution your monitor can support:
sudipta@Springfield:~$ xrandr
Screen 0: minimum 320 x 200, current 832 x 624, maximum 4096 x 4096
VGA1 connected 832x624+0+0 (normal left inverted right x axis y axis) 376mm x 301mm
   1280x1024      60.0 +   75.0 
   1280x960       60.0 
   1152x864       75.0 
   1024x768       75.1     70.1     60.0 
   832x624        74.6*
   800x600        72.2     75.0     60.3     56.2 
   640x480        72.8     75.0     66.7     60.0 
   720x400        70.1 
LVDS1 connected 832x624+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1280x720       60.0 +
   832x624        74.6*
   800x600        85.1     72.2     75.0     60.3     56.2 
   640x480        85.0     72.8     75.0     59.9 
   720x400        85.0 
   640x400        85.1 
   640x350        85.1 
See that 1280x1024 at the top of the list? That is how high my monitor could go. And see that line in the middle with a * at the end (832x624        74.6* in my case) - that one is what I am currently running. And strangely enough, although xrandr knew the highest possible on available, the monitor options only showed 832x624 to be the highest:

So all I had to do to rectify the situation was to open up the gnome terminal and run
xrandr --output VGA1 --mode 1280x1024
which was the highest one supported by my monitor, as mentioned above. Note that I did not specify a refresh rate (using --rate 75 or 60): I let the computer decide for itself. And voila! I had a 1280x1024 screen on my monitor!

I will post an update about how to make the change permanent as well, although the wiki already mentions some options.

Thursday, July 7, 2011

ln -sf gives ?[01;32mFILENAME?[0m

So I was trying to link to a few files from a script and it kept getting me these strange links instead of the actual file name. This is what I had in my shell prompt:

for i in `ls /var/www | grep FILENAME`; do ln -sf $i .; done

[The grep is there because of multiple files which began by the same name]. But then what I got instead in the folder where I was running this script was this:

sudipta@Hogwarts:~/html$ ls -l
total 156
lrwxrwxrwx 1 sudipta sudipta     25 2011-07-06 23:08 ?[01;32mFILENAME?[0m -> ?[01;32mFILENAME?[0m

lrwxrwxrwx 1 sudipta sudipta     34 2011-07-06 23:08 FILENAME.txt -> FILENAME.txt

I had no idea where this strange file was from or why it was here. Also, only a few files were getting affected by this. A simple "ls -l" showed that this was happening only to those files which had the executable file set

After some time, I realized that this was a permissions problem. I gave the local directory write permission by www-data, and then sudo-ed myself into www-data and re-executed my script again.

sudipta@dev:~/html$ rm -f FILENAME*sudipta@dev:~/html$ chmod a+w .
sudipta@dev:~/html$ sudo su www-data
[sudo] password for sudipta:
$
for i in `ls /var/www | grep FILENAME`; do ln -sf $i .; done
$^D
And that did it! All I needed was to run the thing as www-data with write permission in my current directory.
sudipta@Hogwarts:~/html$ ls -l
total 156
lrwxrwxrwx 1 sudipta sudipta     25 2011-07-06 23:08 FILENAME -> FILENAME

lrwxrwxrwx 1 sudipta sudipta     34 2011-07-06 23:08 FILENAME.txt -> FILENAME.txt

Monday, February 14, 2011

Deleting all panels on GNOME desktop

Apparently, deleting all panels is not the easiest thing to do on a GNOME desktop.

Open gconf-editor and goto /apps/panel/toplevels and set these values:
auto_hide: yes


auto_hide_size: 1
expand: no
hide_delay: 1
monitor: 3
unhide_delay: 10000
x: 10000
y: 10000

This will hide the panel permanently.

Friday, November 19, 2010

Keynote like multi-screen output in linux

I normally create my presentations using the beamer package in Latex compiling them into pdf, can't really imagine why would anyone use anything else. I use evince to display the pdf on a projector, but found it to be relatively basic.

I was looking for an application to display some meta-information like the remaining time and the preview of the next slide on my laptop while displaying the current slide on the projector, the way Keynote does it. I found the pdf_presenter_console application, it is fairly minimalistic but seems to do the trick for me.

Tuesday, November 9, 2010

PHP Fatal error: Class 'PDO' not found

When using SQLite with Php for the first time, you might get this error under /var/log/httpd/error_log (I was using a Fedora 13 machine). The trick is to install a package called "php-pdo" and then use the function.

su
yum install php-pdo

Hopefully it will save someone some heartache :)

Friday, October 22, 2010

StrongSwan: we have no ipsecN interface for either end of this connection

I installed a new NIC card on one of my PCs where IPSec was already set up through StrongSwan and configured NAT-ing through iptables. Afterward, when I tried to do "ipsec up myconnection" I got this error:
we have no ipsecN interface for either end of this connection
The reason, it turns out, is that if the ipsec services were started before all the network interfaces came up, it is confused about which egress route to take. As I found on the Layer9 blog (and translated from German to English via Babelfish), it turns out you need to make sure that ipsec starts after the network has come up. The quick fix was just an IPSec restart:
sudo /etc/init.d/ipsec restart

And the long-term fix was definitely to just delay the ipsec a little. Add this to your /etc/rc.local file:
/etc/init.d/ipsec stopsleep 5/etc/init.d/ipsec start

Thursday, October 7, 2010

Strongswan: ike alg: unable to locate my private key

If you are using StrongSwan to establish an IPSec connection and you encounter this error:
root@crackjack:~# ipsec up conn-to-td
002 "conn-to-td" #2: initiating Main Mode
002 "conn-to-td" #2: ike alg: unable to locate my private key
002 "conn-to-td" #2: ike alg: unable to locate my private key
003 "conn-to-td" #2: empty ISAKMP SA proposal to send (no algorithms for ike selection?)

Then I have found the way to solve the first part of your problem - the private key part. Basically, after FreeSwan became OpenSwan and then finally StrongSwan, they created a directory for each individual part under /etc/ipsec.d. So for example the CA certs are stored in the folder /etc/ipsec.d/cacerts, or the certs you got are stored in /etc/ipsec.d/certs. Similarly, you are supposed to store your private key at /etc/ipsec.d/private. What you have probably done is that in /etc/ipsec.conf you wrote down
leftcert=/etc/ipsec.d/private/my_private_key.pem
When in fact you should have your /etc/ipsec.conf as the following:

# ipsec.conf - strongSwan IPsec configuration file

# basic configuration

config setup
    plutodebug=all
    plutostderrlog=/var/log/pluto.log
    charonstart=yes
    plutostart=yes


conn host-to-host
      left=
      leftcert=my_cert.pem
      leftid=my_private_key.pem
      right=
      rightid=
      auto=start
      pfs=no
      rekey=no
      keyingtries=3
After this, you can do the faithful /etc/init.d/ipsec restart and the private key problem will disappear

Tuesday, August 17, 2010

Ubuntu/ALSA controlling volume from the command line

If you are using ALSA as your audio framework, if you are using a common distribution like Ubuntu you probably are, there is a command line program called alsamixer which provides an elaborate set of options to control your sound settings.

The sound setting I most often tinker with is, of course, raising and lowering the volume. A simple way to do that on the command line is "amixer -c 0 sset Master,0 %", for e.g. amixer -c 0 sset Master,0 60%.

Saturday, August 7, 2010

mediawiki blank page after install

If you have freshly installed MediaWiki and are getting a blank page after installing, here is what you are probably doing wrong: the LocalSettings.php needs to have read permissions by everyone as well.

(I am assuming a standard install here)
So if you go to /var/lib/mediawiki/LocalSettings.php it should actually be a softlink to /etc/mediawiki/LocalSettings.php. Try this command:
sudo chmod 755 /etc/mediawiki/LocalSettings.php
And then restart apache (just to make sure):
sudo /etc/init.d/apache restart
That should be it. Now your http://localhost/mediawiki should be visible :)

Monday, August 2, 2010

VMWare tries network boot although you've specified an ISO file in the device settings

It just happened to me, and I found the solution thanks to my teammate. You have to click on the check-box under CDRom that says "Connect at power on". By default, when you add a new CDRom to the machine, this box is not checked. So, there goes...

Friday, July 30, 2010

Cisco IOS router stuck in rommon

Moral of the story - if you are getting checksum errors on the rommon prompt of a Cisco IOS router, and you know that you have downloaded the correct image from the correct website, then either your router's flash memory or the USB drive you are using to transfer it is corrupt. I know the latter seems like a distant possibility, but yes, it has happened to me and I lost a good 3 weeks of productive time trying to troubleshoot this.

Peace!!

Saturday, July 10, 2010

How to see a Cisco IOS CA's root certificate

If you have created an IOS CA server and want to see its root certificate for distribution to other machines, then you must look at its storage location. Suppose you used the following to create your CA:

# enable
(config)# cry pki server thehacklist
(cs-server)# database url flash:
(cs-server)# issuer-name C=IN, ST=WB, O=thehacklist
(cs-server)# cdp none
(cs-server)# grant auto
(cs-server)# no shut
%Some server settings cannot be changed after CA certificate generation.
% Please enter a passphrase to protect the private key
% or type Return to exit
Password:

Re-enter password:
% Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
% Exporting Certificate Server signing certificate and keys...

% Certificate Server enabled.
(cs-server)# end

Now if you look at the storage location (flash in this case, as specified above), you will see a three files named after your CA server (with extensions ending in ser, crl and p12).

# dir flash:
Directory of flash:/

11 -rw- 32 Jul 10 2010 17:54:20 +00:00 thehacklist.ser
1 -rw- 1826 Jan 15 2008 17:52:38 +00:00 sdmconfig-38xx.cfg
2 -rw- 6036480 Jan 15 2008 17:53:10 +00:00 sdm.tar
3 -rw- 861696 Jan 15 2008 17:53:26 +00:00 es.tar
4 -rw- 1164288 Jan 15 2008 17:53:46 +00:00 common.tar
5 -rw- 1038 Jan 15 2008 17:54:02 +00:00 home.shtml
6 -rw- 113152 Jan 15 2008 17:54:16 +00:00 home.tar
7 -rw- 1697952 Jan 15 2008 17:54:42 +00:00 securedesktop-ios-3.1.1.45-k9.pkg
8 -rw- 416354 Jan 15 2008 17:55:06 +00:00 sslclient-win-1.1.3.173.pkg
9 -rw- 59526004 Jun 29 2010 19:23:10 +00:00 c3845-advipservicesk9-mz.124-22.T2
10 -rw- 60288320 Dec 15 2008 23:27:58 +00:00 c3845-adventerprisek9-mz.124-20.T
12 -rw- 247 Jul 10 2010 17:54:20 +00:00 thehacklist.crl
13 -rw- 1627 Jul 10 2010 17:54:22 +00:00 thehacklist_00001.pem

From here, to see the root certificate of the CA, you can use:

# more flash:/thehacklist_00001.pem
-----BEGIN CERTIFICATE-----
MIIB/TCCAWagAwIBAgIBATANBgkqhkiG9w0BAQQFADASMRAwDgYDVQQDEwdjbG91
ZGNhMB4XDTEwMDUwNTIxNDI1MloXDTEzMDUwNDIxNDI1MlowEjEQMA4GA1UEAxMH
Y2xvdWRjYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAlKg0l1DdBpgc/5j3
mA8XodkRq3d5c6K4ZYgUKftEUBAJV3tQz8/ms+CObfmvOn8BdZl0vsLDhJIPRCoq
pypec//gtJpQAAo2I8PCl874yB8k/ebhxBMMhzxQ7y70B0d6gbl8Ub+pmXJnl7Gi
61G41bmNCzXHdfUUiVczpVnaaaaaaaaaaaaaaaaaaaYDVR0TAQH/BAUwAwEB/zAO
BgNVHQ8BAf8EBAMCAYYwHwYDVR0jBBgwFoAUbjpam0qXL8U93MSmngJ1vE1USrMw
HQYDVR0OBBYEFG46WptKly/FPdzEpp4CdbxNVEqzMA0GCSqGSIb3DQEBBAUAA4GB
ACDHm7NNssxSzdD1aQUyUtAni9zo2TCrdcVYtUa5z497JWAPK5YE1tGsMdkYawky
/sUuQMQY4nQFaHtlwKoDHKUSRuygq24GjCUXwoSLLR8jqzfuSgah1ZPohZUPRFEo
EAN2hDdw3Y0o75rsHzie355AH2a22nDnyAm+89EJqEsv
-----END CERTIFICATE-----

Thursday, June 24, 2010

MPlayer: Failed to open LIRC support

Whenever I run MPlayer from my terminal, which is always when I am playing any kind of media, including Youtube videos, I get the following error.

mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

I do not own a LIRC remote control, although I have read it is not too difficult to build one yourself. I this message had become an eyesore. The fix is rather simple. Add a line "nolirc = yes" without the quotes to the file ~/.mplayer/config in your home directory. Given how customizable MPlayer is, it is possible to fine tune almost everything from the config file. The default configurations are listed in /etc/mplayer/mplayer.conf and are overridden by the config file in the home directory.

Tuesday, June 15, 2010

Resolving "murrine_style_draw_box: assertion `height >= -1'"

When using Emacs 23 and a few other applications on Ubuntu running GNOME, I often get a irritatingly cryptic error message ** (emacs:25074): CRITICAL **: murrine_style_draw_box: assertion `height >= -1' failed. Turns out it has got something to do with the theme I'm running.

Thanks to Alf, it is very easy to get rid of that by tweaking Gtk configuration. Modify the entry in /usr/share/themes/Ambiance/gtk-2.0/gtkrc from GtkRange::trough-under-steppers = 0 to GtkRange::trough-under-steppers = 1.

Wednesday, May 26, 2010

Upgrading Fedora from the command line

I have a Fedora box running and I sort of screwed up the GDM so I was left without a display. Since the Fedora 13 (Goddard) was released recently, I decided to upgrade, from the command line. It kept giving me the error that complained, "Can't open display".

I finally figured out that I needed preupgrade-cli, as specified here: http://fedoraproject.org/wiki/PreUpgrade

The syntax, from the command line is this (as root):
preupgrade-cli "Fedora 13 (Goddard)"

Note the quotes surrounding the argument - you need those to specify the string for the version you want to upgrade to.

Monday, May 24, 2010

Eclipse: GLib-WARNING **: g_set_prgname() called multiple times

While coding a few things using SWT on Eclipse, the console was continuously showing me this error:
g_set_prgname() called multiple times
that too in red - meaning a sort of an error.

This is a nagging problem: especially if you are a code purist like me who loves to see no errors/warnings at all in the code I write. I googled a bit, and the Ubuntu Forums provided the solution: downgrade libglib2.0. I'm quoting from there:

Mark the package you want to downgrade, and choose "Force version ..." from "Package" on the main menu. Select the previous version and it is done.

I am using Karmic Koala (yeah I haven't upgraded to the Maverick LTS yet). So all I needed to do was to select the value from the drop down menu to one that did not say "(updates)". Don't worry, there are only two options and you just have to select the other one. After applying, I got that line marked in yellow in Synaptic. But hey... got rid of a nagging warning! :)

Sunday, May 9, 2010

Road rash on Linux using wine

For a lot of us, Roadrash is a game that is going to remain close to our hearts forever! Countless hours spent in front of the PC while kicking and punching others, or even on the LAN fending off your room-mate. For a lot of us, this has been THE introduction to computer video games.

Downloading the game is pretty easy, actually. I got mine at http://www.download-full-games.com/pc/sports/road_rash.html

The tricky part is to get to run it on Linux. In my case, Ubuntu Linux is the only operating system I have: I honestly don't need Windows for much. This game, however, runs only on Windows and so the quintessential wine came to the rescue. So then I unzipped the file and from the command prompt typed:

sudipta@Hogwarts:~/roadrash$ wine ROADRASH.EXE

This unfortunately leads to the "CD-Rom not found" error. The fix to this, as we all know, is to have the registry edited. There is a SETREG.EXE which you can run, but then the state is not persistent. As in, if you run

sudipta@Hogwarts:~/roadrash$ wine SETREG.EXE
sudipta@Hogwarts:~/roadrash$ wine ROADRASH.EXE

Then the registry was just altered when the last wine command was run, not this time. So I opened up the RASH.REG file and found that it contained:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Electronic Arts\RoadRash 95]
@=""
"Path"="D:\\"
"CheckDialup"=hex:00
"ChatState"=hex:02
"MiniDash"=hex:00
"OpponentList"=hex:01 

Which basically means that the above Windows registry value needed editing. This in turn led me back to the .wine folder in my home directory. Lo and behold, there was a system.reg file with lots of Registry-like entries.

sudipta@Hogwarts:~/.wine$ gedit  system.reg

So I simply added a section right on top that said:

[SOFTWARE\\Electronic Arts\\RoadRash 95]
@=""
"Path"="D:\\"
"CheckDialup"=hex:00
"ChatState"=hex:02
"MiniDash"=hex:00
"OpponentList"=hex:01 

This was because there was an entry right on top that said, ";; All keys are relative to \\Machine". And now when I run


sudipta@Hogwarts:~/roadrash$ wine ROADRASH.EXE

I get







Viola! Ah the joys of kicking the next guy off the road... :D

Sunday, April 25, 2010

SSH Hostname Shortcut

As I work with 3 machines: laptop, desktop, and a server: all running 64-bit Linux, I often need to use ssh and scp. I find repeated typing of long hostnames stress inducing, with the chance of making a typo or just the pressure on my fingers. Here is a trick I use.

Create a file .ssh/config with the following entries:

Host [shortcut]
Hostname [full-hostname]
User [username]

where entries in [brackets] are to be filled with your entries. Additional entries like Port, ServerAliveInterval, etc. can also be filled out.

This along with public key based password-less ssh works like a charm. If you are as lazy (= productive) as I am, one-letter shortcuts for frequently used hosts like

$ ssh a

is enough.