Friday, November 15, 2024

Installing IBC (Interactive Broker Controller)

 This is a nice utility to keep ibkr TWS running. These are the commands :

$ wget https://github.com/IbcAlpha/IBC/releases/download/3.20.0/IBCLinux-3.20.0.zip

$ sudo unzip IBCLinux-3.20.0.zip -d /opt/ibc

$ sudo chmod o+x /opt/ibc/*.sh /opt/ibc/*/*.sh

$ cat ~/ibc/config.ini

     IbLoginId=<username>

     IbPassword=<password>

$ rm IBCLinux-3.20.0.zip

Friday, September 6, 2024

New Linux installation checklist

  • sudo apt install ~/Downloads/google-chrome-stable_current_amd64.deb
  • sudo apt-get install gnome-browser-connector
  • sudo apt install libreoffice
  • sudo apt install git-all
  • ssh-keygen -t rsa
  • sudo snap install code
  • sudo apt install python3-venv
  • python3 -m venv ~/.venv/ibkr_python

  • https://extensions.gnome.org/extension/1160/dash-to-panel/
  • settings -> ungroup applications
  • settings -> system -> date/time -> show weekday

  • Install vscode, extensions- python

Tuesday, September 3, 2024

git commands

Following are basic git commands which should be sufficient for most of the git use :

git fetch
git pull
git commit
git push

Security cameras from desktop

 Need to install ffmpeg in order to access rstp streams

* sudp apt install ffmpeg

Once it is installed, you can access the cameras via

* ffplay rtsp://hpatil:<pass>@<ip_address>:554/stream1

Monday, August 26, 2024

More than one ssh key for the github

 * Generate new key:

[18:05:20 harsshal@dell:~/projects]$ ssh-keygen -t ed25519 -C "harsshal@gmail.com"

* Add new key in the ssh config

[18:07:35 harsshal@dell:~/projects]$ cat ~/.ssh/config 
TCPKeepAlive yes

Host 10.234.1.112
  HostName 10.234.1.112
  User harshal

# Default GitHub
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-public
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519.pub

Host github-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519

* Clone the repo

[18:09:02 harsshal@dell:~/projects]$ git clone git@github-personal:harsshal/icarus_gl.git

Friday, July 5, 2024

Jupyter notebook setup

jupyter notebook --notebook-dir [LOCATION] --no-browser

Monday, June 3, 2024

Installing a module directly from repo

pip install git+https://github.com/blampe/IbPy.git

pip install git+https://github.com/atreyuxtrading/atreyu-backtrader-api.git

Friday, July 15, 2022

command line / bash variable in awk command

 This is how we use a command line / bash variable (named num) in a awk command. We define an awk  variable 'var' with -v option. This also shows use of BEGIN block.

awk -F, -v var=$num 'BEGIN{srand(var)} {print $1","$2","rand()}' file_name 

Sunday, July 3, 2022

Change nameserver entries in resolve.conf

 We can directly change the contents of the file but they dont seem to be in effect. So I added Google's nameserver in the file as follows : 


$ sudo cat /etc/resolvconf/resolv.conf.d/base 

nameserver 8.8.8.8

nameserver 8.8.4.4


And then updated the file as follows : 


$ sudo resolvconf -u 


we can also just update /etc/resolve.conf and it will be in effect immediately.

$ sudo sed -i '1 i\nameserver 8.8.8.8\nnameserver 8.8.4.4' /etc/resolv.conf 

To remove the changes :

$ sudo sed -i '1,2d' /etc/resolv.conf 

Wednesday, June 22, 2022

renaming all the files in a folder

 IF we want to rename all the files with a part of the file we can do something following:

for file in $(ls); do nn=$(echo $file | awk -F'_' '{print($2)}'); mv $file $nn; done

Friday, March 11, 2022

shell loop through dates

 Easy command to loop through the dates : 

for i in 2022-01-{01..31} 2022-02-{01..15}; do echo $i; done


More comprehensive command :

d=2015-01-01 while [ "$d" != 2015-02-20 ]; do echo $d d=$(date -I -d "$d + 1 day") done

Tuesday, October 27, 2020

tp-link archer t3u on ubuntu

Recently got tp-link T3u mini wifi adapter  but as usual ubuntu did not have its drivers. So executed following commands and it worked perfectly. 

cd /opt 
git clone https://github.com/cilynx/rtl88x2bu.git 
cd rtl88x2bu
VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf)
sudo rsync -rvhP ./ /usr/src/rtl88x2bu-${VER}
sudo dkms add -m rtl88x2bu -v ${VER}
sudo dkms build -m rtl88x2bu -v ${VER}
sudo dkms install -m rtl88x2bu -v ${VER}
sudo modprobe 88x2bu

Monday, October 26, 2020

sudo access to ldap user

 Typically, if you dont have sudo and "gain" sudo access, you cant just add yourself to sudo group. In that scenario, we need to reboot in "advanced mode" and gain access to root shell. Once in, you can have following : 

$ sudo cat /etc/sudoers.d/hpatil 

hpatil ALL=(ALL) ALL

and then we will have sudo access. 

Thursday, February 20, 2020

Bootable USB

In case your laptop has good old booting system and not advanced system like UEFI, you can use following command to create bootable USB. In case your laptop is fancy, you will have to use software like Rufus which works only on amazing windows.

sudo dd bs=4M if=~/Downloads/ of=/dev/sdc1 status=progress oflag=sync
you can find out /dev/sdc1 via df command.

Highlight mouse with win + F5

When you have multiple monitors, and we need to search for a mouse, it becomes difficult to see where its hiding. Windows had a good feature to highlight mouse when you press Ctrl, but linux typically dont have that. So I used following workaround to achieve same effect in i3.

sudo apt install libx11-dev libxcomposite-dev libxdamage-dev libxrender-dev
mkdir ~/git
cd git
git clone https://github.com/Carpetsmoker/find-cursor.git
cd find-cursor
make
echo "bindsym $mod+F5 exec /home/maahi/git/find-cursor/find-cursor -of" >> ~/.config/i3/config

docker commands

A while ago, I was playing around with docker. Here is the collection of all the commands I used. I used following to install dockers:

sudo echo 'deb https://apt.dockerproject.org/repo debian-stretch main' > /etc/apt/sources.list.d/dockertemp.list
sudo apt-get update
sudo apt-get install docker-engine
sudo rm /etc/apt/sources.list.d/dockertemp.list sudo service docker start
 Once installation was done, these were basic commands I used :

https://sakuli.readthedocs.io/en/v1.0.0/docker-containers/
sudo docker pull harsshal/tws:first
sudo docker run -it -p 5901:5901 -p 8000:6901 harsshal/tws:first
sudo docker run -it -p 5901:5901 -p 8000:6901 -exec -u 0 harsshal/tws:first /bin/bash
sudo docker run -it -p 5901:5901 -p 8000:6901 -e "VNC_PW=ibtrader" harsshal/tws:first
sudo docker ps -a
sudo docker start
sudo docker commit harsshal/tws:second
sudo docker push harsshal/tws:second
sudo docker images
sudo docker ps -a | awk '{print $1}' | xargs sudo docker rm

Monday, December 16, 2019

Display all dataframe lines in python

Sometimes when you want to see all lines in ipython, either in IDE or in notebook, it wont show you because of in-build options. Here are those options, in case you want to change that :

import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

Wednesday, December 4, 2019

Vertica creating a temporary list of numbers

I just wanted to quickly check what is the behavior of NULL in analytics functions like median.
So rather than creating a table, I  wanted to pass a list of numbers and see what happens. This is how I achieved it :

