Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 21 total  RSS 

Externally reference ECMAScript in an SVG file

source: Using Internal & External Scripts, [rit.edu]
<script type="text/ecmascript" xlink:href="scripts/changeCircle.js"/>

[Ruby] Script/bot to send MediaWiki Recent Changes over UDP to a Campfire room

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.

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):
$wgRC2UDPAddress = '69.178.6.244';
$wgRC2UDPPort = '41895';
$wgRC2UDPPrefix = "";


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).
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.
require 'rubygems'
require 'tinder'
require 'socket'
puts 'Dependencies loaded...'

campfire = Tinder::Campfire.new 'subdomain'
campfire.login 'email@domain.com', 'password'
exit unless room = campfire.find_room_by_name('Case Sensitive Room Name')
puts 'Campfire logged in...'

server = UDPSocket.new
exit unless server.bind('0.0.0.0', 41895)
puts 'Socket listening...'

loop do
  msg = server.recv(2048).gsub(/\003[\d]{0,2}/,'').chomp
  print "sending to room: #{msg.inspect}..."
  exit unless room.speak msg.to_s
  puts ' sent!'
end

Unix shell script providing Ruby on Rails enhanced String methods

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.,

$ String camelize snake_case_example another_snake_case_example

The output is:

SnakeCaseExample
AnotherSnakeCaseExample

#!/usr/bin/env ruby

if ARGV.size > 1 then
  gem 'activesupport'
  require 'active_support/core_ext/string/inflections'

  class String
    include ActiveSupport::CoreExtensions::String::Inflections
  end

  command = ARGV.shift
  ARGV.each { |argument|
    puts argument.send( command )
  }
else
  # Print usage information
  puts "Usage: #{File.basename( __FILE__ )} <command> <argument_1> [<argument_2> ...]"
end

PHP : Hace Script / Ago Script

Hace Script / Ago Script
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

function hace($timestamp)
{
$diferencia = time() - $timestamp;
	if($diferencia > 0)
	{
$periodo = array("segundo", "minuto", "hora", "dia", "semana", "mes" , "a&ntilde;o", "decada");
$longitud = array(           "60"    , "60"  , "24" , "7"     , "4.35", "12"       , "10"    );
	
	for($j = 0; $diferencia >= $longitud[$j]; $j++)
	$diferencia /= $longitud[$j];
	
	$diferencia = round($diferencia);
	
	if($diferencia != 1)
	{
		if($periodo[$j] == "mes")
		$periodo[$j].= "es";
		else
		$periodo[$j].= "s";
	}
	
	return "Hace <b>".$diferencia."</b> ".$periodo[$j];
	}
}

Download all xkcd.com comics

This goes through all the first 329 (you might want to change this) pages, downloading the comic strips.

#!/bin/bash

for i in `seq 1 329`
do
	wget http://xkcd.com/$i/
	wget `grep http://imgs.xkcd.com/comics/ index.html | head -1 | cut -d\" -f2`
	rm index.html
done

Flac to mp3

Converts all *.flac files in the current dir to mp3.

#!/bin/bash

for file in *.flac
do
	echo Converting $file
	flac123 -q --wav=- "$file" | lame - "$file".mp3
done

Get the name of the script that is running

script-name: does [system/options/script]

rails related svn configurator

#!/bin/sh
svn remove log/*
svn commit -m"removing log files" 
svn propset svn:ignore "*.log" log/
svn update log/
svn commit -m 'Ignoring all files in /log/ ending in .log'
svn move config/database.yml config/database.example
svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'
svn propset svn:ignore "database.yml" config/
svn update config/
svn commit -m 'Ignoring database.yml'
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content from now" 
svn propset svn:ignore ".htaccess" config/
svn update config/
svn commit -m 'Ignoring .htaccess'
svn propset svn:ignore "dispatch.fcgi" config/
svn update config/
svn commit -m 'Ignoring dispatch.fcgi'

Start rails dev env

Here's the script I use to start up my Rails editing environment. It assumes you are in the RAILS_ROOT folder, and you have textmate and mongrel.

#!/bin/sh
killall ruby
mongrel_rails start -d
sleep 1
open http://localhost:3000/
sleep 1
mate .

Linux - command ls without color

// Elimina tutti i caratteri speciali che portano il colore

ls --color=never
« Newer Snippets
Older Snippets »
Showing 1-10 of 21 total  RSS