OSX Screenshots tips

Changing location to store screenshot

The default place where screenshots are saved in OSX is the Desktop. For people (like me), who would like to keep their desktops nice and clean and a little organised, we can change the location where the screenshot are stored. This needs command line. Launch “Terminal” and type the following commands which should do the trick. I am moving my screenshot location to somewhere in Google Drive. Please note that the location which you are setting as the target for storing screenshots, must exist, and as you can see, I am creating it first.

$ mkdir -p ~/Google\ Drive/Pictures/Screenshots
$ defaults write com.apple.screencapture location ~/Google\ Drive/Pictures/Screenshots/ && killall SystemUIServer

The “killall” command is used to restart the SystemUIServer so that the changes can be picked up by the system.

Changing the Screenshot file type

The default screenshot file type is PNG. However, you can change this to – jpg, tiff, pdf, gif by using the following command on the terminal.

$ defaults write com.apple.screencapture type gif && killall SystemUIServer
Posted in Tips/Code Snippets | Tagged | Leave a comment

Huawei E303c as Modem on Raspberry Pi

I have a Huawei E303c USB modem, which I wanted to use with my Raspberry Pi so that I can connect my Pi to the Internet and run my local server. Now why would I want to do that when I have a broadband at home? Now those of you who are in India and uses ACT Broadband, which has recently become very popular in Southern India due to its fibre technology, may know that ACT uses Carrier-Grade NAT, as a result of which I do not have the public IP address and hence can not rely on port forwarding on my router.

Here is how I configured the device. During this course, I referred to various other websites and at the bottom of this page, I have provided those as a reference.

These UMTS modems consume a lot of power and hence it is recommended that these may be connected to a powered USB hub connected to the Pi.

Configuring the USB Modem Device

Connect the device to the USB port and issue the lsusb command after few seconds to check if the device has been detected –

$ lsusb
Bus 001 Device 008: ID 12d1:14fe Huawei Technologies Co., Ltd.

Note down the device number, in this case 12d1:14fe
If you see the dmesg at this point you will find that the device will be detected as a CDROM and a USB storage device and not a modem. I do not have the output as I forget to save it.

We need to install usb-modeswitch package which helps in the switching of device mode from USB Storage to USB modem mode.

$ sudo apt-get install usb-modeswitch
$ sudo reboot
$ lsusb
Bus 001 Device 008: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard

Make a note of the device number for future reference, we would need this number for TargetProduct value. In this case this is 12d1:1506. If you see this has been changed from the last time. Here the usb-modeswitch is active. The pi has detected my E303C as E398 but that’s alright.

Now running dmesg will show the below which indicates that the modem is detected and configured –

