Saturday, December 26, 2015

Hotspot script for ubuntu

This script was tested on both Ubuntu 12.04


#!/bin/sh
# 20141208
# hotspot access point creation for android mobiles in ubuntu 12.04.4; works for laptop to laptop connection as well

zenity --warning --text "Run this script from terminal. \n ./hotspot_install. \n Close dialog box/ESC if you are running via terminal. Else click ok/ENTER."
if [ $? -eq 0 ]
then
    exit
fi

echo "Is ap-hotspot already installed (y/n) ? "
read ch
if [ "$ch" = "n" ]
then
    sudo add-apt-repository ppa:nilarimogard/webupd8
    sudo apt-get update
    sudo apt-get install ap-hotspot
fi


echo "Is ap-hotspot already configured (y/n) ? "
read ch
if [ "$ch" = "n" ]
then
    echo "configure your hotspot. give an access point name and good password"
    sudo ap-hotspot configure
    echo "delete all hotspot connection. Disconnect connected hotspots. Then Network -> Wireless -> Forget/Remove all hotspot. Then press any key to continue..."
    read key
fi

sudo ap-hotspot start

echo "Are you able to obtain ip address in your android mobile (y/n) ? "
read ch
if [ "$ch" = "n" ]
then
    echo "configuring network manager"
    sudo sed -i 's:^dns=dnsmasq:#dns=dnsmasq:gi' /etc/NetworkManager/NetworkManager.conf
    echo "restarting network manager"
    sudo service network-manager restart
    echo "check if following command does not say nameserver 127.0.0.1"
    cat /etc/resolv.conf
    echo "restarting ap-hotspot"
    sudo ap-hotspot stop
    sudo ap-hotspot start
fi

Friday, December 25, 2015

Ethernet wired connection not detected in Ubuntu 14.04

I have been using only wireless connection for a long time now. Finally a day has come for me to use wired ethernet connection.

Unfortunately, it was not getting detected at all.
The first command that comes to mind for checking connection....

ifconfig
The command didn't show "eth0".

ifconfig - a
This time it showed "eth0", but HWaddr  is all 0's. No valid physical address.


Well, this was the reason the wired connection was not getting detected.

Solution is to edit the rc.local file (/etc/rc.local)

Add these two lines before the "exit 0" line.

ifconfig eth0 hw ether 00:22:68:8f:09:e0
service network-manager restart


Restart and wired connection back.

Weirdly, the connection that got connected is "ifupdown (eth0)" instead of "Wired connection 1". Anyway, I just wanted it to work and that's done.

Wednesday, December 16, 2015

Getting started with Swift on Ubuntu 14.04

Download the swift 2.2 or later from Swift.org offical site.
Extract and set path to the binaries.

export PATH=${PATH}:~/swift-2.2-ubuntu14.04/usr/bin

assuming extracted folder is in home directory (indicated by ~/ ).
Try executing

$ swift --version

