Archive for August, 2009

CRM Systems

Sunday, August 9th, 2009

Checking out SugarCRM in terms of features and capabilities:

Helps when you are running Ubuntu on your laptop:
http://www.howtoforge.com/installing-sugarcrm-community-edition-on-ubuntu-8.10

Search & Move in Ruby

Tuesday, August 4th, 2009

Its interesting that one can still get an adrenalin rush from coding…
Ever wanted to be able to move a set of opening and closing tag from one part of the document to another? Across 100 files?

This was a quick hack I did up over a night in Ruby.

#### Initialisation ############
files = Array.new
filelines = Array.new
locationfiletype = “/home/yuit/*.html”
destinationfolder = “/home/yuit/Desktop/”
loggingfolder = “/home/yuit/Desktop/”

#### loading all files into memory ######
files = Dir["#{locationfiletype}"]
files.each do |f|
# puts “#{f}”

filename = “#{f}”.split(’/')
filelines = IO.readlines(”#{f}”)
puts “Opening file #{f}”

############################################
## initial scanning : Form tag replacement##
############################################
a = 0
foundstarttagsource = false
foundendtagsource = false
foundstarttagdestination= false
foundendtagdestination = false
locationstarttagsource = 0
locationstarttagdestination = 0
locationendtagsource = 0
locationendtagdestination = 0

filelines.each do |g|
if “#{g}”.include? “

” then
locationstarttagsource = a
foundstarttagsource = true
end
if “#{g}”.include? “” then
locationstarttagdestination = a
foundstarttagdestination = true
end
if “#{g}”.include? “” then
locationendtagsource = a
foundendtagsource = true
end
if “#{g}”.include? “

Notes:” then
locationendtagdestination = a
foundendtagdestination = true
end
a = a+1
end

if foundstarttagsource && foundstarttagdestination && foundendtagsource && foundendtagdestination then
puts “Found the form tag in #{f}”
puts “#{locationstarttagsource}, #{locationendtagsource}, #{locationstarttagdestination}, #{locationendtagdestination}”
filelines[locationstarttagsource].gsub!(”
“,”)
filelines[locationendtagsource].gsub!(”",”)
filelines[locationendtagdestination].gsub!(”

Notes:”,’

Notes:

‘)
filelines.insert(locationstarttagdestination,”

“)

file_output = File.open(”#{destinationfolder}#{filename[-1]}”, “w”)
filelines.each {|line| file_output.puts “#{line}”}
file_output.close

else
File.open(”#{loggingfolder}error_replacement.log”, ‘a+’) { |file| file << “#{Time.now}\t #{f}\t : Form tag not replaced\t #{foundstarttagsource}\t#{foundstarttagdestination}\t#{foundendtagsource}\t#{foundendtagdestination}\n”}

end
end

#### Clearing up memory ##########
files.clear
filelines.clear