$ sudo dmesg | grep -i usb
[ 0.593089] usbcore: registered new interface driver usbfs
[ 0.598824] usbcore: registered new interface driver hub
[ 0.604340] usbcore: registered new device driver usb
[ 1.015352] usbcore: registered new interface driver smsc95xx
[ 1.539943] dwc_otg 20980000.usb: DWC OTG Controller
[ 1.546616] dwc_otg 20980000.usb: new USB bus registered, assigned bus number 1
[ 1.555602] dwc_otg 20980000.usb: irq 32, io mem 0x00000000
[ 1.573463] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[ 1.581919] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.590782] usb usb1: Product: DWC OTG Controller
[ 1.597093] usb usb1: Manufacturer: Linux 4.1.18+ dwc_otg_hcd
[ 1.604400] usb usb1: SerialNumber: 20980000.usb
[ 1.611639] hub 1-0:1.0: USB hub found
[ 1.623853] usbcore: registered new interface driver usb-storage
[ 1.797393] usbcore: registered new interface driver usbhid
[ 1.804559] usbhid: USB HID core driver
[ 2.076207] usb 1-1: new high-speed USB device number 2 using dwc_otg
[ 2.316814] usb 1-1: New USB device found, idVendor=0424, idProduct=9512
[ 2.325540] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 2.338687] hub 1-1:1.0: USB hub found
[ 2.626257] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[ 2.736724] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00
[ 2.745604] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 2.844813] smsc95xx 1-1.1:1.0 eth0: register 'smsc95xx' at usb-20980000.usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:c2:b6:99
[ 2.956388] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[ 3.086999] usb 1-1.2: New USB device found, idVendor=1a40, idProduct=0201
[ 3.095927] usb 1-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[ 3.105228] usb 1-1.2: Product: USB 2.0 Hub [MTT]
[ 3.114467] hub 1-1.2:1.0: USB hub found
[ 3.416291] usb 1-1.2.3: new high-speed USB device number 5 using dwc_otg
[ 3.527702] usb 1-1.2.3: New USB device found, idVendor=1058, idProduct=0748
[ 3.536728] usb 1-1.2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=5
[ 3.547663] usb 1-1.2.3: Product: My Passport 0748
[ 3.554208] usb 1-1.2.3: Manufacturer: Western Digital
[ 3.561146] usb 1-1.2.3: SerialNumber: 57585331453233574A4C4432
[ 3.617837] usb-storage 1-1.2.3:1.0: USB Mass Storage device detected
[ 3.628629] scsi host0: usb-storage 1-1.2.3:1.0
[ 3.716364] usb 1-1.2.4: new high-speed USB device number 6 using dwc_otg
[ 3.837768] usb 1-1.2.4: New USB device found, idVendor=1058, idProduct=0702
[ 3.846795] usb 1-1.2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3.857730] usb 1-1.2.4: Product: External HDD
[ 3.864239] usb 1-1.2.4: Manufacturer: Western Digital
[ 3.871169] usb 1-1.2.4: SerialNumber: 575843393037323139333433
[ 3.924643] usb-storage 1-1.2.4:1.0: USB Mass Storage device detected
[ 3.946315] scsi host1: usb-storage 1-1.2.4:1.0
[ 4.037283] usb 1-1.2.5: new high-speed USB device number 7 using dwc_otg
[ 4.159220] usb 1-1.2.5: New USB device found, idVendor=12d1, idProduct=1506
[ 4.168316] usb 1-1.2.5: New USB device strings: Mfr=3, Product=2, SerialNumber=0
[ 4.179397] usb 1-1.2.5: Product: HUAWEI Mobile
[ 4.185712] usb 1-1.2.5: Manufacturer: HUAWEI
[ 4.256197] usb-storage 1-1.2.5:1.4: USB Mass Storage device detected
[ 4.282053] scsi host2: usb-storage 1-1.2.5:1.4
[ 4.307321] usb-storage 1-1.2.5:1.5: USB Mass Storage device detected
[ 4.329879] scsi host3: usb-storage 1-1.2.5:1.5
[ 4.843019] usbcore: registered new interface driver cdc_ncm
[ 4.868289] usbcore: registered new interface driver usbserial
[ 4.966542] usbcore: registered new interface driver usbserial_generic
[ 4.975231] usbserial: USB Serial support registered for generic
[ 5.048437] usbcore: registered new interface driver cdc_wdm
[ 5.209021] usbcore: registered new interface driver option
[ 5.342683] usbserial: USB Serial support registered for GSM modem (1-port)
[ 5.546749] huawei_cdc_ncm 1-1.2.5:1.1: cdc-wdm0: USB WDM device
[ 5.555830] huawei_cdc_ncm 1-1.2.5:1.1 wwan0: register 'huawei_cdc_ncm' at usb-20980000.usb-1.2.5, Huawei CDC NCM device, 58:2c:80:13:92:63
[ 5.741270] usbcore: registered new interface driver huawei_cdc_ncm
[ 5.839357] usb 1-1.2.5: GSM modem (1-port) converter now attached to ttyUSB0
[ 5.995187] usb 1-1.2.5: GSM modem (1-port) converter now attached to ttyUSB1
[ 6.225904] usb 1-1.2.5: GSM modem (1-port) converter now attached to ttyUSB2

