Archive for the 'Scripts' Category

29
Aug

slashhardcore.rb is a station tuner for Digitally Imported radio

I updated this script! Forgot to bind the /hardcore command before. Grab it now!

I was surprised how easy it is to write an XChat plugin in Ruby, even though it would be cooler to see a the xchat-ruby bindings pimped out DSL style…oh well.

Download slashhardcore.rb

Windows users must modify @launcher to the path to their Winamp, Firefox, IE, or other shoutcast-compatible player.

# slashhardcore.rb - A faster way to tune in than the playlist bot.
# Should work on Windows if you set a valid browser/winamp location.
#
# Usage: Put in your $HOME/.xchat2 directory to autoload, and restart xchat,
# or type "/load /path/to/slashhardcore.rb"
#
# Commands: /pls <station, /stations (list stations), /hardcore
#
# Author: Logan Koester <logan@logankoester.com>
 
include XChatRuby
 
class SlashHardcore < XChatRubyPlugin
 
	attr_accessor :launcher
 
	def initialize( plugin )
		@launcher = "/usr/bin/firefox"
		hook_command( "pls", XCHAT_PRI_NORM,
			method ( :pls ),
			"Use /pls <station> to tune in. Use /stations to check list
			of stations at di.fm"
		)
		hook_command( "stations", XCHAT_PRI_NORM,
			method ( :stations_list ),
			"Fetches an updated list of DI.fm stations"
		)
		hook_command( "hardcore", XCHAT_PRI_NORM,
			method ( :hardcore ),
			"Tunes into the happyhardcore.com radio stream"
		)
		puts_fmt "Digitally Imported!"
	end
 
	# Alias for /pls hardcore
	def hardcore (words, words_eol, data)
		puts_fmt "Hardcore is good for you!"
		play "hardcore"
		return XCHAT_EAT_ALL
	end
 
	# Tunes you in using your browses's default application
	# for *.pls files
	def pls (words, words_eol, data)
		station = words[1]
		puts_fmt "Tuning into #{station} (using #{@launcher})"
		@plugin.command( "/msg #candyball test" )
		play station
		return XCHAT_EAT_ALL
	end
 
	def play (station)
		exec "#{@launcher} http://di.fm/mp3/#{station}.pls" if fork == nil
	end
 
	# Returns the playlist filenames of playlists at di.fm
	def stations_list (words, words_eol, data)
		require 'open-uri'
		uri = "http://www.di.fm/mobile/?type=mp3"
		index = URI.parse uri
		list = index.read.to_s.scan(/="\/mp3\/(.*)\.pls/).flatten
		puts_fmt list.join ", " # CSV string
		return XCHAT_EAT_ALL
	end
end
22
Aug

killevery is what happens when programmers don’t sleep

A simple Ruby script to kill all processes with a specific name.

Looking back on what I’ve done after a night’s rest with mixed horror and amusement, it seems this script is completely and totally useless, unless you’re looking for a half-hearted reimplementation of killall in Ruby. Why the hell did I write this?

Download the script to /usr/bin (or wherever) and chmod +x ./killevery

#!/usr/bin/ruby
def killevery(victim, options)
	processes = `ps -A | grep #{victim}`.scan(/(d+) .*/)
	if processes.length &gt; 0
		puts "Killing #{processes.length} processes named #{victim}"
		processes.each { |p|
			print `kill #{options} #{p}`
		}
	else
		puts "No processes are named #{victim}."
	end
end
if $*.length &lt; 1
	puts "Kill every process named &gt;name&lt;. Takes the same parameters as killall"
else
	killevery($*.pop, $*.join(' '))
end



RSS Latest tweet

  • logankoester: Locked out of my apartment... Woops

Flickr Randomness

www.flickr.com

Netflix Queue


EveningMama's BoyRainbow Brite and the Star StealerThe Brazilian JobThe Gene GenerationParty Monster