Archive for the 'script' Category

identi.ca feed plugin

Tuesday, July 8th, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?
$limitToShow = 10;
$xmlcontent = "";
$xfh = fopen("http://identi.ca/evolmachine/rss", "r");
 
while( !feof($xfh) ) {
	$xmlcontent .= fread( $xfh, 128 );
}
fclose( $xfh );
 
$feedArr = array();
 
$xml = simplexml_load_string( $xmlcontent );
 
foreach ( $xml->item as $item ) {
	$feedItem['title'] = (string) $item->title;
	$feedItem['link'] = (string) $item->link;
	$feedItem['description'] = (string) $item->description;
	$feedItem['date'] = (string) $item->date;
	array_push( $feedArr, $feedItem );
}?>
 
<ul>	
	<? 
	$count = 0;
	foreach( $feedArr as $item ) {
		if( $count < $limitToShow ) { ?>
			<li><a href="<?=$item['link'];?>"><?=$item['title'];?></a></li>
		<? $count+=1; }
	} ?>
</ul>

you do need php compiled with simplexml for this script to work. All you need then is to include this where you want your identi.ca feed to show up!

email obfuscation javascript

Monday, February 4th, 2008
<script>
	var ermail = "moc.liamg@lairetamciteneg";
	var ungarbled = "mailto:";	
	for( i = ermail.length-1; i >= 0; i-- ) {
		ungarbled += ermail[i];
	}
	document.getElementById('contact').href = ungarbled;
</script>

If you hate spam and dont want your email address from being harvesting via some crawler. why try and obfuscate your email using some simple javascript. this script simply reverses the order of a string which contains your email in reverse. It then looks for a link with an id of “contact” and replaces the href attribute with your email address.

rip an internet stream with a cronjob

Saturday, February 2nd, 2008

I listen to various internet radio stations through out my day and sometimes I just don?t have the time or am I in front of a computer at
the time. This prompted to write a script that gets run in the background by a cron job and quietly kills itself after a predetermined amount of time. The only requirement would be mplayer, a radiostream and a simple cronjob.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
# rip_steph_miller_show
 
source_stream="mms://38.116.147.100/SMS?MSWMExt=.asf"
dest_directory="/home/lando/podcasts/steph_miller/"
prefix="steph_miller"
postfix="asf"
 
date=`date +%Y-%m-%d`
dest_file="${dest_directory}${prefix}-${date}.${postfix}"
mplayer -dumpstream ${source_stream} -dumpfile ${dest_file} &
 
pid=$!
let "sleeptime=60*60*3" # 60secs*60mins*3hours = 3 hours
sleep ${sleeptime}
kill -15 $pid

grab the above bash script and replace the source_stream with the address to the stream you want ripped, then the dest_directory to where you want to save the ripped stream and finally replace the prefix to the name you want the saved rip stream to have and the postfix to the same extension the stream has.

No matter what you choose the prefix to be the file will be saved with the date added to keep from overwriting itself the next time the script
is run.

Save the script and place it in a safe out of the way directory where your cronjob can access it from. now we can take a look at the cron line that needs to be added.

0 9 * * 1-5 bash /home/lando/scripts/rip_steph_miller_show >/dev/null 2>&1

to access your users crontab enter the command “crontab -e” and enter the above cron line. This cron line will run every weekday at 9 am. for more information on crontabs you can visit this wiki or google crontabs for hundreds of examples.

The first couple of numbers and ?*?s are what tells the cronjob when to execute. immediately after your have the command to execute and at the very end any output that might end up in logs or mailed to your will be redirected to /dev/null. I wont go into a whole crontab tutorial because it really is a simple concept and there are already enough of those about.

hope this script help somebody and im rather new to bash scripting if anyone has any improvements let me know. kthxbye!

queue random songs onto mpd

Saturday, February 2nd, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# mpdrandom.py
 
import os, random
 
dbfile = '/home/foo/.mpd/mpd.db'
num_of_songs_to_add = 50
songs = []
 
dbfile = open(dbfile)
for line in dbfile.readlines():
	if line.startswith('file: '):
		songs.append( line.split('file:')[1].strip() )
dbfile.close()
 
random.shuffle(songs)
 
for i in range(num_of_songs_to_add):
	os.system("mpc add " + '"' + songs[i] + '"')

you need mpd and mpc for this script. all it does is goes to the database of songs that mpd created and parses out the filenames then shuffles them and adds n number of songs from the beginning of the array to the mpc playlist.

list directories in openbox menu

Saturday, February 2nd, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
# list dirs openbox pipe-menu
 
import os, os.path
 
home_dir='/home/lando'
file_manager='thunar'
dir_dic = {}
 
for file in os.listdir(home_dir):
	path = home_dir+'/'+file
	if os.path.isdir(path):
		base = os.path.basename(path)
		if not base.startswith('.'):
			dir_dic[base] = path
 
print "<openbox_pipe_menu>"
 
for base, path in sorted( dir_dic.iteritems() ):
	print "<item label=\"" + base + "\">"
	print "<action name=\"Execute\">"
	print "<execute>" + file_manager + " " + path + "</execute>"
	print "</action>"
	print "</item>"
 
print "</openbox_pipe_menu>"

the script above populates the menu with any directories under your home directory. all you need to tweak is line 7 to your file manager of choice. finally you need to add the following pipe menu item to your “~/.config/openbox/menu.xml” file under your root menu and tweak the execute path to where you saved the script. now run “openbox –reconfigure” and you should see it in your menu.

<menu id="screen-sessions-menu" label="Screen-Sessions" execute="python /home/lando/scripts/list_all_screen_sessions_pipe_menu.py"/>