Now we will look for the relevant device configurations in the sample config files which comes with the usb-modeswitch package and extract the file.

$ tar -tvzf /usr/share/usb_modeswitch/configPack.tar.gz|grep "12d1:14fe"
-rw-r--r-- root/root       155 2012-12-08 22:22 12d1:14fe
$ tar -xvzf /usr/share/usb_modeswitch/configPack.tar.gz 12d1\:14fe
12d1:14fe
$ ls -l 12d1\:14fe
-rw-r--r-- 1 ajitabhp ajitabhp 155 Dec  8  2012 12d1:14fe

Checking the contents of this file will give me

$ cat 12d1\:14fe 
# T-Mobile NL (Huawei E352)

TargetVendor=  0x12d1
TargetProduct= 0x1506

MessageContent="55534243123456780000000000000011062000000100000000000000000000"

If you notice that the TargetProduct value of 0x1506 matches with the value we found earlier in the lsusb output after the reboot. Based on the contents of this file, we will now create a configuration file for the usb_modeswitch utility.

$ sudo vi /etc/usb_modeswitch.d/12d1\:14fe

# Huawei E303C 3G USB modem
# usb_modeswitch configuration
#
DefaultVendor=0x12d1
DefaultProduct=0x14fe

TargetVendor=0x12d1
TargetProduct=0x1506

MessageContent="55534243123456780000000000000011062000000100000000000000000000"

Configuring the Dialer

I will use wvdial utility for dialing out to the internet –

$ sudo apt-get install wvdial
$ sudo vi /etc/wvdial.conf
[Dialer Default]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
Baud = 460800
New PPPD = yes
Modem = /dev/ttyUSB0
ISDN = 0

[Dialer t24]
Modem Type = Analog Modem
Modem = /dev/ttyUSB0
ISDN = 0
Stupid Mode = 1
New PPPD = yes
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 = AT+CGDCONT=1, "IP", "T24.Internet"
Phone = *99#
Username = xxxxxxxxxx
Password = xxxxxxxxxx

[Dialer tatadocomo]
Modem Type = Analog Modem
Modem = /dev/ttyUSB0
ISDN = 0
Stupid Mode = 1
New PPPD = yes
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
#Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Baud = 115200
Phone = *99#
Username = internet
Password = internet

The xxxxxxxxxx in one of the configurations above is my 10 digit mobile number for the SIM. I tried this with two different SIMs, hence you are seeing two entries. T24 in India is a rebranded Tata Docomo mobile service provider.