SELECT median(val) over() FROM (
SELECT * from (SELECT 1 as val, 1 as row
UNION SELECT 2, 2
UNION SELECT NULL,3
UNION SELECT NULL,4
UNION SELECT 4,5)temp
)temp2;

Tuesday, December 3, 2019

Show all columns in ipython

In few scenarios, when you are in ipython or notebook, you want to see all the columns and not truncated list. For that, we need to execute these commands :

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

Thursday, November 7, 2019

i3 layout reload configuration

Recently started playing around with i3. I liked it so far. It can open all the applications where you need after a restart. After learning how to split the screens etc, get to your desired configuration. Once fixed, execute following : 

i3-save-tree > i3.json
We need to edit json file so that "class" entries in "swallows" sections are un-commented.

Enter following in config "~/.config/i3/config" :

exec load_i3_layout.sh
Where as contents of the shell scripts are :

i3-msg 'workspace 1; append_layout i3.json'
i3-msg 'exec /usr/bin/chromium-browser'
i3-msg 'exec /usr/bin/dbeaver'
i3-msg 'exec /snap/bin/pycharm-community'
i3-msg 'exec /usr/bin/nautilus'
i3-msg 'exec /usr/bin/gnome-terminal'
i3-msg 'exec /usr/bin/chromium-browser'
This will open up all the windows at your needed locations.

Friday, October 12, 2018

awk delimiters

I have been using awk for a while and I had a use case where I wanted to use multiple delimiter, ' ' being one of them.
If its just space, we can use :
awk -F' ' '{print $2}'
If its bunch of characters, we can use :
awk -F'[.:]' '{print $2}' 

But with space, we need to use as follows :
awk -F'[[:space:].]+' '{print $2}'

I have not been able to figure out to associate '+' only to space. But for now this will server the purpose as long as I can combine multiple '.'

Some other classes are:
[[:blank:][:cntrl:]] 
[ \t,:;]

Tuesday, September 25, 2018

Python notebook shortcuts

Recently started using a lot of notebook and keep struggling to remember shortcuts. So posting here so that I'll remember few important ones.


Ctrl + Enter : Execute current cell
Ctrl + / : multi-line comment
Ctrl + Shift + - : Split cell
Shift + m : Merge cells
a : Above current cell, create a cell
b : Below current cell, create a cell

Saturday, September 15, 2018

Linux mint suspend after more than 1 hour

