Tuesday, May 14, 2013

RSA SecureID in Android

install RSA SecureID Software Token
https://play.google.com/store/apps/details?id=com.rsa.securidapp&hl=en

You should have .sdtid file in your Linux box.
Download ftp://ftp.rsasecurity.com/pub/agents/TokenConverter261.tar.gz

./TokenConverter  -iphone
com.rsa.securid.iphone://ctf?ctfData=1034701932740192347...

change this as;
http://127.0.0.1/securid/ctf?ctfData=1034701932740192347...

Transfer this URL into your android device in a file. Open it with an text editor and copy it in the import text box of RSA SecureID Software Token.

Saturday, February 9, 2013

Clean Uninstaller for Mac OS X packages

This will automate the uninstallation process of an installed Mac OS X packages [.pkg]. It utilizes the functionalities provided by pkgutil.

#!/bin/bash
# Copyright (C) 2008 Nayanajit Mahendra Laxaman mail: nmlaxaman@gmail.com

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
LOG=/var/log/uninstall.log

#Verify the arguments
if [[ $# -ne 1 ]]
then
 echo "Usage:"
 echo "$0 "
 echo "NOTE:The PKGID should be as in 'pkgutile --pkgs' list."
 echo "Eg:"
 echo "$0 com.apple.pkg.JavaForMacOSX107"
 exit 1
fi

#Check the availability of the package
if [[ $( pkgutil --pkgs | grep "$1" ) == ''  ]]
then
 echo "Package $1 not installed!"
 exit 1
else
 echo "Following package will be uninstalled:"
 pkgutil --info $1
 sudo pkgutil --info $1 >> $LOG
 echo "The files removed will be archived at /tmp/$1.tar"
fi

#Confirm UNINSTALLTION
echo -n "Proceed with UNINSTALLTION [y/N]:"
read ans
if [[ $ans == 'y' || $ans == 'Y' ]]
then
 echo "Uninstalling $1"
else
 echo "Uninstalltion aborted!"
 exit 0;
fi

#Do it from root
cd /

#Generating the list of files
FILES=$(pkgutil --only-files --files $1 | tr '\n' ' ' )
sudo echo $FILES >> $LOG

#Generating the list of directories
DIRS=$(pkgutil --only-dirs --files $1 | tr '\n' ' ')
sudo echo $DIRS >> $LOG

#Archive  all the files
echo "Creating archive at /tmp/$1.tar ..."
tar -cf /tmp/$1.tar  $FILES

echo "Deleting files ..."
for file in $FILES
do
 if [[ $(pkgutil --file-info $file | grep pkgid | wc -l) -ne 1 ]]
 then
  echo "$file is used by another package and not removing!"
 else
  sudo rm -f $file
 fi
done

echo "Deleting dirs ..."
for dir in $DIRS
do
 if [[ $(pkgutil --file-info $dir | grep pkgid | wc -l) -ne 1 ]]
 then
  echo "$dir is used by another package and mot removing!"
 else
  sudo rm -fr $dir
 fi
done

#Forgetting the package from pkg database
echo "Forgetting the package $1..."
sudo pkgutil --forget $1

Friday, September 28, 2012

Easy read out loud in linux

1. Install espeak and xclip
2. Create the following script
vim /opt/myapps/read_out_loud.sh

#!/bin/bash
pidof espeak
if [[ $? == 0 ]]
then
   pkill -9 espeak
else
   TEXT=$( xclip -o | sed s/\"/\'/g )
   espeak -ven+f2 -s180 "$TEXT"
fi


3. Add keyboard short-cut to the script  (eg: Ctrl+Shift+r)
4. To read any text, first copy the text (eg: Select and Press Ctrl+c) and the press Ctrl+Shift+r. This will read the text in the clipboard.

Saturday, August 18, 2012

PHP array_walk any function

Built-in array_walk  function of PHP require a specially defined functions to work with. So any built-in functions or your other functions can not walk on array. Below code provide a functionality to overcome this issue and walk any function on your array. 
$my_arr=array("a"=>"apple","b"=>"banana","c"=>'cashew');

//walker function holder array
$GLOBALS['walker']="";

/**
 * walker walks a function over an array
 */
function array_walk_(&$array,$function,$var=array()){
   $GLOBALS['walker']=$function;
   array_walk($array,'walk_helper',$var);
}

/**
 * Helper function for the walker
 */
function walk_helper(&$item,$key,$var=null){
   $var[]=$item;
   $item=call_user_func_array($GLOBALS['walker'],$var);
}

array_walk_($my_arr,'strtoupper');
print_r($my_arr);

array_walk_($my_arr,'strtolower');
print_r($my_arr);            


Result of the execution:

Array ( [a] => APPLE [b] => BANANA [c] => CASHEW ) Array ( [a] => apple [b] => banana [c] => cashew )

Saturday, July 21, 2012

ZTE MF190B on OpenSUSE 12.1

Create following two files in given paths  and that will do 

1) vim /etc/udev/rules.d/40-usb_modeswitch.rules
# ZTE MF190B 19d2:0146#
#disable cdrom
ACTION=="add", SUBSYSTEMS=="scsi", DRIVERS=="sr", ATTRS{manufacturer}=="ZTE", RUN:=""
#disable handeled by network manager
ATTRS{idVendor}=="19d2", ENV{ID_MM_DEVICE_IGNORE}="1"
#change usb mode
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="0146", RUN+="/lib/udev/usb_modeswitch '%b/%k'"
#starting wvdial if you are using wvdial else comment this line
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="0143", RUN+="/usr/bin/wvdial'"

2) vim /usr/share/usb_modeswitch/19d2:0146

#ZTE MF190B 19d2:0146#

DefaultVendor = 0x19d2
DefaultProduct = 0x0146

TargetVendor = 0x19d2
TargetProduct = 0x0143
MessageContent="5553424312345678000000000000061b000000020000000000000000000000"
CheckSuccess=20

3)This step is if you are using wvdial: sample /etc/wvdial.conf (for mobitel Sri Lanka)
[Dialer Defaults]
Init1 = ATZ
Stupid Mode = 1
Password = null
Phone = *99#
Modem Type = USB Modem
Check DNS = off
Dial Command = ATDT
Modem = /dev/ttyACM0
Init = AT+CGDCONT=1,"IP","mobitel3g"
Init1 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Username = null
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Auto Reconnect = off
Baud = 460800
Auto DNS = Off
dns1 = 8.8.8.8
Check Def Route = 1



