|
|
|
Tuesday, 26 July 2011 11:24 |
// description of your code here
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries
controllers.each do |controller|
if controller =~ /_controller/
cont = controller.camelize.gsub(".rb","")
puts cont
(eval("#{cont}.new.methods") -
ApplicationController.methods -
Object.methods -
ApplicationController.new.methods).sort.each {|met|
puts "\t#{met}"
}
end
end
 Read more: |
|
|
Wednesday, 08 December 2010 03:01 |
// Excel to GraphViz RDF Converter *Ruby*
#!/usr/bin/env ruby -W0
# =============================================================================
# File: excel2dot.rb
# Decription: utility to convert RDF triples listed in Excel to GraphViz "dot"
# formatted files.
# Usage: ./excel2dot InFile.xls OutFile[.dot] graph_name graph_dir
# : InFile.xls - File with 3 columns (first row is skipped)
# : OutFile[.dot] Output file in GraphViz DOT format
# : graph_name - any textname (no spaces) for the Digraph name
# : graph_dir - "v" top-down oriented, "h" left to right oriented
# Version: 0.2
# =============================================================================
require 'rubygems'
require 'spreadsheet'
numArgs = ARGV.count
# Check to ensure that we have at least 2 arguments (input and output file)
if numArgs < 2
puts "Usage: ./excel2dot RDF_TriplesSpreadsheet.xls GraphVizDotFile[.vg] graph_name graph_dir"
else
if numArgs < 3
GraphName = "my_graph"
else
GraphName = ARGV[2].to_s
end
# Default to Horizontal Graphing unless specified
if numArgs < 4
GraphDir = "h"
else
GraphDir = ARGV[3].to_s.downcase
end
# puts "Number of Args: " + ARGV.count.to_s
# puts "Spreadsheet File:" + ARGV[0]
# puts "GraphViz Dot File:" + ARGV[1]
puts "Coverting Spreadsheet Triples to Dot..."
# Open Input Triples Excel Spreadsheet
book = Spreadsheet.open ARGV[0]
# Open Output GraphViz Dot File
gvdFile = File.new(ARGV[1],"w")
# Write header for dot file
gvdFile.puts "digraph #{GraphName} {"
sheet = book.worksheet 0
sheet.each(skip=1) do |row|
gvdFile.puts "\t"+ "\"#{row[0].strip}\"" + "\t-> " + "\"#{row[2].strip}\"" + "\t[label=" + "\"#{row[1].strip}\"];"
# if the short name predicate is encountered then change the color and shape of the graphic item for the video name
if row[1].strip == "video:short_name"
gvdFile.puts "\t\"#{row[2].strip}\"" + "\t[shape=polygon,sides=8,peripheries=2,color=purple,style=filled];"
end
end
# Set up the graphing flow direction
if (GraphDir == "h") || (GraphDir != "v")
gvdFile.puts "\trankdir=LR"
end
gvdFile.puts "}"
gvdFile.close
puts "Done!"
end
 Read more: |
|
|
Thursday, 21 October 2010 11:45 |
require 'mscorlib'
include System::Threading
include System::Threading::Tasks
Parallel.For(0, 100, lambda { |a| puts a })
 Read more: |
|
Monday, 13 September 2010 17:00 |
//Convert Db To Utf8codeine vs hydrocodone
class ConvertDbToUtf8 < ActiveRecord::Migration
def self.up
db_config = ActiveRecord::Base.connection.instance_values["config"]
db_name = db_config[:database]
db_user = db_config[:username]
db_pass = db_config[:password] || ''
latin1_dump = 'latin1_dump.sql'
utf8_dump = 'utf8_dump.sql'
print "Dumping database... "
system "mysqldump --user=#{db_user} --password='#{db_pass}' --add-drop-table --default-character-set=latin1 --insert-ignore --skip-set-charset #{db_name} > #{latin1_dump}"
puts "done"
print "Converting dump to UTF8... "
system "iconv -f ISO-8859-1 -t UTF-8 #{latin1_dump} | sed 's/latin1/utf8/' > #{utf8_dump}"
puts "done"
print "Recreating database..."
system "mysql --user=#{db_user} --password='#{db_pass}' --execute=\"DROP DATABASE #{db_name};\""
system "mysql --user=#{db_user} --password='#{db_pass}' --execute=\"CREATE DATABASE #{db_name} CHARACTER SET utf8 COLLATE utf8_unicode_ci;\""
puts "done"
print "Importing UTF8 dump..."
system "mysql --user=#{db_user} --password='#{db_pass}' --default-character-set=utf8 #{db_name} < #{utf8_dump}"
puts "done"
puts " *** don't forget to delete temp files #{latin1_dump} and #{utf8_dump}"
end
def self.down
raise "cant revert sorry"
end
end
37.5 phentermine Read more: |
|
|
|
|
|
|
Page 1 of 2 |