Script – Tech Stuff https://gofedora.com How Tos, Tutorials, Tips and Tricks Thu, 18 Jun 2015 14:17:41 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.4 Javascript To Remove All Facebook Apps From Your Account https://gofedora.com/javascript-remove-facebook-apps-account/ https://gofedora.com/javascript-remove-facebook-apps-account/#comments Thu, 11 Feb 2010 23:06:45 +0000 http://gofedora.com/?p=1022 … ]]> This is a guest post by Gaganpreet Arora AKA bitgeek.

My Facebook app list was cluttered with useless apps accumulated over the time I had joined Facebook. The worst thing is that Facebook does not allow you to remove multiple apps in one go. You have to select one, confirm on “Are you sure?” first and then click on “Okay” when it is deleted. Very cumbersome. So I wrote a Javascript hack to remove all of the apps in one go.

Warning: This will actually delete all the apps

Step 1

Go to: http://www.facebook.com/editapps.php?v=allowed.

Step 2

Select and copy the complete code below and paste it into the address bar.

javascript:
function postwith (to,p)
{
  var myForm = document.createElement("form");
  myForm.method="post" ; myForm.action = to ;
  for (var k in p)
  {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}

function getElementsByClassName(classname, node)
{
  if (!node)
  {
    node = document.getElementsByTagName('body')[0];
  }
  var a = [], re = new RegExp('\\b' + classname + '\\b');
  els = node.getElementsByTagName('*');
  for (var i = 0, j = els.length; i < j; i++)
  {
    if ( re.test(els[i].className) )
    { a.push(els[i]); }
  }
  return a;
}

var arr = [];
els=document.getElementsByClassName('app_row');
arr['fb_dtsg']=document.getElementsByName('fb_dtsg')[0].value;
arr['remove'] = 1;
arr['post_form_id_source']='AsyncRequest';
arr['post_form_id'] = document.getElementById('post_form_id').value;
arr['app_id']=els[0].id.replace("editapps_allowed_","");
arr['__a'] = 1;
for (i=0; i

Step 3

Press Enter. The browser may get stuck for a few moments if the list is large, so if it does, just wait a bit and it will respond back.

References

Function postwith was taken from here, and getElementsByClassName was taken from here.
]]>
https://gofedora.com/javascript-remove-facebook-apps-account/feed/ 8
IntelligentMirror: RPM and DEB Caching Improved (0.5) https://gofedora.com/intelligentmirror-rpm-deb-caching-improved-05/ Wed, 19 Nov 2008 04:15:28 +0000 http://172.17.8.64/gofedora/?p=462 … ]]> After spending a lot of time with youtube cache, now I am trying to devote some time to update intelligentmirror with required features and enhancements that youtube cache already enjoys. In the same direction here is version 0.5 of intelligentmirror.

Improvements

  • Added max_parallel_downloads options to controll the maximum threading fetching from upstream to cache the packages.
  • Fine grained control on logging via max_logfile_size and max_logfile_backups option.
  • Added setup script to help you install intelligentmirror. No need to execute commands one by one for installation. Just run
 [root@localhost]# python setup.py install [ENTER]
  • Added update script (update-im). So in case you decide to change the locations for caching rpm/deb packages, just run
 [root@localhost]# update-im [ENTER]

OR

 [root@localhost]# /usr/sbin/update-im [ENTER]
  • Download scheduler similar to youtube cache is added to facilitate the download queing in case of large number of requests.
  • More informative logging.
  • cache.log is not flooding anymore with XMLRPC logs and python tracebacks.
  • Added extensive exception handling thoughout the program.

Availability

  1. RPMs for Fedora/Red Hat/Cent OS
  2. Source RPMs for Fedora/Red Hat/Cent OS
  3. Source Tar balls

Installation and Configuration

INSTALL and README files should help you throughout the installation and configuration process.

In case you have questions, ask them here in comments. Suggestions for improvement are welcome 🙂

]]>
Hack: Mange Fluctuating Wireless https://gofedora.com/hack-mange-fluctuating-wireless/ https://gofedora.com/hack-mange-fluctuating-wireless/#comments Sat, 23 Sep 2006 20:52:38 +0000 http://172.17.8.64/gofedora/?p=241 … ]]> I am trying this small script with a so called gui 😉 . This helps managing my wireless in the extreme conditions. Just a shell script. Run the script as root otherwise it’ll not work.

