domenica, aprile 15, 2007
Desktop
Ruby: lista + stampa file ruby nella directory corrente
Elenca tutti i .rb presenti nella directory corrente stampandoli a video
Dir.foreach(".") { |f|
if ( f !~ /^\./ && f !~ /\~$/ && f =~ /\.rb$/)
printf("-- %s --\n",f)
for r in File.new(f,'r').readlines do
printf("%s\n",r.chomp)
end
printf("-- %s --\n\n",f)
end
}
Etichette: ruby, sample, script
Ruby: unit test
Ruby test unit con il modulo 'test/unit'
require 'test/unit'
class TC_MyTest < Test::Unit::TestCase
# def setup
# end
# def teardown
# end
def test_fail
assert(false, 'Assertion was false.')
end
end
Scrivania
Chiudo con la scrivania nuova dell'ikea WOW finalmente ho sistemato un po' sto casino! Peccato che l'ordine sia durato un paio di giorni
C'era una volta
Natale 2006
Era da molto tempo che dovevo postarla :) oggi ho trovato il tempo :D
Exerb
Qui si trova uno script ruby per convertire uno script in un eseguibile win32!
Shell: sostituzione globale su file
#!/bin/sh
find . -name '*.txt' -exec perl -p -i.bak -e 's/old/new/' {} \; -print
Shell: Elenco delle maschere in un sorgente
$ egrep “^.MSK” $pgm |sed 's/!MSK=\s*//;s/\s*[|/]\s*/:/'|awk -F: '{printf(%s:%s,,,)}'|sed 's/,$//'
Ruby: marshaling via xml
Modulo disponibile all'indirizzo http://clabs.org/clxmlserial.htm
require 'cl/xmlserial'
class MyClass
include XmlSerialization
attr_accessor :attr
def initialize
attr = 0
end
end
doc = REXML::Document.new(File.open("class.xml"))
c = MyClass.from_xml(doc.root)
c.attr = 60
f = File.new("class.xml", File::CREAT|File::TRUNC|File::RDWR)
c.to_xml.write(f, -1)
f.close
Ruby : file system watcher
require "filesystemwatcher"
watcher = FileSystemWatcher.new()
watcher.addDirectory("/inetpub/ftproot", "*.xml")
watcher.sleepTime = 10
watcher.start { |status,file|
if(status == FileSystemWatcher::CREATED) then
puts "created: #{file}"
elsif(status == FileSystemWatcher::MODIFIED) then
puts "modified: #{file}"
elsif(status == FileSystemWatcher::DELETED then
puts "deleted: #{file}"
end
}
watcher.join() # join to the thread to keep the program alive
Iscriviti a Post [Atom]