Trying to determine ideal time for suspending the machine but found that maximum time Linux mint allows before it can suspend the machine is 1 hour. After researching a bit, found that we can extend this time. These are the commends :

  1. sudo apt-get install dconf-editor
  2. Open Menu->dcong-editor
  3. In dconf-editor, org > cinnamon > settings-daemon > plugins > power and manually set the value for the "sleep-inactive-ac-timeout" (it's in seconds)

Thursday, March 29, 2018

Installing new packages behind proxy



There are 2 main ways to do this :

pip install pandas
python -m pip install pandas --proxy proxy..com:3128

Second option has many other parameters which can be passed.

For installing via notebook, we can do as follows :

import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip list --user 

Wednesday, March 14, 2018

Converting screen into tmux ( terminal multiplexer )

We have beutiful program called
tmux
which allows us to see multiple terminal windows at the same time. We can covert screen in doing something similar.

To split vertically: ctrl + a then |.
To split horizontally: ctrl + a then S (uppercase 's').
To unsplit: ctrl + a then Q (uppercase 'q').
To switch from one to the other: ctrl + a then tab

We can save layouts in screenrc so that we wont have to keep doing this as well.

Friday, February 23, 2018

Shell keyboard shortcuts


On Linux shell, imagine you are executing a long command and then you remember that you need to execute other command first.

Just found out an awesome feature where you can put a command in buffer (Ctrl+U), execute another command and then retrieve the buffer(Ctrl+Y).

Awesome!

Of course, Ctrl+A (Ctrl+A+A when you are in screen) to take you to the start of the line and Crtl+E to take you to end of the line.

Thursday, September 14, 2017

Linux mint buzzing sound when using headphones

I had annoying buzzing sound coming in from speakers whenever I used to insert headphones. After few trial and errors I found following solution :

  • Open terminal and type
Alsamixer 
  • After that select the sound card (usually PCH)
  • Go to far right until optiona
Auto-mute mode 
  • press up arrow to make it disabled.  

Sunday, March 26, 2017

sqllite commandline history via up/down keys

I found very annoying problem with sqlite CLI. When you press up/down arrow keys, it prints ASCI characters of the keys rather that showing historical commands. When I googled, I realised that we can either link readline library when compiling sqlite or do:
sudo apt-get install rlwraprlwrap sqlite3 database.db
worked like a charm for me.

Saturday, March 18, 2017

increasing brightness on LXDE display on lubunut

LXDE seems to have 2 brightness controls. Both of them are found in locations: /sys/class/backlight/

For me it was :

harsshal@dell:~$ ll /sys/class/backlight/ 
lrwxrwxrwx  1 root root 0 Mar 18 12:58 acpi_video0 -> ../../devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/lrwxrwxrwx  1 root root 0 Mar 18 12:58 intel_backlight -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-LVDS-1/intel_backlight/


Both locations have max_brightness file :

harsshal@dell:~$ ll /sys/class/backlight/*/max_brightness -r--r--r-- 1 root root 4096 Mar 18 12:58 /sys/class/backlight/acpi_video0/max_brightness-r--r--r-- 1 root root 4096 Mar 18 12:58 /sys/class/backlight/intel_backlight/max_brightness

harsshal@dell:~$ cat /sys/class/backlight/*/max_brightness 7255000
So typically intel_backlight will be controlled by all your default brightness controller, but acpi_video0 will need manual changes when you need to change it:
harsshal@dell:~$ echo 7 | sudo tee /sys/class/backlight/acpi_video0/brightness 7
Other methods of increasing brightness :

harsshal@dell:~$ xbacklight -set 60
Or

harsshal@dell:~$ xrandr -q | grep -w connectedLVDS-1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 290mm x 180mmharsshal@dell:~$ xrandr --output LVDS-1 --brightness 1

Wednesday, March 1, 2017

startup scripts in windows to keep screen active

I wrote a script to keep my comupter not get locked. script goes as follows:
set WshShell = WScript.CreateObject("WScript.Shell")

x = 1

do while x = 1 'Loop forever and ever and ever and ever

WshShell.SendKeys "%^" 'SEND CTL + ALT

WScript.Sleep 290000 '<5 MINS

loop

I placed this script at location C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
and no more locking up the screen....

Tuesday, February 28, 2017

Adding right click options

I add my custom scripts to perform certain actions via right-click. To achieve that, we need to do following :
vim ~/.gnome2/nautilus-scripts/terminal
For nemo, we need to have scripts at following locations:

/usr/share/nemo/actions/ for system-wide actions
$HOME/.local/share/nemo/actions/ for user actions

Type the command you want to have after right click. In this example, I do :
gnome-terminal
And make that script executable:
chmod a+x ~/.gnome2/nautilus-scripts/terminal

Friday, January 6, 2017

Citrix receiver on linux version LUbuntu

Started my new year by installing Lubuntu on my old dell laptop. Usually I install via USB, so prepared USB again via
usb-creator-gtk
on my previous installation of linux mint.
Installation always used to hang on certain point on installer and could not figure out why. After googling, came to know that it needs network during installation but does not give any error. So connected LAN cable and got it installed.

First task was to make sure that no issues when connecting to office network. I installed receiver from

https://www.citrix.com/downloads/citrix-receiver.html

After installation, logged in and got an verisign ssl error. So did
sudo cp /usr/share/ca-certificates/mozilla/* /opt/Citrix/ICAClient/keystore/cacerts
One issue is chrome does not open citrix application right away. I need to open it via command line by executable located at
/opt/Citrix/ICAClient/wfica

Friday, May 22, 2015

Creating python executables

I needed to create python executable so that people wont have to rely on my python version.
So these are the steps:
# Install "cx_Freeze"
# Create setup.py
$catsetup.py 
from cx_Freeze import setup, Executable
build_exe_options = {
"includes": ['numpy', 'pandas','matplotlib.backends.backend_qt4agg'],
"packages": [],
"excludes": ['tk','ttk','zmq','boto','tkinter','_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger','pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter'],
"include_files": []}

setup(
    name = "appName",
    version = "0.1",
    description = "",
    author = "Dengar",
    options = {"build_exe": build_exe_options},
    executables = [Executable("sectorize.py")]
)
#python setup.py build

Tuesday, May 19, 2015

Alt+Tab not working in remote desktop of citrix receiver on Linux mint 17

I use citrix to connect to office computer. But Alt+Tab wasn't seem to be working when I used remote desktop. I found few solution about HKEY edit solution for windows, but none for linux mint. I did some trial and error and finally found a solution myself.

I found this file in installation directory of ICAClient:

[17:43:43 harsshal@lenovo:~]$ ll /opt/Citrix/ICAClient/config/All_Regions.ini

lrwxrwxrwx 1 root root 37 Nov 8 2013 /opt/Citrix/ICAClient/config/All_Regions.ini -> /etc/icaclient/config/All_Regions.ini
Went to link and started edited this file

[17:44:08 harsshal@lenovo:~]$ sudo vim /etc/icaclient/config/All_Regions.ini

Search for "TransparentKeyPassthrough" in "Virtual Channels" section and add "Remote" in front of it.

[Virtual Channels\Keyboard]
TransparentKeyPassthrough=Remote

Save and restart Remote Desktop Connection

Wednesday, April 8, 2015

Google CodeJam in python templates

I recently started learning python and designed these programs.

Following program is for http://code.google.com/codejam/contest/351101/dashboard#s=p2


 # -*- coding: utf-8 -*-
"""
Created on Tue Apr  7 15:40:09 2015

@author: hpatil
"""

import sys

def read_file( input_file, output_file):
    sys.stdin = open(input_file)
    if(output_file != '' ):
        sys.stdout = open(output_file,"w+")
    read_input()

def solver(line):
    last_digit=10
    for i in line:
        #print(i)
        #print(len(line))
        digit, mystring = digit2string(i)
        if(last_digit==digit):
            print(' ',end='')
        print(mystring,end='')
        last_digit=digit
    print()
    return

def digit2string(char):
    dial = [
        [' '],
        [],
        ['a','b','c'],
        ['d','e','f'],
        ['g','h','i'],
        ['j','k','l'],
        ['m','n','o'],
        ['p','q','r','s'],
        ['t','u','v'],
        ['w','x','y','z'],
    ]
    mystring = ""  
    for digit in range(len(dial)):
        for repeat in range(len(dial[digit])):
            if(char==dial[digit][repeat]):
                for times in range(repeat+1):
                    mystring+=str(digit)
                return digit,mystring
  
  
def read_input():  
    with sys.stdin as file:
        testCases = int(file.readline())
        for test in range(testCases):
            print("Case #{}: ".format(test+1), end="")
            line = file.readline().strip('\n')
            solver(line)

#read_file('input','')
read_input()


This one is for with integer reading for http://code.google.com/codejam/contest/351101/dashboard


# -*- coding: utf-8 -*-
__author__ = 'hpatil'

import sys

def show_graph(x,y):
    import matplotlib.pyplot as plt

    plt.plot (x, y)
    plt.grid(True)
    plt.show()

def solver(credit, nItems, items):
    for i in range(nItems):
        for j in range(i+1,nItems):
            sum = items[i] + items[j]
            if( sum == credit):
                print(i+1,j+1)
                return

def set_io( input_file, output_file):
    sys.stdin = open(input_file)
    sys.stdout = open(output_file,"w")
   
def read_input():   
    with sys.stdin as file:
        testCases = int(file.readline())
        for test in range(testCases):
            print("Case #{}: ".format(test+1), end="")
            credit = int(file.readline())
            nItems = int(file.readline())
            items = list(map(int,file.readline().split()))
            show_graph(range(len(items)), items)
            solver(credit, nItems, items)

set_io('input','out')
read_input()

Following program is for http://code.google.com/codejam/contest/3214486/dashboard which took me a loooooong time

# -*- coding: utf-8 -*-
"""
Created on Wed Apr  8 13:08:15 2015

@author: hpatil
Solution to problem : http://code.google.com/codejam/contest/3214486/dashboard

"""

lit = [
        #['abcdefg']
        '1111110',
        '0110000',
        '1101101',
        '1111001',
        '0110011',
        '1011011',
        '1011111',
        '1110000',
        '1111111',
        '1111011'
    ]


def display_calci(string):
    if(string=="ERROR!"):
        print(string)
    else:
        display = list("         ")
        print(''.join(display))
        # line 1
        if(string[5] =='1'):
            display[0]='|'
        if(string[0] =='1'):
            display[1]='^'
        if(string[6] =='1'):
            display[2]='_'
        if(string[1] =='1'):
            display[3]='|'
        display[4]='\n'
        if(string[4] =='1'):
            display[5]='|'
        if(string[3] =='1'):
            display[6]='_'
            display[7]='_'
        if(string[2] =='1'):
            display[8]='|'
        print(''.join(display))

def isDigitFeasible(active, disp_digit, digit):
    for led in range(7):
        if(active[led]=='1'):
            if( disp_digit[led] != lit[digit][led]):
                return 0
    return 1

def get_active_leds(active, disp_digits):
    active= list(active)
    count = int(disp_digits[0])
    for digit in range(1,count+1):
        for led in range(len(disp_digits[digit])):
            if(disp_digits[digit][led]=='1' ):
                active[led]='1'
    return ''.join(active)

def led_unused(active, disp_digits, possible_digit):
    not_used = list('1111111')
    active= list(active)
    count = int(disp_digits[0])
    for digit in range(1,count+1):
        possible_digit= (possible_digit+1)%10
        for led in range(len(lit[possible_digit])):
            if(lit[possible_digit][led]=='1' ):
                not_used[led]='0'
    return ''.join(not_used)

def print_digit(active, disp_digits, digit):
    result_string = ""
    unused = led_unused(active, disp_digits, digit)
    for led in range(len(active)):
        if(active[led]=='1'):
            result_string += lit[digit][led]
        else:
            if(lit[digit][led] == '1'):
                if(unused[led]=='1'):
                    return "ERROR!"
                else:
                    result_string += '0'
            else:
                result_string += '0'

    return result_string

def get_possible_digits(active, disp_digit, possible):
    possible_return = [ ]
    for digit in possible:
        if(isDigitFeasible(active, disp_digit, digit)):
            possible_return.append(digit)
    return possible_return

def solver(disp_digits):
    active= list('0000000')
    active = get_active_leds(active,disp_digits)
    if(debug):
        display_calci(active)
    count = int(disp_digits[0])
    possible = [9,8,7,6,5,4,3,2,1,0]
    for digit in range(1,count+1):
        possible = get_possible_digits(active,disp_digits[digit], possible)
        possible = list(map(lambda x: (x-1) % 10, possible))
    if(debug):
        print(possible)
    possible_soln = list(map(lambda x: print_digit(active,disp_digits,x), possible))
    if(debug):
        print(possible_soln)
    soln_set = set(possible_soln)
    if(len(soln_set) != 1):
        return "ERROR!"
    else:
        return list(soln_set)[0]

def read_input():
    with sys.stdin as file:
        nTests = int(file.readline())
        for tests in range (1, nTests+1):
            print("Case #" + str(tests)+": ", end="")
            disp_digits = file.readline().split('\n')[0].split(' ')
            if(debug):
                print(disp_digits[1:])
                list(map(lambda x: display_calci(x), disp_digits[1:]))
                print("-----------")
            answer_string = solver(disp_digits)
            if(debug):
                display_calci(answer_string)
            print(answer_string)

import sys
debug = int(sys.argv[1])
sys.stdin = open (sys.argv[2])
#sys.stdin = open ('input2')
#sys.stdin = open ('A-small-practice.in')
#sys.stdin = open ('A-large-practice.in')

read_input()

Friday, March 6, 2015

Wake on by USB devices on Linux mint 17

I am back after a looooooong time... after my firm started supporting RDP from Linux again. I tried Linux mint 17 on my old laptop and attached external Samsung monitor to it. I stopped using monitor of laptop completely. So wanted laptop to go to sleep and wake up without actual power buttons on it.

I realized that Linux mint doesn't support wake on USB mouse / keyboard out of the box. so I created following file and it started supporting wake on USB devices again.


[01:35:11 harsshal@dell:~]$ cat /etc/udev/rules.d/90-keyboardwakeup.rules #idVendor and idProduct taken from 'lsusb' SUBSYSTEM=="usb", ATTRS{idVendor}=="0461", ATTRS{idProduct}=="4d15" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'" SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="2002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'" SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="1002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"

PS: When I rebooted machine, for some reason, my idProduct was changed. So if these don't work after reboot, make sure numbers are correct using "lsusb" again.

Wednesday, November 28, 2012

ctrl+left/right arrow by inputrc

Suddenly my Ctrl+left arrow and Ctrl+right arrow stopped working for navigating word-by-word and it had become eally annoying. I still dont know the root cause. But I found following :

1. On your console, press Ctrl + v - Ctrl + RightArraow.  It should either print ^[0D or ^[[D.
2. Replace initial "^[" by "\e" and put it in ~/.inputrc as follows

  "\e[D": forward-word

3. Restart session or press Ctrl x - Ctrl r . Confirm binding by

  bind -P

Make sure your "env" has TERM=linux. (Putty -> Connection -> Data -> terminal-type string= linux)

Final ~/.inputrc should look like :

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line # Home key
"\e[4~": end-of-line # End key
"\e[5~": beginning-of-history # PageUp key
"\e[6~": end-of-history # PageDown key
"\e[3~": delete-char # Delete key
"\e[2~": quoted-insert # Insert key
"\eOD": backward-word # Ctrl + Left Arrow key
"\eOC": forward-word # Ctrl + Right Arrow key

Monday, October 15, 2012

Tabbed vim

I always felt like we should have tabs in vim so that I wont have to split screen using "vim -O option / ":vs". I just found that we can use tabs.

 vim -p < file1 > < file2 >

You can see that you can open multiple files and go to next file without saving (something you cannot do in multiple buffer). Youcan switch between files using tabn/tabp, but I do it as follows and use F5/6.

 :map <f5> :tabp <cr>
 :map <f6> :tabn <cr>

Thursday, May 10, 2012

Shell commands in VIM

If we need to execute a shell command on currently opened file in VIM, we can do following

  :%! sed G          Double space the entire file.
  :1,5! sed G        Double space the lines from 1-5.

Sunday, April 1, 2012

Downloading flash videos in ubuntu

Here is a modified version of a online script I found to download videos. Online script download everything which is a clutter because it has many flash ads too.

$ cat ~/Dropbox/new_installation/scripts/flash_vid.sh
#!/bin/bash
num=1;
for FILE in $(lsof -n | grep "Flash.*deleted" | awk '{printf "/proc/" $2 "/fd/"; sub(/[a-z]+/,"",$4); print $4}'); do
cp $FILE $HOME/Desktop/$num.flv
size=$( stat -c %s $HOME/Desktop/$num.flv);
if [ $size -gt 5000000 ]; then
num=$[$num + 1];
else
rm $HOME/Desktop/$num.flv;
fi
done

Thursday, March 15, 2012

CVS important commands

cvs add < filename >
cvs commit -m "my comment < filename >
cvs update < filename >

cvs -j < what version you want cvs to think it has > -j<what version you want cvs to go to > < filename >

Tuesday, March 13, 2012

linux commandline mail from shell as attachement

There are few ways to do this. Here are some :

(cat mailtext; uuencode surfing.jpeg surfing.jpeg) | mail sylvia@home.com
uuencode $ATTFILE $ATTFILE | mail -s "$SUBJECT" $MAILTO
echo "hi" | mutt -a $ATTFILE -s "$SUBJECT" $MAILTO

Tuesday, November 22, 2011

mysqldump

Transferring data between two tables/two databases can be achieved by

insert into table1 select * deom database2.table2;

But they are not on the same host you can use following :

$ mysqldump -h host_name -u user_name -p database table_name "--where= date = 20111121" > temp

We can use "-t" option which will exclude table creation definition from the output.

Thursday, September 1, 2011

Finding latest modified file/directory

Another useful command

$ find . -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1

$ for i in `ls`; do echo -n $i" "; find $i -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1;done

Sunday, August 14, 2011

Mysql Tricks

  • How to get current time
select now();
select curdate();
select curtime();


  • How to get date in standard format

select date from table;

will give answer as "2011-08-15"
But

select date+0 from table;

will give answer as "20110815"

  • To use group by with a summary.


select col from .... group by col with rollup;

This will give a summary(addition) in the last row.

  • When performing string operations


Shell "*" => mysql "%"
Shell "?" => mysql "_"


  • Conditional statements in mysql


select (sum(case when shares>0 then shares else - end) from table;

  • Case-sensetive comparison
select 'A' like 'a';
1
select 'A' like binary 'a';
0


  • Using variables

set @total=0;select (@total := 2+@total) as total from table;

  • Checking table sizes


select table_schema "Database name", sum(data_length _ index_length)/1024/1024 "size", sum (data_free)/1024/1024 "Free space " from information_schema.TABLES group by table_schema;

  • Command line execution and output
bash# mysql -e "select * from table";
mysql> select * into outfile "/tmp/hpatil" from ...;

But watchout for mysqld host and users when searching for outfile on commandline.

Thursday, July 14, 2011

Linux/Unix NFS bug

Sometimes it seems that we are not able to 'touch' the file becaue of error "already exists", but we try to delete it we get an error "file does not exists".

To solve this issue,
We need to create a temp file.
mv to original file
and then delete this file.

Now, we will be able to create a new file in same location.

Friday, July 8, 2011

Finding database size through mysql query


SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

My bashrc

This is a initial setup. You can work on things similar to these.





PATH=$PATH:.:~/hpatil/0/
export EDITOR=/usr/bin/vim

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
PS1="[\t \u@\h:\w]$ "
export HISTSIZE=10000
export HISTCONTROL=erasedups
shopt -s histappend

BC_ENV_ARGS=~/.bcrc
export BC_ENV_ARGS
export INPUTRC=~/.inputrc

#alias vim="vim -c 'set nopaste'"
alias ll="ls -l"
alias rl="readlink -f"
alias vim='vim -c"set nopaste" '
alias vr='vim -MR -c"set nopaste" '

alias li='less -niFX'


alias grep_dir='_(){ bd;grep -a "mt=j" app.$1.tlog | grep -av "not active" | li;}; _'

Tuesday, June 28, 2011

Setting autofs timeout option

This is the time after which autofs will unmount the volume if kept idle. It can be set in file /etc/sysconfig/autofs.

OPTIONS="--timeout=86400"

Friday, June 24, 2011

Compression bzip2 command

Good and simple compression command

find ./04 -type f | grep -v bz2 | xargs bzip2

Friday, April 30, 2010

Best way to get IE on ubuntu

I was doing web development(???) and I needed to check page on IE. so this is what I found out.

sudo apt-get install wine
sudo apt-get install cabextract
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-2.99.0.1.tar.gz
tar xzvf ies4linux-2.99.0.1.tar.gz
./ies4linux-2.99.0.1/ies4linux
ln /root/bin/ie6 /usr/bin/ie6
ie6


And nice IE for testing...

Tuesday, April 27, 2010

popup=popup, not popup=newtab

For some reason or other, Firefox does not have the option under the Tabs option items to “force links that open in new windows to open in:”. I have Firefox 2.0.0.7 now, and I don’t have that under Tabs options. But, if you open about:config in your address bar, you can change the setting manually.

Change:
browser.link.open_newwindow

Mine was set to 3, which told the popups to always open in a new tab. I like that, mostly. But some web sites, TinyMCE editor in this case, like to open a popup and return you back the the original page. I keep losing that original popup. So I wanted to turn off my popup forced to new tab option. To make this behave normally, I set it to 2. All worked just peachy!

Monday, April 19, 2010

Disabling touchpad while typing


cat >> /etc/hal/fdi/policy/shmconfig.fdi << END
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="input.x11_driver" string="synaptics">
<merge key="input.x11_options.SHMConfig" type="string">True</merge>
</match>
</device>
</deviceinfo>
END


In start-up programs, add command

syndaemon -i 1 -d


and reboot!!!

Thursday, April 15, 2010

Listing files by decreasing directory size / space left

Nautilus doesn't give you total size of folder. It just gives the number files in the folder.
If you want to see how is your disk being used, you can use

du -s * | sort -k 1 -rn

If you want to see hidden files,

du -s .* | sort -k 1 -rn

Unfortunately, I couldn't combine both of them and also couldn't use -h option of du
If you want to see size of different partition, you can also use

df -h

Monday, April 12, 2010

Removing ^M from end of the line in VI

To remove the ^M characters at the end of all lines in vi, use:

:%s/^V^M//g

The ^v is a CONTROL-V character and ^m is a CONTROL-M. When you type this, it will look like this:

:%s/^M//g

In UNIX, you can escape a control character by preceding it with a CONTROL-V. The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).

Friday, April 2, 2010

Invisible plugin in pidgin

Want to become invisible in pidgin??

wget http://fahhem.com/pidgin/gtalkinvisible.tar.gz
tar -vxf gtalkinvisible.tar.gz
mv gtalkinvisible/gtalkinvisible.so ~/.purple/plugins/
rm -rf gtalkinvisible*

Friday, March 26, 2010

Changing base of a number

Suppose we want to convert 0xFACE into decimal value.


echo "ibase=16; obase=A; FACE" | bc


'ibase' is input number base.
'obase' is output number base in ibase number.(10 is A in hexadecimal format).
'FACE' is the number.

when we dont specify any of the value, its assumed to be 10.

Saturday, February 27, 2010

Linux or UNIX password protect files

Suppose you want to protect file pwd.txt

gpg -c pwd.txt

This will ask you to set new password and create a file called pwd.txt.gpg
Now you can delete pwd.txt.

If you want to retrieve pwd.txt, you can say

gpg pwd.txt.gpg

and it will ask you to enter password and create pwd.txt

Monday, February 22, 2010

Keep Firefox Open When Closing the Last Tab

The new Firefox 3.5 release brought a lot of great features, but one annoyance sent reader Mark looking for a solution: When you close the last tab, the browser closes instead of opening a blank tab.

Changing the behaviour back to the way it used to work is very simple: just type about:config into the address bar and find the browser.tabs.closeWindowWithLastTab entry in the list—using the filter makes it easy. Once you've found that key, double-click on it to change the value from true to false, and Firefox should no longer close when you close the last tab.

Sunday, February 21, 2010

Disabling selinux

Temporary disabling.

echo 0 >/selinux/enforce


Permanent disabling.

vim /etc/selinux/config

.. just change SELINUX=enforcing to SELINUX=disabled, and you're done.
Or we can also change /boot/grub/grub.conf.
On the kernel line of current distribution, add enforcing=0 at the end.

Tuesday, February 2, 2010

New wallpaper script

New wallpaper script. This had been on my mind for a long time. Using this we can change wallpaper any-time, unlike previous one in which we could change only once per day.


cat >> ~/Dropbox/new_installation/wallpaper/mast/wall.sh << END
folder="Dropbox/new_installation/wallpaper/mast/"
rm -f ~/$folder/*.jpg

limit=`wc -l < ~/$folder/list`
my_number=`expr $RANDOM % $limit`
name=`tail -n $my_number ~/$folder/list| head -n 1`

wget -O ~/$folder/pics_list http://www.wallpaperbox.com/Celebrities/$name/

limit=`wc -l < ~/$folder/pics_list`
limit=`expr $limit - 10`
limit=`expr $limit / 2`
my_number=`expr $RANDOM % $limit`
echo $my_number

wget -O ~/$folder/$name.jpg http://www.wallpaperbox.com/Celebrities/$name/$name-$my_number.JPG
gconftool-2 -t str --set /desktop/gnome/background/picture_filename ~/$folder/$name.jpg
END


and a bit improvised version of that is

#!/bin/bash
#folder=`pwd`;
folder="/root/Dropbox/new_installation/wallpaper/celeb";

cd $folder;
rm -f *.jpg;

limit=`wc -l < list`;
my_number=`expr $RANDOM % $limit`;
name=`tail -n $my_number list| head -n 1`;

wget -O pics_list http://www.wallpaperbox.com/Celebrities/$name/ ;

limit=`wc -l < pics_list`;
limit=`expr $limit - 10`;
limit=`expr $limit / 2`;
my_number=`expr $RANDOM % $limit`;

wget -O $name.jpg http://www.wallpaperbox.com/Celebrities/$name/$name-$my_number.JPG;
gconftool-2 -t str --set /desktop/gnome/background/picture_filename $folder/$name.jpg;

Tuesday, December 1, 2009

Undo the settings of pppoeconf command

"pppoeconf" sets up dialup networks on linux/ connect to internet without connecting via network manager. But thats done, it sets up few files to always do that.
To undo this on ubuntu, follow these steps :

1) Edit nm-system-settings.conf

vim /etc/NetworkManager/nm-system-settings.conf


You have to write managed=true under [ifupdown]

4) Edit interfaces

vim /etc/network/interfaces


This file must look like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 dhcp


5) Restart your computer

reboot


6) Finished.

Friday, November 13, 2009

Finding out your external IP address

If you want to find out what external IP address your router has assigned to it, you can either search the Internet for sites that can display that said IP address or you can use the Linux command line:

wget -O - -q icanhazip.com


wget options:
'-O -' will display output on terminal instead of saving it in a file.
'-q' will suppress wget's output (e.g. connecting ,saving)

This are other sites which can be used instead of icanhasip.com
http://www.canyouseeme.org/
http://www.formyip.com/
http://www.checkip.org/
http://www.whatismyip.org/

Monday, November 9, 2009

Multiple line comments and designs

Have you ever wondered how do people make fancy design around comments like

/**************************/
/* Different all twisty a */
/* of in maze are you, */
/* passages little. */
/**************************/


or like
__ _,--="=--,_ __
/ \." .-. "./ \
/ ,/ _ : : _ \/` \
\ `| /o\ :_: /o\ |\__/
`-'| :="~` _ `~"=: |
\` (_) `/
.-"-. \ | / .-"-.
.---{ }--| /,.-'-.,\ |--{ }---.
) (_)_)_) \_/`~-===-~`\_/ (_(_(_) (
( qwe )
) asd (
( zxc )
) (
'---------------------------------------'


I even tried creating a one in one of my files. Then I had to change my message and my design was screwed.

Today in casual browsing I found this and all questions which have been there for years were solved.

All you need to do is
1. yum/apt-get install boxes

2. Open vim select the text you want inside the box in visual mode.

3. Type : (Prompt will be :'<,'>)
4. And then type !boxes (Prompt will be :'<,'>!boxes)

And you will have nice designed comments.

If you want to undo boxes, select the whole box using visual mode(only box,not starting of next line), and say !boxes -r

Friday, November 6, 2009

Cross-platform Browser Sync - Xmarks

I have 3 machines, each one with Linux/windows installation. Its really a pain to sync my browsers for bookmarks and ....
But now I found this and its really working great. I suggest you to try this out too.
http://www.xmarks.com/

Thursday, October 29, 2009

Dropbox - online storage/backup

Every morning I start my computer, I pray that it at least starts.
This is why I always looking for option for getting things off of the local computer.

Recently I came across Dropbox. I am really liking it. It gives you 2 GB of storage free of cost.
To Setup follow these commands

For Ubuntu :
1. Go to https://www.getdropbox.com/downloading and download appropriate package.
2. # dropbox start -i

For Redhat/Fedora (without Nautilus plugin):
1. If 32 bit,
wget http://www.getdropbox.com/download?plat=lnx.x86
If 64 bit,
wget http://www.getdropbox.com/download?plat=lnx.x86_64


tar zxof dropbox-*.tar.gz
mv .dropbox-dist ~/.dropbox-dist
wget http://dl.getdropbox.com/u/6995/dbmakefakelib.py
wget http://dl.getdropbox.com/u/6995/dbreadconfig.py
python dbmakefakelib.py

It will ask all the information,fill it and let it sync. Then close it using icon->stop or ^C.


python dbreadconfig.py
cat >> ~/.bash_profile << END
~/.dropbox-dist/dropboxd &
END


You will get a folder ~/Dropbox. Create anything in that folder and it will be backed up automatically. Also they have a folder called ~/Dropbox/Public where you can put a document and its available to non-dropbox users too.

Here are other options available
http://en.wikipedia.org/wiki/List_of_online_backup_services
http://tomuse.com/ultimate-review-list-of-best-free-online-storage-and-backup-application-services/

Ubuntu has its own online storage too. Its called Ubuntu_one.

Wednesday, September 30, 2009

my ~/.vimrc

"-------------------------------------
" always show this custom status line
set notitle       " to avoid vim renaming the title of the xterm window
set nonumber      " we don't need line numbers on the left, because we have status line
set laststatus=2  " always show the status line
set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%c\",getftime(expand(\"%:p\")))}%=\ col:%c%V\ line:%l\,%L\ %P
" -------------------------------------
" use 2-space indentation
" set tabstop=2     " read :help tab for explanation of tabstop, softtabstop, shiftwidth
" set softtabstop=2 "
set shiftwidth=2  "
" set expandtab     " inserts spaces instead of tab (for real tab use ctrl-V - tab)
" -------------------------------------
set showmatch     " When a bracket is inserted, briefly jump to the matching one if it is visible on the screen.
set matchtime=3
" -------------------------------------
" set autoindent
" set smartindent
" set paste       " you can set paste temporarily, but be aware that it interferes with autoindent
                  " it turns it off (and many other settings). Read :help paste
" -------------------------------------
set incsearch     " search incremental
set ignorecase    " search case-insensitive
set smartcase     " search case-insensitive for small chars, case-sensitive if at least 1 capital char
set nohlsearch    " search highlighting
" -------------------------------------
" This only works if you have plugin under .vim in home dir
" or if you include here a command to source plugin, for example:
"   source ~lselector/lselector/.vim/plugin/taglist.vim
:map :TlistToggle
let Tlist_Exit_OnlyWindow = 1
" -------------------------------------

set ignorecase
set smartcase
set incsearch
set title
set wrap
set wildmenu
set noautoindent smartindent
set hlsearch
set paste
set ic

set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab

match ErrorMsg '\%>80v.\+'
match

nnoremap :set invpaste paste?
set pastetoggle=
set showmode

nnoremap :set nowrap!
"set wrap!=
"set showmode

":set mouse=a
":map
":map
":map
":map

:map
:map
noremap :call ToggleMouse()

function! ToggleMouse()
  if &mouse == 'a'
    set mouse=
  else
    set mouse=a
  endif
endfunction

if match($TERMCAP, 'Co#256:') == 0 || match($TERMCAP, ':Co#256:') > 0          
      set t_Co=256                                                               
endif

command -nargs=1 T2 :2match Search //




2nd paragraph is for not putting tab as /t ( instead, put it as 2 spaces).
3rd paragraph is for limiting column to 80. It will start highlighting if it goes after 80. For undoing it in some cases you can say ':match'.

Monday, September 28, 2009

Editing multiple lines in vim

1.Press ctrl + v (To selest visual block. v/V are for visual region)
2.Select lines you want to append to.
3.Press I{string}<ESC>
(Note: Its I = capital i = shift+i)

In our case, {string} = #. It takes a while for changes to appear after you press <ESC>.

Saturday, September 19, 2009

Searching using/in URL bar

1. Go to any site which you use for searching (e.g. Wikipedia).
2. Right click on text box where you enter your query.
3. Click on "Add a keyword for this search".
4. Enter <keyword>(e.g. wk) in keyword box.
5. Save.

Whenever you want to search 'something' in Wikipedia, just type 'wk something' in URL bar. If search doesn't work, try to analyse and modify location field.

Wednesday, September 16, 2009

'rename' command

To rename multiple files:
I wanted to rename all files in a folder from *_vXXX.sh to *_vYYY.sh.
Thus I used

rename XXX YYY *_vXXX.sh


We can specify the number of wild characters in searching pattern by ? e. g. reaplce only a_vXXX.sh but not ab_vXXX.sh

rename XXX YYY ?_vXXX.sh

Monday, September 7, 2009

'ndiswrapper' on fedora 11

Again this might change with newer version of OS or different version of OS.

rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stabl
yum install kmod-ndiswrapper
mkdir ~/new_installation/ndiswrapper_driver
cd ~/new_installation/ndiswrapper_driver
wget http://www.jbg.f2s.com/bcm43.bz2
tar jxvf bcm43.bz2
cd bcmwl5\ driver
ndiswrapper -i bcmwl5.inf


Now reboot your machine and execute these commands.

modprobe ndiswrapper
ndiswrapper -ma

Wednesday, September 2, 2009

Installing GUI on a non-GUI/Command line terminal

We need to execute 2 packages as opposed to google's result.

yum -y groupinstall "X Window System" "GNOME Desktop Environment"

Friday, August 28, 2009

Comparing 2 files

Better than opening in 2 VIM windows , I used to take diff and open its output in vim :).
But diff itself has flag which will compare files line by line.


diff -ay file1 file2 | less

Friday, August 21, 2009

Creating your own file/web host

Pretty easy.

yum install httpd
ln -s /directory_to_share /var/www/directory_to_share
chmod 777 /directory_to_share
service httpd restart


i take drastic approach when it come to directories.:)

Wednesday, August 19, 2009

Connecting to windows machine from linux machine

By default Linux has "rdesktop" program.
Problem will rise on windows machine(of course!!).

1.Go in Start -> Control Panel -> Windows firewall.
2.Goto "Exceptions" tab.
3.Check "Remote Desktop" entry.
4.Press OK.

5.Open System Properties menu (Computers -> Right Click -> Properties)
6.Goto Remote tab
7.In Remote Desktop menu, check "Allow users to connect remotely to this computer"
8.Press OK.

Other variants with similar setting are tsclient on Linux(which is for both VNC and rdesktop),vncviewer(again by default in Linux ,but need VNC on windows machine)

Monday, August 10, 2009

KVM live migration

You can refer to my previous post for setting up KVM.

Before :

[root@euclid ~]# virsh list
Id Name State
----------------------------------
4 veuler running

[root@gauss ~]# virsh list
Id Name State
----------------------------------



Migration Command :

[root@euclid ~]# virsh migrate --live veuler qemu+ssh://gauss/system
root@gauss's password: *****


After :

[root@euclid ~]# virsh list
Id Name State
----------------------------------

[root@gauss ~]# virsh list
Id Name State
----------------------------------
4 veuler running



QEMU Vs KVM :

QEMU provides virtualization purely by means of software, and can be used as a stand-alone package.

KVM--which stands for "Kernel-based Virtual Machine"--provides for hardware-assisted virtualization. It can only be used with newer processors, such as Intel Core 2's or more recent AMD Athlon64's. It must be used in conjunction with QEMU.

Thursday, August 6, 2009

Opening qcow files

Qcow files are used as disks in KVM

losetup -f

Get a free loop-back device, say /dev/loop0.

losetup /dev/loop0 harshal.qcow
kaprtx -av /dev/loop0
vgscan


Get the name of the volume group in qcow file, say vg_harshal.

vgchange -ay vg_harshal

Enable that volumegroup.

lvdisplay

Get logical volume name for that volume group, say /dev/vg_harshal/root1

mount /dev/vg_harshal/root1 /mount_point

Good to Use.

Once done, we need to undo the changes.


umount /mount_point
vgchange -an vg_harshal
kpartx -dv /dev/loop0
losetup -d /dev/loop0

Sunday, July 19, 2009

"Firefox already running" error

Do you get this error when there is no process called firefox?
I mean

# ps -aux | grep firefox
#


Then do this

cd ~/.mozilla/firefox/[profile_name]
rm lock .parentlock

Wednesday, July 15, 2009

Network tweaks

Many times client computer doesn't get IP address even if its protocol is DHCP. If we manually give IP address to it, everything works perfectly fine. Thus the command to give manual IP is as follow


ifconfig eth0 'new_ip' netmask 255.255.255.0 up


Do not forget to fill in the IP adress you want.

Also if the default routes are screwed up, fix it like this

cat >> /etc/sysconfig/network << END
GATEWAY='Gateway_IP'
END

Friday, July 10, 2009

Setting up NIS server

These are the scripts which I have tried and tested in order to set NIS service over the network.

On server side :

yum -y install ypserv
domainname SCRC
cat >> /etc/yp.conf << END
ypserver 127.0.0.1
END
cat >> /etc/sysconfig/network << END
NISDOMAIN=SCRC
END
service ypserv start
chkconfig ypserv on
/usr/lib/yp/ypinit -m
service ypbind start
chkconfig ypbind on
service ypxfrd start
chkconfig ypxfrd on
cd /var/yp
make



On client side :

yum -y install ypbind
domainname SCRC
cat >> /etc/yp.conf << END
ypserver pioneer
END
cat >> /etc/sysconfig/network << END
NISDOMAIN=SCRC
END
service ypbind start
chkconfig ypbind on


Do not forget to change /etc/nsswitch.conf

Friday, June 12, 2009

SVN Introduction

A very common thing while doing any kind of project is using repository. I tend to forget these commands every now and then. That's why this

svn checkout http://fileextensiontype.unfuddle.com/svn/fileextensiontype_fi/ local_directory_name

svn status

svn add *

svn commit


You may also have to do this
export EDITOR=vim

Monday, June 8, 2009

Wordweb Equivalent on Linux

One feature I really miss in Linux is Word-Web. We can have word-web in Linux using wine but pressing the hot-key when word is selected does not activate it. Thus, we can use "gnome-dictionary" with "xbindkeys" and "xclip" to get same kind of functionality.

yum install xbindkeys
yum install xclip
xbindkeys --defaults > ~/.xbindkeysrc
xbindkeys -k

Now a small window will appear and you can get code for the key-combination pressed. Use this combination in configuration file ~/.xbindkeysrc. (I got m:0x1c + c:52 for alt+ctrl+e)

cat <<- END
"gnome-dictionary $(xclip -o)"
m:0x1c + c:52
END
echo "xbindkeys &" >> ~/.bashrc
killall -HUP xbindkeys


Equivalent to "delimiter cat" is "echo -e".

That's it. Just select any word you don't know and press your key combination. We will get its meaning.

Friday, June 5, 2009

Using cscope and ctags

Many people complain that though Linux is in C they don't have good IDE for C development. Though there the things mentioned here are not great but they are good enough to help you in C development.

1. Cscope

find . -name '*.c' > cscope.files
cscope -i cscope.files


cscope.files is default file name, thus just cscope command would work. To exit, you can type Ctrl+D and to see help, you can type "?".

2.Ctags

cd /path/to/your/project
ctags -R *
vim -t

Once inside a file, hitting ctrl-] while the cursor is over a function/class name, Vim will attempt to open the file with that tag. Pressing ctrl-t will take you back a step. To exit, , regular ":q" should work.