NOTE: modify 'Phone' and 'Init' of wvdial.conf to match your providers configuration

Monday, July 16, 2012

Sunday, July 15, 2012

Ubuntu 12.04 install ffmpeg with amr support

1)Install the source package
apt-get source ffmpeg


2) install dependencies to build the package
apt-get build-dep ffmpeg


3) Install dependencies for custom options (confflags)
apt-get install libopencore-amrnb-dev libopencore-amrwb-dev

4) ffmpeg is on of the components of libav so apt-get source ffmpeg will create /usr/src/libav-0.8.3 with the source so cd to that location
cd /usr/src/libav-0.8.3

4) change confflags to enable some extra options for ffmpeg
vim debian/confflags
add following lines in '# Common configuration flags' section
confflags += --enable-libopencore-amrwb
confflags += --enable-libopencore-amrnb
confflags += --enable-version3

5) Build the package
dpkg-buildpackage -rfakeroot -uc -b

6) Install the resulting deb package(s)
cd /usr/src
dpkg -i ffmpeg_0.8.3-0ubuntu0.12.04.1_all.deb

7) Using ffmpeg to convert mp3 to amr
ffmpeg -y -vn -i in_file.mp3 -y -acodec libvo_amrwbenc -ac 1 -ar 16000 -ab 7.4k -f amr -map_metadata  -o out_file.amr

Friday, July 13, 2012

Generate wallpaper slideshow xml for gnome/Unity


#!/bin/bash

start='<background><starttime><year>2009</year><month>08</month><day>04</day><hour>00</hour><minute>00</minute><second>00</second></starttime>';
end='</background>';
static='<static><duration>1000.0</duration><file>%s</file></static>';
transition='<transition><duration>5.0</duration><from>%s</from><to>%s</to></transition>';

echo $start
echo
prev_file='';
ls | grep -i -e .jpg -e .png | while read line
do
   file=$PWD/$line;
   if [[ $prev_file == '' ]]
   then
      printf $static "$file";
      echo
   else
      printf $transition "$prev_file" "$file";
      echo
      printf $static "$file";
      echo
   fi
   prev_file=$file;
done
echo $end

1) In ubuntu precise the xml which provides the wallpaper slideshow is located here
/usr/share/backgrounds/contest/precise.xml

2) In order to create your own xml file you have to cd to the directory which contains the images and run this script and recirect the output to an xml file

3) After createing the xml file (eg: myshow.xml) backup the original file comes with precise and replace the newly created file to its place with the same name (precise.xml)

4) Go to system settings > appearance and select your slide show there

NOTE: make sure to keep your image filenames without spaces or use following script to replace spaces with underscores

#!/bin/bash

ls | grep '[a-zA-Z0-9]\ [a-zA-Z0-9]' | while read line
do
mv "$line" $( echo $line | sed s/' '/'_'/g )
done

Put wirless in to ad-hoc shell script

#!/bin/bash
rfkill unblock 0
rfkill unblock 1
ifconfig wlan0 down
sleep 1
iwconfig wlan0 essid
iwconfig wlan0 key s:
iwconfig wlan0 mode ad-hoc
ifconfig wlan0 up
ifconfig wlan0 10.16.90.12 netmask 255.255.240.0
route add default ppp0
sleep 1
iwconfig wlan0 essid

NOTE: place your essid and password in the script

Keyboard shortcukt to Send to back send to front a application window