Get the script here or copy the code below.

#!/bin/bash
#
#	Author - Kulbir Saini, IIIT Hyderabad.
#	Home - http://saini.co.in/
#	KWirelessManger - Just for fun.(It works ... its not just fun).
#

#Give the popup life.
POPUP_LIFE="10"
#kdialog --passivepopup "Welcome to 'KWirelessManager'"  ${POPUP_LIFE} &
#Give your device name for proceeding further. It may be one of wlan0, ra0, eth0, ipw2200 etc...
WLAN_DEVICE="wlan0"
#Give your WLAN host to be connected.
WLAN_HOST="IIIT WLAN"
CONNECTED=0
while [[ 1 ]];
do
	iwlist ${WLAN_DEVICE} scanning 2> /dev/null > /tmp/iwlist.aps
	grep -e "Cell" /tmp/iwlist.aps | tr " " "\t" | cut -f15 > /tmp/iwlist.apadd
	ACCESS_POINTS_IN_RANGE=`wc -l /tmp/iwlist.apadd`
	for ACCESS_POINT_ADDRESS in `cat /tmp/iwlist.apadd`
	do
		iwconfig ${WLAN_DEVICE} ap ${ACCESS_POINT_ADDRESS}
		#kdialog --passivepopup "Connceting to Access Point ${ACCESS_POINT_ADDRESS} ..." ${POPUP_LIFE} &
		echo "Connceting to Access Point ${ACCESS_POINT_ADDRESS} ..."
		WLAN_STATUS=`service network restart | tail -1 | grep "FAILED"`
		if [[ ${WLAN_STATUS} == "" ]];
		then
			#kdialog --passivepopup "You are connected to ${WLAN_HOST}." ${POPUP_LIFE} &
			echo "You are connected to ${WLAN_HOST}."
			CONNECTED=1
			break
		else
			#kdialog --passivepopup "Failed to connect to the Access Point ${ACCESS_POINT_ADDRESS} :(" ${POPUP_LIFE} &
			echo "Failed to connect to the Access Point ${ACCESS_POINT_ADDRESS} :("
			CONNECTED=0
		fi
	done
	if [[ ${CONNECTED} == 1 ]];
	then
		sleep 180;
	fi
done

Please suggest any optimization and do tell if u like it.

]]>
https://gofedora.com/hack-mange-fluctuating-wireless/feed/ 1
Hack: Mail Filter – Shell Script https://gofedora.com/hack-mail-filter-shell-script/ https://gofedora.com/hack-mail-filter-shell-script/#comments Mon, 06 Mar 2006 20:57:28 +0000 http://172.17.8.64/gofedora/?p=243 … ]]> This is an attempt by me to filter mails on a Linux machine. You can run this file on your home directory at mail server and it will help you to sort mails on the basis of

  • From which user the mail has come or from which domain it came,
  • to which user or domain mail was sent and
  • the keywords in the subject part of the mail.

Actually its very slow as shell is very slow , I cant help it . It scan your entire mbox file in the home directory by default. Copy the code and paste in a file say filter.sh and change its permissions to executable. Place it in you home directory at the mail server and run.

Example
You want to see all mails from username@gmail.com just run and it will ask for input,
press 1
From: username [Enter]
It will display all the mails from that are lying there in your mbox one by one.

Get the script here or copy the code below.

#!/bin/bash
#################################
#   Author - Kulbir Saini       #
#   Home - http://sain.ico.in/  #
#################################