Friday, May 29, 2009

KVM setup

I usually love to start from a brand new OS installation. That way we know what packages we actually need. Follow these instructions for both machines A and B.

1. Confirm your CPU has virtualisation support
egrep 'vmx|svm' /proc/cpuinfo

2. Install kvm packages
yum install kvm kmod-kvm qemu

3. Install appropriate kernel module
modprobe kvm-intel
OR
modprobe kvm-amd

4.Check whether the module is installed or not
lsmod | grep kvm
Also make sure the kvm is present as a device
ls -l /dev/kvm

5.Mount same NFS share at same path (say /mount_point)
mount server:/nfs_share /mount_point

6.Download ISO file for creation on virtual machine
wget -O /mount_point/fedora.iso http://mirror.cc.vt.edu/pub/fedora/linux/releases/10/Fedora/i386/iso/Fedora-10-i386-DVD.iso

7. Create VM image file
qemu-img create fedoraroot.img -f raw 10G

8. I do not know if there is a command line version of qemu. So if your server does not have GUI, you can use following commands
On server
export DISPLAY=your_machine:0.0
On your_machine
xhost +
You can specify server's name after + sign. But I prefer accepting whole world to avoid routing problems.

9. Start VM using
qemu-kvm -m 512 -cdrom fedora.iso -boot d fedoraroot.img