1) Create this script as /opt/terminator_quake.sh
 
#!/bin/bash
TM_STATE=/tmp/tm_stat
WIN=$( wmctrl -lGx | grep -i terminator | awk '{print $1}' );
if [[ $WIN == "" ]]
then
   exit 0
   #terminator&
else
   if [[ -e $TM_STATE ]]
   then
      wmctrl -i -r $WIN -b remove,below
      wmctrl -i -r $WIN -b add,above
      rm $TM_STATE
   else
      wmctrl -i -r $WIN -b remove,above
      wmctrl -i -r $WIN -b add,below
      touch $TM_STATE
   fi
fi

2) I'm using this in unity on ubunutu (ie. compiz) so open ccsm (compiz config setting manager)
3) Click 'commands' button in 'general' section
4) In 'commands' tab add /opt/terminator_quake.sh to 'command line 0'
5) Click 'key binding' tab and add shortcut to the 'Run command 0' entry.

Thats it now you can send to front and sent to back the window (eg: terminator in this case). This can be use as alternative to yakuake, guake and tilda.

Check real bandwidth usage in mobitel sri lanka

#!/bin/bash

if $(gconftool-2 -g /system/http_proxy/use_http_proxy)
then
   export http_proxy="http://$(gconftool-2 -g /system/http_proxy/host):3128"
else
   unset http_proxy
   unset https_proxy
fi

ping -c 1 www.google.com 2>/dev/null >/dev/null
if [[ $? != 0 ]]
then
   zenity --error --text="Error connecting to the server!"
   exit 0;
fi

USER=
PASSWORD=

ACC="username=$USER&password=$PASSWORD"
DATA="select=ing"
COOKEY="/tmp/cookey.$USER"
OUTPUT="/tmp/curl.out"
MYACC="http://selfcare.mobitel.lk/MyAccount"
LOGIN="$MYACC/SubmitLogin.jsp"
DATA_USAGE="$MYACC/DataUsage.jsp"

#echo "curl --head --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data '$ACC&$DATA' $LOGIN 2>/dev/null >/dev/null"
curl --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data "$ACC&$DATA" $LOGIN 2>/dev/null >/dev/null
curl --cookie $COOKEY --cookie-jar $COOKEY --user-agent Mozilla/4.0 --data "$ACC&$DATA" $DATA_USAGE -o $OUTPUT 2>/dev/null >/dev/null

UTILIZED="Utilized: $( cat $OUTPUT | grep Utilized -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"
REMAINING="Remaining: $( cat $OUTPUT | grep Remaining -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"
EXCESS="Excess: $( cat $OUTPUT | grep Excess -A1 | tail -1 | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' )"

if [[ $1 == gui ]]
then
   zenity --title "3g Usage in Mb" --info --text=" $UTILIZED \n $REMAINING \n $EXCESS"
else
   echo  $UTILIZED
   echo  $REMAINING
   echo  $EXCESS
fi

Thursday, June 7, 2012

libreoffice macro basic full name in to name with initials format


1) Open macro organizer
Tools > Macros > Organize Macros > Libreoffice basic...


2) Select and edit Main located at
My Macros > Standard > Module1 > Main


3) Add following function to the end of the file
Function FullnameInitialed(fullname)
Dim out as String
Dim arr() As String
arr = Split(fullname, " ")
For lngPosition = LBound(arr) To UBound(arr)
word = arr(lngPosition)
If UBound(arr) = lngPosition Then
out = out & " " & word
Else
    out = out & " " & LEFT(word,1)
End If        
Next lngPosition
FullnameInitialed=out
End Function 


4) Save and close the macro editor and get back to spreadsheet and now you can use this function as any other function (like SUM function)


eg:
=FULLNAMEINITIALED("string here")
=FULLNAMEINITIALED(D22)

Wednesday, June 6, 2012

How to retrieve contacts from android CWM backup

1) Connect the phone to PC in USB storage mode and get the data.img from the cwm backup
 cp /media/clockworkmod/data.img . 

2) compile and build unyaffs which is need to retrieve the files from data.img 
download unyaffs.c, unyaffs.h from http://code.google.com/p/unyaffs/downloads/list 
wget http://unyaffs.googlecode.com/files/unyaffs.c
wget http://unyaffs.googlecode.com/files/unyaffs.h
gcc -o unyaffs unyaffs.c 
unyaffs data.img 

3) after extracting the image browse the contact database location
cd data/com.android.providers.contacts/databases 

4) use sqlite3 command line client to read the table of contacts 
sqlite3 contacts2.db 
sqlite> select number,name from view_v1_phones;

Thursday, June 10, 2010

Sinhala hangman


Sinhala hangman;
A word game to improve sinhala word power
Source, Debina package and Windows package can be downloaded here:
http://code.google.com/p/hangman-si/downloads/list

Tuesday, June 8, 2010

xmms-1 is still the best

xmms-1 is still can be found here 
eq-xmms (high quality equalizer) can be found here