#shell script to filter mails.
echo -e -n "\033[32mWelcome to the mail filter system \nWhat do you want to do? \nCheck mails on basis of \n1) Sender... \n2) Receiver... \n3) Subject... \n4) Quit... \nPress(1,2,3,4): \033[0m"
read int <&2
while [[ 1 ]];do
while [[ 1 ]];do
count=0;	line=""
if [[ $int == 1 ]];then
	echo -n -e "\033[32mFrom:\033[0m "
	read from <&2
	i=0
	clear
	while read line ;do
	loopbreak=0;	nextmessagestatus=1;	mailtostatus=1;		mailsubstatus=1;	stat=1;
	toecho=`echo $line | grep -E "^From:+" | grep -E "${from}"`
	if [ "$toecho" != "" ];then
		i=`expr $i + 1`
		echo -e "${toecho}"
		while read line ; do
		mailto=`echo $line | grep -E "^To:+"`
		mailsub=`echo $line | grep -E "^Subject:+"`
		if [[ "$mailto" != "" ]] && [[ $mailtostatus == 1 ]];then
			echo $mailto
			mailtostatus=0
		fi
		if [[ "$mailsub" != "" ]] && [[ $mailsubstatus == 1 ]];then
			echo $mailsub
			mailsubstatus=0
		fi
		if [[ $mailtostatus == 0 ]] && [[ $mailsubstatus == 0 ]] && [[ $stat == 1 ]];then
			echo -e "\033[33mStarting of the Message${i}:\033[0m"
			stat=0
		fi
		fromstatus=`echo $line | grep -E "^X-UID:+"`
			if [[ $fromstatus != "" ]];then
			while read line; do
				loopstatus=`echo $line | grep -E "^From +"`
				if [[ $loopstatus != "" ]];then
				loopbreak=1
				break
				fi
				echo $line
			done
			if [[ $loopbreak == 1 ]];then
			echo -e -n "\033[33mEnd of the Message${i}.\nDisplay next message(y/n):\033[0m"
			read messagestatus <&2
			if [[ "$messagestatus" == "y" ]];then
				clear
			else
				nextmessagestatus=0
			fi
			break
			fi
			fi
		done
		count=`expr $count + 1`
	fi
	if [[ $nextmessagestatus == 0 ]];then
		break
	fi
	done
	if [[ $count == 0 ]];then
		echo -e "\033[32mNo mail(s) From: ${from}.\n\033[0m"
	else
		echo -e "\033[32mTotal $count mail(s) From: ${from}.\n\033[0m"
	fi
elif [[ $int == 2 ]];then
	echo -n -e "\033[32mTo: \033[0m"
	read to <&2
	i=0
	clear
	while read line ;do
	loopbreak=0;	nextmessagestatus=1
	toecho=`echo $line | grep -E "^To:+" | grep -E "${to}"`
	if [[ "$toecho" != "" ]];then
		echo -e "$toecho"
		i=`expr $i + 1`
		while read line; do
			tostatus=`echo $line | grep -E "^X-UID:+"`
			if [[ $tostatus != "" ]];then
			echo -e "\033[33mStarting of the Message${i}:\033[0m"
			while read line; do
				loopstatus=`echo $line | grep -E "^From +"`
				if [[ $loopstatus != "" ]];then
				loopbreak=1
				break
				fi
				echo $line
			done
			if [[ $loopbreak == 1 ]];then
			echo -e -n "\033[33mEnd of the Message${i}. \nDisplay next message(y/n): \033[0m"
			read messagestatus <&2
			if [[ $messagestatus == "y" ]];then
				clear
			else
				nextmessagestatus=0
			fi
			break
			fi
			fi
		done
		count=`expr $count + 1`
	fi
	if [[ $nextmessagestatus == 0 ]];then
		break
	fi
	done
	if [[ $count == 0 ]];then
		echo -e "\033[32mNo mail(s) to: ${to}.\n\033[0m"
	else 
		echo -e "\033[32mTotal $count mail(s) To: ${to}.\n\033[0m"
	fi
elif [[ $int == 3 ]];then
	echo -n -e "\033[32mSubject:\033[0m "

	read subject <&2
	clear
	i=0
	while read line ;do
	loopbreak=0;	nextmessagestatus=1
	toecho=`echo $line | grep -E "^Subject:+" | grep -E "${subject}"`
	if [[ "$toecho" != "" ]];then
		echo "$toecho"
		i=`expr $i + 1`
		while read line; do
		substatus=`echo $line | grep -E "^X-UID:+"`
		if [[ $substatus != "" ]];then
		echo -e "\033[33mStarting of the Message${i}:\033[0m"
		while read line ; do
			loopstatus=`echo $line | grep -E "^From +"`
			if [[ $loopstatus != "" ]];then
			loopbreak=1
			break
			fi
			echo $line
		done
		if [[ $loopbreak == 1 ]];then
		echo -e -n "\033[33mEnd of the message${i}. \nDisplay next message(y/n): \033[0m"
		read messagestatus <&2
		if [[ $messagestatus == "y" ]];then
			clear
		else
			nextmessagestatus=0
		fi
		break
		fi
		fi
		done
		count=`expr $count + 1`
	fi
	if [[ $nextmessagestatus == 0 ]];then
		break
	fi
	done
	if [[ $count == 0 ]];then
		echo -e "\033[32mNo mail(s) with Subject: ${subject}.\n\033[0m"
	else
		echo -e "\033[32mTotal $count mail(s) with Subject: ${subject}.\033[0m\n"
	fi