10. Once installation is done, change boot flag to "c"( which is default). You can also remove CD-ROM from VM.
qemu-kvm -m 512 fedoraroot.img

Wednesday, May 20, 2009

Wallpaper changer script

Tired of changing wallpaper everyday? You will get many soft-wares which will change it for you everyday. The only thing which I dint like about them is, they put a picture which is stored on your computer. SO there is possibility that you have seen that picture before. What about a truly random pic??
Here is the script:

rm -f ~/wallpaper/w.jpg ~/wallpaper/widescreen_rss.php
wget -O ~/wallpaper/widescreen_rss.php http://www.mlewallpapers.com/widescreen_rss.php
wget -O ~/wallpaper/w.jpg `grep enclosure ~/wallpaper/widescreen_rss.php | cut -d \" -f 2`
gconftool-2 -t str --set /desktop/gnome/background/picture_filename ~/wallpaper/w.jpg

Put it in your cron so that it will execute daily. You can modify this to fetch picture from any site which will give new picture daily.


All this can be done using following :

mkdir -p ~/new_installation/wallpaper
cat > ~/new_installation/wallpaper/wallpaper_changer.sh << END
rm -f ~/new_installation/wallpaper/w.jpg ~/new_installation/wallpaper/widescreen_rss.php
wget -O ~/new_installation/wallpaper/widescreen_rss.php http://www.mlewallpapers.com/widescreen_rss.php
wget -O ~/new_installation/wallpaper/w.jpg \`grep enclosure ~/new_installation/wallpaper/widescreen_rss.php | cut -d \" -f 2\`
gconftool-2 -t str --set /desktop/gnome/background/picture_filename ~/new_installation/wallpaper/w.jpg
END
chmod a+x ~/new_installation/wallpaper/wallpaper_changer.sh
cat >> /etc/sudoers << END
# crontab root scripts
action-owl ALL=(ALL) NOPASSWD:~/new_installation/wallpaper/wallpaper_changer.sh
END

For fedora :

cat >> /var/spool/cron/root << END
0 12 * * * ~/new_installation/wallpaper/wallpaper_changer.sh >/dev/null 2>&1
END

For ubuntu :

cat >> /var/spool/cron/crontabs/root << END
0 12 * * * ~/new_installation/wallpaper/wallpaper_changer.sh >/dev/null 2>&1
END


This will change wallpaper on 12 noon every day.

Tuesday, May 19, 2009

Installing 64 bit adobe in firefox

I have 64 bit ubuntu in office and for some strange reasons, it installs 32 bit flash player through apt-get. To install 64 bit version here are the commands to copy paste in terminal.


wget -O flash.tar.gz http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-10.0.22.87.linux-x86_64.so.tar.gz
tar xvzf flash.tar.gz
mkdir -p ~/.mozilla/plugins
mv libflashplayer.so ~/.mozilla/plugins
pkill firefox
firefox

Friday, May 15, 2009

Open terminal in current folder

One feature I really miss in Fedora after moving from redhat was opening a terminal in current folder of nautilus.
So my workaround is this :


echo gnome-terminal > ~/.gnome2/nautilus-scripts/terminal
chmod a+x ~/.gnome2/nautilus-scripts/terminal

Monday, May 11, 2009

MS office 2007 in openoffice

We need to have this plug-in in order to open docx and xlsx files in open-office.

http://rpm.pbone.net/index.php3/stat/4/idpl/10821603/com/odf-converter-integrator-0.2.0-2.i386.rpm.html

Thursday, May 7, 2009

Radio in linux

Being in linux, its a obvious thing to use command line for EVERYTHING. For example, listening songs. "Usual" folks just go on some site, either download or keep browser open if the site is providing media player itself. But in linux, its just a command (which can be run in background). I use following commands for listening radio :

mplayer -playlist http://asx.abacast.com/arabian_radio-city-64.asx -loop 0
mplayer - playlist http://www.1.fm/TuneIn/WM/energybbfm128k/Listen.aspx -loop 0
mplayer mmsh://citadelcc-wplj-fm.wm.llnwd.net/citadelcc_WPLJ_FM?MSWMExt=.asf


"-loop 0" because dont let a single corrupt packet stop your radio.

You can always find a radio station of your choice. One radio station which I would really like to promote is http://wnyu.org/.

Friday, May 1, 2009

Sopcast in linux

Love watching sports? But cant get working on linux??
Here is what I found.

1. Download sopcast for linux from http://code.google.com/p/sopcast-player/.
(No need to download player. Just the source i.e. sp-auth is enough)

2. Create a small script ('~/sop' in my case) as follows :

#!/bin/sh
while [ 1 ]
do
sp-sc $1 3908 8908 > /dev/null &
mplayer http://localhost:8908/tv.asf
done
pkill sp-sc


(while loop because mplayer doesn't start the stream in first attempt.)

3. Search the forums like http://myp2p.eu/index.php?part=sports for your favourite channel and get the sopcast link which will look like sop://broker1.sopcast.com:3912/10912

4.

./sop sop://broker1.sopcast.com:3912/10912


then sit back and enjoy!!!

Tuesday, April 28, 2009

passwordless SSH Log in and even more secure

Suppose you want to log into your office computer very often from home computer. Its very annoying to enter password each time you open a terminal or new window in terminal. Thus I searched a bit and found a procedure to bypass entering password. And it happens to be more safer way that entering password.

1.On your Home-comp
ssh-keygen -t rsa

This will generate ~/.ssh/id_rsa.pub file

2.
cat ~/.ssh/id_rsa.pub | ssh office-user@office-comp "cat >> ~/.ssh/authorized_keys"


This will ask you password for one last time. Note that we have used cat command over ssh. Hence we will require the password at least once.

Make sure that you have following permissions on "office-comp" :
chmod 750 ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Monday, April 27, 2009

Getting CD-ROM info in linux

I wanted to burn a DVD( Ubuntu :D) but my machine does not have DVD RW. I thought one of the server might have it, so I needed to check them. The problem is all servers are without X, so I needed some command to get that info. After Googling a bit I found some useful files.

/proc/sys/dev/cdrom/autoclose
/proc/sys/dev/cdrom/autoeject
/proc/sys/dev/cdrom/check_media
/proc/sys/dev/cdrom/debug
/proc/sys/dev/cdrom/info
/proc/sys/dev/cdrom/lock

All the files are readable by all and produce ASCII output when read. They reflect the current state of the CDROM subsystem. This location is part of the procfs's window through to the sysctl configuration mechanism (see man sysctl). All but info are writable by the superuser. There is a column for each CDROM and DVD player in the system in info (not just SCSI devices).

As an example, the auto eject feature can be turned on by the superuser with the command echo "1" > /proc/sys/dev/cdrom/autoeject. This will cause cdroms to be ejected from the drive when unmounted.

Sunday, April 26, 2009

NYU wireless/VPN on linux

I use Fedora on my laptop and I had tough time configuring NYU wireless in it. I found three procedures, of which I tried hard with the first one but Couldn't get it working. It was for Ubuntu but I thought I might give it a try. Here it is.

Approach 1 :
First off you'll need to get the Verisign Root CA certificate:
1.Go to https://getca.verisign.com/ and download the current Root CA Certificate. It downloads for me as 'getrootcert.cer'.
2.Convert the .cer file to a .pem file:
openssl x509 -in getrootcert.cer -inform d -out verisign.pem

3.Save verisign.pem wherever you want (/etc/ssl/certs would make sense).
4.You need to go to the network manager (usually on the top bar) where you select wireless networks, click the left mouse button and select 'connect to other wireless network'.
5.Select 'WPA2 Enterprise' for a 'Wireless Security', and a whole bunch of new options will appear.
Network Name is 'nyu'
EAP Method is PEAP
Key Type: Automatic (or, I believe AES)
Phase2 Type is MSCHAPv2
Identity is you NYU NetID (eg. js123 -- don't include the @nyu.edu )
Password is your NetID password.
Anonymous Identity, Client Certificate File, Private Key File, and Private Key Password should be left blank.
6.For CA (Certifying Authority, I guess) Certificate file use the verisign.pem file.
It should work fine.



Approach 2:(NYU VPN)

After a while I found second one.I got this thing working in first attempt but the problem is we never know when will NYU-ITS will shut off NYU-Roam3.Here is the procedure.

1.Connect to NYU-ROAM3.
2.Create a VPN connection using cisco VPN.
3.Gateway : vpn.nyu.edu
4.Group name : nyu-vpn
5.User password : NYU net ID password
6.Group password : nyu-net
7.User : NYU net ID

For ubuntu:
Install vpnc and network-manager-vpnc using synaptic first.



Approach 3:

Simplest of all.
1. Get guest username and password from library.
2. Connect to NYU-GUEST.
3. Put that username and password.

But dont get too excited, this user name and password is changed every Monday.