Now connect to internet with one of the following (depending on which SIM has been connected –

$ wvdial t24

or

$wvdial tatadocomo

If you remove the USB dongle and then reconnect it, you may have to do the following in order to bring the device in the modem mode –

$ sudo usb_modeswitch -c /etc/usb_modeswitch.d/12d1\:14fe

Resources

Posted in RaspberryPi | Tagged | Leave a comment

Installing Oracle Instant Client for Mac OSX

I came across few links for installing Oracle Instant Client on Mac OS X namely – this and this. But I don’t like to tinker with the System paths while installing any s/w manually. I did the same with perl CPAN modules, I install them locally in home directory and same with Python pip packages, but that’s another post for future. So I had to work out the following method for installing the Oracle Instant Client as I needed sqlplus client for connecting to my RDS Oracle instance.

Download the following two files from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

instantclient-basic-macos.x64-11.2.0.4.0.zip
instantclient-sqlplus-macos.x64-11.2.0.4.0.zip

These will be downloaded in the Downloads directory

Unzip these two files in a single directory

$ cd Downloads
$ unzip instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
$ unzip instantclient-basic-macos.x64-11.2.0.4.0.zip
$ cd ~

Create the required structure in the home directory and copy the files in place

$ mkdir -p oracle/product/instantclient_64/11.2.0.4.0/{bin,lib,jdbc/lib,rdbms/jlib,sqlplus/admin,network/admin}
$ mv Downloads/instantclient_11_2/ojdbc* product/instantclient_64/11.2.0.4.0/jdbc/lib/
$ mv Downloads/instantclient_11_2/x*.jar product/instantclient_64/11.2.0.4.0/rdbms/jlib/
$ mv Downloads/instantclient_11_2/glogin.sql product/instantclient_64/11.2.0.4.0/sqlplus/admin/
$ mv Downloads/instantclient_11_2/*dylib* product/instantclient_64/11.2.0.4.0/lib/
$ mv Downloads/instantclient_11_2/*README product/instantclient_64/11.2.0.4.0/
$ mv Downloads/instantclient_11_2/adrci instantclient_11_2/genezi instantclient_11_2/sqlplus instantclient_11_2/uidrvci product/instantclient_64/11.2.0.4.0/bin/

Make the following additions to your ~/.bashrc file –

ORACLE_HOME="~/oracle/product/instantclient_64/11.2.0.4.0"
PATH=$ORACLE_HOME/bin:$PATH
alias sqlplus="DYLD_LIBRARY_PATH=$ORACLE_HOME/lib sqlplus"

Now I can connect to the Oracle RDS instance using –

$ sqlplus 'root@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ajitabh-oracle-test.bkl9a9lqwsoxcd.us-west-1.rds.amazonaws.com)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))'

SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 26 21:59:46 2015

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Enter password:

Connected to:
Oracle Database 11g Release 11.2.0.4.0 - 64bit Production

SQL>

That’s it. More on exploring Oracle RDS later.

Posted in Databases, Tips/Code Snippets | Tagged , , , , | Leave a comment

Expanding HardDisk of VirtualBox Guest

VirtualBox is a beautiful piece of virtualisation software created for users, first acquired by Sun and then by Oracle as a part of Sun acquisition. I have been using VirtualBox for quite a few testing projects, however until today have never needed to expand my hard drive on a guest. I am running a Windows 7 guest for some client side related tests. I started with a 25Gb disk for Windows 7, but after applying all security patches (I like my machines patched and upto-date), I realised that 25GB is all gone.

This is where I love virtualisation. I do not need to buy a new disk if I need more space on my virtual machine (as far as my physical disk has enough space). I can just expand the existing virtual hard disk and get all the space I need. VirtualBox does not yet have a GUI option to do storage expansion work, but fortunately VirtualBox comes with an excellent command line, so I followed the following steps in order to increase my hard drive space.

In order to see the virtual hard disk info, following command can be used.

$ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi
UUID: e2272600-df31-4dbc-a71d-56af5f5714df
Parent UUID: base
State: created
Type: normal (base)
Location: /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 25600 MBytes
Size on disk: 25502 MBytes
In use by VMs: Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)

To expand this to 50GB and then verify that the operation is done

$ VBoxManage modifyhd --resize 50000 VirtualBox\ VMs/Win764/Win764.vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi
UUID:           e2272600-df31-4dbc-a71d-56af5f5714df
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       50000 MBytes
Size on disk:   25502 MBytes
In use by VMs:  Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)

Now so far we have only been able to expand the Hard disk drive, but the partition table still would say that the NTFS filesystem is still the original size. However, we can not use Windows to expand the partition table of the same partition wherein it is installed. The System Rescue CD came to help here. I attached the System Rescue CD ISO to the windows virtual machine and booted the system.

In the command prompt, I used the GNU parted to expand the partition table (partition 2 in my case)

% parted resizepart 2 50GB /dev/sda

In case you want to check which is your NTFS partition, which you want to expand use the following command –

% parted print /dev/sda

After expanding the partition table, we need to expand the NTFS filesystem on it, which can be done by ntfsresize utility as below. First I ran the utility in info mode to find out the exact size to which to expand to and then in dry run (test) mode and finally actually ran it.

% ntfsresize --info /dev/sda2
% ntfsresize -n -s 52294093824 /dev/sda2
% ntfsresize -s 52294093824 /dev/sda2

Finally remove the the System Rescue CD ISO file and boot the system normally in windows, a check will be force and you are done.

Posted in FLOSS | Tagged , | Leave a comment

Kurukshetra by Ramdhari Singh ‘Dinkar’

Kurukshetra book coverKurukshetra is a poetic description of the analysis and after effects of a war. The poet has taken the Bhishma – Yudhishthir dialogue after the Mahabharat war was over in order to explain the effects of war.

After the war was over, Yudhishthir repents on the unjust caused by war. Yudhistir says that everybody understands the effects of war. The end result of every war is only destruction, but is it just to have enormous casualties for the selfish purpose of few.

“युद्ध को पहचानते सब लोग हैं,
जानते हैं, युद्ध का परिणाम अन्तिम ध्वंस है!
सत्य ही तो, कोटि का वध पाँच के सुख के लिए!”

Bhishm replies that nobody wants to get sick, but when the infection has already spread then their is no alternative other than treating it from root. He then explains that by itself no action is just or unjust. It is the internal feeling which makes it so.

“रुग्ण होना चाहता कोई नहीं,
रोग लेकिन आ गया जब पास हो,
तिक्त ओषधि के सिवा उपचार क्या?
शमित होगा वह नहीं मिष्टान्न से।

है मृषा तेरे हृदय की जल्पना,
युद्ध करना पुण्य या दुष्पाप है;
क्योंकि कोई कर्म है ऐसा नहीं,
जो स्वयं ही पुण्य हो या पाप हो।

Bhishm further explains that Lord Krishna explained it very well that the feelings of the actor are more important than the action itself. And it is important for one to separate oneself from the “Karma” and still continue doing that. He explains to Yudhishthir that although the prime duty of a human being is mercy and compassion. but  when the interest of the larger society is concerned we have to forget that prime duty. He then says that pardoning only suits the powerful people.

सत्य ही भगवान ने उस दिन कहा,
‘मुख्य है कर्त्ता-हृदय की भावना,
मुख्य है यह भाव, जीवन-युद्ध में
भिन्न हम कितना रहे निज कर्म से।'”

“व्यक्ति का है धर्म तप, करुणा, क्षमा,
व्यक्ति की शोभा विनय भी, त्याग भी,
किन्तु, उठता प्रश्न जब समुदाय का,
भूलना पड़ता हमें तप-त्याग को।

जो अखिल कल्याणमय है व्यक्ति तेरे प्राण में,
कौरवों के नाश पर है रो रहा केवल वही।
किन्तु, उसके पास ही समुदायगत जो भाव हैं,
पूछ उनसे, क्या महाभारत नहीं अनिवार्य था?”

“क्षमा शोभती उस भुजंग को,
जिसके पास गरल हो।
उसको क्या, जो दन्तहीन,
विषरहित, विनीत, सरल हो ?

Finally he explained the episode from Ramayan as mentioned below –

तीन दिवस तक पन्थ माँगते
रघुपति सिन्धु-किनारे,
बैठे पढते रहे छन्द
अनुनय के प्यारे-प्यारे।

उत्तर में जब एक नाद भी
उठा नहीं सागर से,
उठी अधीर धधक पौरुष की
आग राम के शर से।

सिन्धु देह धर ‘त्राहि-त्राहि’
करता आ गिरा शरण में,
चरण पूज, दासता ग्रहण की,
बँधा मूढ बन्धन में।”

About the Author

Ramdhari Singh ‘Dinkar’ was an Indian Hindi poet, essayist, patriot and academic. He is famous for his nationalist poetry written in the days before Indian independence. He was born on 23rd September 1908 and passed away on 24th April 1974)

Posted in Book Reviews | Tagged | Leave a comment