elif [[ $int == 4 ]];then
	echo -e "\033[32mThank you for using this utility. \nPlease visit again.\033[0m"
	exit
else
	echo -e "\033[32mI could not understand that. \nPlease try again.\033[0m\n"
fi
echo -e -n "\033[32m1) Sender... \n2) Receiver... \n3) Subject... \n4) Quit... \nPress(1,2,3,4):\033[0m "
read int <&2
break
done < mbox 
done 
]]>
https://gofedora.com/hack-mail-filter-shell-script/feed/ 4
Hack: Graphical Implementation of CP Command https://gofedora.com/hack-graphical-implementation-cp-command/ https://gofedora.com/hack-graphical-implementation-cp-command/#comments Sat, 03 Dec 2005 09:33:48 +0000 http://172.17.8.64/gofedora/?p=260 … ]]> To use this graphical interface do as directed below:

#!/bin/bash
##############################
# Author - Kulbir Saini      #
# Home - http://saini.co.in/ #
##############################

if [ $1 == -i ] || [ $1 == -f ];then          
	if [ ! -s $2 ] && [ ! -f $2 ] && [ ! -d $2 ];then
		dialog --title "Copy daemon" --backtitle "copy:" --infobox "file:$2 doesn't exist.\nCan't copy...\nPress any key..." 5 30; read
	elif [ ! $3 ];then
		dialog --title "Copy daemon" --backtitle "copy:" --infobox "Invalid arguements...\nCan't copy...\nPress any key..." 5 30; read
	elif [ -d $3 ];then
		dialog --title "Copy daemon" --backtitle "copy:" --infobox "$3: is a directory.\nCan't copy...\nPress any key..." 5 30; read
	elif [ -d $2 ];then
		dialog --title "Copy daemon" --backtitle "copy:" --infobox "$2: is a directory.\nCan't copy...\nPress any key..." 5 30; read
	elif [ -s $3 -o -f $3 ];then
		dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to overwrite file:$3" 10 60;
		select=$?
		case $select in 
			0) echo -e "i'm ordered to overwrite file:$3 \noverwriting...\noverwritten file:$3" ; cp -f $2 $3 ;;
			1) echo "i'm ordered not to overwrite.";;
			255) echo "cancelled by you by pressing [Esc].";;
		esac
	else
		dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to copy the file:$2 to file:$3" 10 60 ;
		select1=$?
		case $select1 in
			0) echo -e "i'm ordered to copy file:$2 to file:$3 \ncopying...\ncopied to file:$3" ; cp $2 $3 ;;
			1) echo "i'm ordered not to copy.";;
			255) echo "cancelled by you by pressing [Esc].";;
		esac
	fi
elif [ ! -s $1 ] && [ ! -f $1 ] && [ ! -d $1 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "file:$1 doesn't exist.\nCan't copy...\nPress any key..." 5 30; read
elif [ ! $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "Invalid arguements...\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$2: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $1 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$1: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -s $2 -o -f $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to overwrite file:$2" 10 60;
	select=$?
	case $select in 
		0) echo -e "i'm ordered to overwrite file:$2 \noverwriting...\noverwritten file:$2" ; cp -f $1 $2 ;;
		1) echo "i'm ordered not to overwrite.";;
		255) echo "cancelled by you by pressing [Esc].";;
	esac
else
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to copy the file:$1 to file:$2" 10 60 ;
	select1=$?
	case $select1 in
		0) echo -e "i'm ordered to copy file:$1 to file:$2 \ncopying...\ncopied to file:$2" ; cp $1 $2 ;;
		1) echo "i'm ordered not to copy.";;
		255) echo "cancelled by you by pressing [Esc].";;
	esac
fi

1. Get the script here .

2. Move it to a file named ‘copy’.

3. Create a director ‘bin’ in your home directory.

4. Write

export PATH=$PATH:${HOME }/bin/

to your ~/.bashrc file.

5. Execute .bashrc by issuing

[saini@localhost ~]# . .bashrc

6. If you want to copy a file foo.txt to bar.txt then do it as

[saini@localhost ~]# copy foo.txt bar.txt [Enter]

Done.

]]>
https://gofedora.com/hack-graphical-implementation-cp-command/feed/ 2