If you get error like
libstdc++.so.6: version `GLIBCXX_3.4.18' not found
execute the following commands.
 $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install libstdc++6-4.7-dev



Finally, verify if the swift is working.

$ swift --version
Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-unknown-linux-gnu



That's all. Enjoy programming in Swift.




Saturday, August 29, 2015

Installing JSHint on Ubuntu using npm


When I tried to install jshint on Ubuntu 12.04 using npm, I got errors. It simply didn't work.

If you are trying to use SublimeLinter-jshint for Sublime Text 3, it won't work unless you install 2 things:
1. node.js
2. jshint

Default version on repo for Ubuntu 12.04
$ /usr/bin/node --version
v0.6.12
$ npm --version
1.1.4

When you try
$ /usr/bin/npm install -g jshint
npm http GET https://registry.npmjs.org/jshint

npm ERR! Error: failed to fetch from registry: jshint
...
...
npm not ok


The important thing to note is you must have recent version to install it properly.

Solution

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository --yes ppa:chris-lea/node.js
$ sudo apt-get install nodejs
$ sudo apt-get update

Check the version to confirm once.
$ npm --version
1.4.28
$ node --version
v0.10.37

and finally...
$ sudo npm install -g jshint
/usr/bin/jshint -> /usr/lib/node_modules/jshint/bin/jshint

Success. It's now installed.

Now if you restart the Sublime text and start with any js file, you can see the jshint will hint you for warnings and errors.a

Thursday, August 27, 2015

Install pygame for python3 on Ubuntu 12.04



To install pygame for python3, do the following:

 1. Open up the terminal and type the following code:
     $ sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev

2. Then once all libraries are downloaded and installed:
     $ svn co svn://seul.org/svn/pygame/trunk pygame
     $ cd pygame
     $ python3 setup.py build
     $ sudo python3 setup.py install

Good to go. You can now run pygame with python3.

To test, open the terminal and try for yourself
$ python3
Python 3.2.3 (default, Jun 18 2015, 21:46:58)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>>

Saturday, August 22, 2015

Command to delete trailing white spaces in Sublime Text

After searching a while for how to replace trailing white spaces from the current document, I decided to go with my own method.

One simple way is to do regex replace.
ctrl+h
Find: [ \t]+$
Replace all [ctrl+alt+enter]

I wanted to do it via a keyboard shortcut. Here come "RegReplace" package to the rescue.

Hit ctrl+shift+p.
Install Package.
Search for "reg replace"
Install.

Now you can add new keybinding to you Keybindings-user file.
This is the keybinding.

{ "keys": ["ctrl+shift+t"], "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces"]}

}

Another  cool feature is that, we can just view the findings without replacing,
by setting "find_only": true.

{ "keys": ["ctrl+shift+t"], "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces"], "find_only": true}
 } 


After confirmation, you can press enter to replace all.

Saturday, August 15, 2015

Grub recovery : Recover the gnu linux boot menu after windows installation

If you happen to install any gnu/linux OS distros before Windows installation, the Windows makes itself start by default and the gnu/linux distro disappears from boot menu.

So, how to recover the grub ? It's pretty simple.
Use the Live CD/USB of gnu/linux distro, say, Ubuntu.

The steps mentioned below are tested on Ubuntu versions 11.04, 11.10 and 12.04.

--------------------------------------------------------------------------------------------

Open the Terminal and follow these steps:

theTechGeany:~$ sudo fdisk -l | more


Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4b2459d9

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        3053    24414208    7  HPFS/NTFS
/dev/sda3            3053       10456    59468800   83  Linux        <=====[Note sda<number> of THIS Partition.sda3 in my laptop]
/dev/sda4           10456       38913   228581217+   5  Extended
/dev/sda5           10706       20104    75497436    b  W95 FAT32
/dev/sda6           20105       29503    75497436    b  W95 FAT32
/dev/sda7           29504       38913    75585793+   b  W95 FAT32

Disk /dev/sdb: 4089 MB, 4089445376 bytes
126 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 7812 * 512 = 3999744 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00059dc3

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1022     3991901    c  W95 FAT32 (LBA)



theTechGeany:~$ sudo mount /dev/sda3 /mnt    <======[Use "Your" appropriate sda<number> here. sda3 in my system]



theTechGeany:~$ sudo grub-install --root-directory=/mnt /dev/sda
Installation finished. No error reported.



theTechGeany:~$ sudo update-grub                
# might get error. /usr/sbin/grub-probe: error: failed to get canonical path of `/cow`
# might get error. cannot find device for /
Solution (follow these only if you get any error)
        $ for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done    # mount you virtual filesystems

        $ sudo chroot /mnt (get into root and now install)
        # update-grub
It should run successfully.


Now Shutdown. Remove the Pen Drive/CD. Power On.
Grub Should be Corrected now and you can choose between the OS available.

Access Ext4 Hard Disk Format on Mac OS X


Install Fuse for OS X. Download and install 2.8.0 or above.
Download.

Install Fuse EXT-2.
Download

Now reboot the system.

EXT4 partitions will be mounted automatically.

Sunday, July 26, 2015

AutoComplete Geany Snippets

Do you give keywords for snippets and often end up forgetting the keywords itself. Instead of improving your coding speed, it just slows you down ! I will show you a cool method to auto-complete the parts of snippets. Once the keyword complete, you can press tab to get a snippet magic code appear on the editor.

You snippets.conf might look like this :

 Copy the code required to a new file and select the code
Format -> Send Selection to "file with the command". Here it is "convert_snippets_to_tag.bat"


This is actually the command to do the conversion which will be written in "convert_snippets_to_tags.bat"
Now the output will look like this.
 Copy this and paste it into the local copy of Geany tags folder.
It would be in C:\Users\<yourname>\AppData\Roaming\
geany\tags
Give the name of the file as, say,
<yourname>.html.tags

Reload the geany editor. Well, you will have the autocomplete for geany snippets working.

Now open any htm file and start typing for tags and you will get this


Now hit enter on the keyword required. Now the cursor at the end of keyword, press tab and the result is magic snippet code getting pasted on to the editor.

Enjoy. Happy coding fast using geany.

Remove empty lines using regular expression in Geany


There were few problems setting the keyboard shortcuts, context actions, search replace while running Geany editor on Windows OS.

One of the instances was to search replace empty lines while running Geany on windows. How to use regular expressions to remove empty lines ?
Well it's just simple, 
Search for: \n\n
Replace with: \n
To make it work on Windows where the line ending is CRLF and not just LF (line feed). The line ending has to set to unix style.

Document -> Set Line Endings -> Convert and Set to LF (Unix)
 Now,
Search for: \n\n
Replace with: \n
Also check the multi-line matching in search replace dialog.


This should work well.