<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: script code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 01:35:53 GMT</pubDate>
    <description>DZone Snippets: script code</description>
    <item>
      <title>Monitor disk usage with a simple Ruby script</title>
      <link>http://snippets.dzone.com/posts/show/5754</link>
      <description>&lt;code&gt;&lt;br /&gt;dev = 'sda1'&lt;br /&gt;report = `df -h`&lt;br /&gt;disk_remaining = report[/sda\w+\s+\d+?.?\dG\s+\d+?.?\dG\s+(\d+.?\d+?G)/,1]&lt;br /&gt;puts "running low on disk space (#{dev}: #{disk_remaining })" if disk_remaining.to_i &lt; 3&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 10 Jul 2008 12:40:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5754</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Executing a Ruby script from Asterisk</title>
      <link>http://snippets.dzone.com/posts/show/5527</link>
      <description>To run a Ruby script from Asterisk you need 2 things 1) an extension to run the script from 2) a Ruby script.&lt;br /&gt;&lt;br /&gt;* Preparing the evironment *&lt;br /&gt;1) create a script directory for Asterisk and ensure it has permission to run the scripts. &lt;br /&gt;&lt;br /&gt;* Running the script *&lt;br /&gt;1) Dial extension 3000&lt;br /&gt;2) Listen to the voice say 'hello world'&lt;br /&gt;3) Observe a new output.txt file has been created containing the message 'hello world!'&lt;br /&gt;&lt;br /&gt;file: hello-world.rb&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;#file : hello-world.rb&lt;br /&gt;&lt;br /&gt;file = File.new('/etc/asterisk/ruby/output.txt','w')&lt;br /&gt;file.puts 'hello world!'&lt;br /&gt;file.close&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;file: extensions.rb&lt;br /&gt;&lt;code&gt;&lt;br /&gt;exten =&gt; 3000,1,Playback(hello-world)&lt;br /&gt;exten =&gt; 3000,n,System(/etc/asterisk/ruby/./hello-world.rb)&lt;br /&gt;exten =&gt; 3000,n,Hangup&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;file: output.txt&lt;br /&gt;&lt;code&gt;&lt;br /&gt;hello world!&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 May 2008 20:10:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5527</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Externally reference ECMAScript in an SVG file</title>
      <link>http://snippets.dzone.com/posts/show/5408</link>
      <description>source: &lt;a href="http://www.it.rit.edu/~jxs/svg/tutorials/scripting.html"&gt;Using Internal &amp; External Scripts,&lt;/a&gt; [rit.edu]&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/ecmascript" xlink:href="scripts/changeCircle.js"/&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 20 Apr 2008 19:21:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5408</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>[Ruby] Script/bot to send MediaWiki Recent Changes over UDP to a Campfire room</title>
      <link>http://snippets.dzone.com/posts/show/5037</link>
      <description>Requires the Tinder gem, and PHP on the server running MediaWiki must be compiled with --enable-sockets. The computer running the bot will also have to be open to the web - it can't be behind a firewall.&lt;br /&gt;&lt;br /&gt;First, add this code to your MediaWiki LocalSettings.php, replacing the IP address with the IP of the server/computer running the bot, and the port to whatever you want to use (probably something above 40,000, but it's up to you):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$wgRC2UDPAddress = '69.178.6.244';&lt;br /&gt;$wgRC2UDPPort = '41895';&lt;br /&gt;$wgRC2UDPPrefix = "";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now, you can run the bot! This is extremely hackish, because the retarded collective-mailing-list-coding system of the MediaWiki repos has somehow managed to code IRC color codes directly into their exported strings (at least with MediaWiki 1.2alpha, which is what I'm running right now).&lt;br /&gt;You'll need to replace the new tinder definition with your subdomain on Campfire, the username and password with ones for the bot account you've created on your campfire room, and the room name with the room you want the updates to be sent to.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'tinder'&lt;br /&gt;require 'socket'&lt;br /&gt;puts 'Dependencies loaded...'&lt;br /&gt;&lt;br /&gt;campfire = Tinder::Campfire.new 'subdomain'&lt;br /&gt;campfire.login 'email@domain.com', 'password'&lt;br /&gt;exit unless room = campfire.find_room_by_name('Case Sensitive Room Name')&lt;br /&gt;puts 'Campfire logged in...'&lt;br /&gt;&lt;br /&gt;server = UDPSocket.new&lt;br /&gt;exit unless server.bind('0.0.0.0', 41895)&lt;br /&gt;puts 'Socket listening...'&lt;br /&gt;&lt;br /&gt;loop do&lt;br /&gt;  msg = server.recv(2048).gsub(/\003[\d]{0,2}/,'').chomp&lt;br /&gt;  print "sending to room: #{msg.inspect}..."&lt;br /&gt;  exit unless room.speak msg.to_s&lt;br /&gt;  puts ' sent!'&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Jan 2008 14:29:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5037</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>Unix shell script providing Ruby on Rails enhanced String methods</title>
      <link>http://snippets.dzone.com/posts/show/4793</link>
      <description>Assuming you have Rails installed as a gem, the following Unix shell script (which I named String, but you can name anything you want when you save the following into a file) allows you to call Ruby String methods (including, importantly, the methods that the Rails ActiveSupport extensions add) on an arbitrary number of arguments, and it will print out the results, e.g.,&lt;br /&gt;&lt;br /&gt;$ String camelize snake_case_example another_snake_case_example&lt;br /&gt;&lt;br /&gt;The output is:&lt;br /&gt;&lt;br /&gt;SnakeCaseExample&lt;br /&gt;AnotherSnakeCaseExample&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;if ARGV.size &gt; 1 then&lt;br /&gt;  gem 'activesupport'&lt;br /&gt;  require 'active_support/core_ext/string/inflections'&lt;br /&gt;&lt;br /&gt;  class String&lt;br /&gt;    include ActiveSupport::CoreExtensions::String::Inflections&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  command = ARGV.shift&lt;br /&gt;  ARGV.each { |argument|&lt;br /&gt;    puts argument.send( command )&lt;br /&gt;  }&lt;br /&gt;else&lt;br /&gt;  # Print usage information&lt;br /&gt;  puts "Usage: #{File.basename( __FILE__ )} &lt;command&gt; &lt;argument_1&gt; [&lt;argument_2&gt; ...]"&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Nov 2007 04:49:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4793</guid>
      <author>HotFusionMan (Al Chou)</author>
    </item>
    <item>
      <title>PHP : Hace Script / Ago Script</title>
      <link>http://snippets.dzone.com/posts/show/4674</link>
      <description>Hace Script / Ago Script&lt;br /&gt;if we call with a timestamp of a month ago, he print "Hace 1 mes". If you want this in english should traduction. Sorry my english&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function hace($timestamp)&lt;br /&gt;{&lt;br /&gt;$diferencia = time() - $timestamp;&lt;br /&gt;	if($diferencia &gt; 0)&lt;br /&gt;	{&lt;br /&gt;$periodo = array("segundo", "minuto", "hora", "dia", "semana", "mes" , "a&amp;ntilde;o", "decada");&lt;br /&gt;$longitud = array(           "60"    , "60"  , "24" , "7"     , "4.35", "12"       , "10"    );&lt;br /&gt;	&lt;br /&gt;	for($j = 0; $diferencia &gt;= $longitud[$j]; $j++)&lt;br /&gt;	$diferencia /= $longitud[$j];&lt;br /&gt;	&lt;br /&gt;	$diferencia = round($diferencia);&lt;br /&gt;	&lt;br /&gt;	if($diferencia != 1)&lt;br /&gt;	{&lt;br /&gt;		if($periodo[$j] == "mes")&lt;br /&gt;		$periodo[$j].= "es";&lt;br /&gt;		else&lt;br /&gt;		$periodo[$j].= "s";&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	return "Hace &lt;b&gt;".$diferencia."&lt;/b&gt; ".$periodo[$j];&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 19 Oct 2007 08:34:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4674</guid>
      <author>Ricardo (Ricardo m. Garc&#237;a)</author>
    </item>
    <item>
      <title>Download all xkcd.com comics</title>
      <link>http://snippets.dzone.com/posts/show/4658</link>
      <description>This goes through all the first 329 (you might want to change this) pages, downloading the comic strips.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;for i in `seq 1 329`&lt;br /&gt;do&lt;br /&gt;	wget http://xkcd.com/$i/&lt;br /&gt;	wget `grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2`&lt;br /&gt;	rm index.html&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 15 Oct 2007 18:05:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4658</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Flac to mp3</title>
      <link>http://snippets.dzone.com/posts/show/4605</link>
      <description>Converts all *.flac files in the current dir to mp3.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;for file in *.flac&lt;br /&gt;do&lt;br /&gt;	echo Converting $file&lt;br /&gt;	flac123 -q --wav=- "$file" | lame - "$file".mp3&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 02 Oct 2007 18:02:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4605</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Get the name of the script that is running</title>
      <link>http://snippets.dzone.com/posts/show/3771</link>
      <description>&lt;code&gt;&lt;br /&gt;script-name: does [system/options/script]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Apr 2007 18:14:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3771</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>rails related svn configurator</title>
      <link>http://snippets.dzone.com/posts/show/3363</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;svn remove log/*&lt;br /&gt;svn commit -m"removing log files" &lt;br /&gt;svn propset svn:ignore "*.log" log/&lt;br /&gt;svn update log/&lt;br /&gt;svn commit -m 'Ignoring all files in /log/ ending in .log'&lt;br /&gt;svn move config/database.yml config/database.example&lt;br /&gt;svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'&lt;br /&gt;svn propset svn:ignore "database.yml" config/&lt;br /&gt;svn update config/&lt;br /&gt;svn commit -m 'Ignoring database.yml'&lt;br /&gt;svn remove tmp/*&lt;br /&gt;svn propset svn:ignore "*" tmp/&lt;br /&gt;svn update tmp/&lt;br /&gt;svn commit -m "ignore tmp/ content from now" &lt;br /&gt;svn propset svn:ignore ".htaccess" config/&lt;br /&gt;svn update config/&lt;br /&gt;svn commit -m 'Ignoring .htaccess'&lt;br /&gt;svn propset svn:ignore "dispatch.fcgi" config/&lt;br /&gt;svn update config/&lt;br /&gt;svn commit -m 'Ignoring dispatch.fcgi'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 25 Jan 2007 07:27:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3363</guid>
      <author>caffo ()</author>
    </item>
  </channel>
</rss>
