Sunday, July 27, 2008

Corrupted Flash Card - Recovery of FAT32 Files

Recently, I was getting ready to copy some images from a "full" memory card, to my pc for archive. Somewhere during the process, the fat32 file system on the card, got confused, and the directory where the images were simply disappeared.

What to do now? I tried chkdsk? Nothing
I tried the "Trash" folder, Again nothing.
Over 540+ irreplaceable photos from my Nikon D70 were
gone.

So doing some research, I found many a "pay" solutions.
But not really wanting to pay, I wanted to find a "free"
solution, without running into a virus, spyware, etc.

After looking at three or four, I found my solution.

PhotoRec.
The interface is a bit primative, but it worked perfectly.
The first time. Every photo was recovered.

So if you hit that problem, give it a try.
Cost is $0.00. Very good perfomance for the price.

http://www.cgsecurity.org/wiki/PhotoRec

Thursday, July 10, 2008

Dynamic Tabnav Widget menus

I wanted to do a "dynamic" menu that is filled from data in my Rails Application.
I have a "table" (Model in rails speak) that has the values. Then I can "overload"
the controller to add more functionality.

The "gotcha" in coding this is, there is "no" each method for activerecord.

The other "gotcha" is a "site" can have mutliple networks, so since we are selecting my "site", and network does not have it, we do a lookup in the conditions_for_collections code. Note that active_scaffold can also "view" the devices via the site controller. But I find having "buttons" on the device controller a nice interface.

Using this technique, I can "dry" up the controller, and reuse it for several "purposes". No need to repeat the "controller".

Note that we have to "pass" the level3 status up thru the controller, and then back down thru the partials.

First the widgets for tabnav

File: app\views\widgets\_device_tier2_tabnav.rhtml
<%
level3 = nil
render_tabnav :device_tier2,
:generate_css => true do

add_tab do |t|
t.named 'All'
t.titled 'All'
t.links_to :controller => 'device'
end
add_tab do |t|
t.named 'Sites'
t.named 'Sites'
t.links_to :controller => 'device?level3=device_sites_tier3'
end
end
%>

File: app/views/widgets/_device_sites_tier3_tabnav.rhtml
<%
render_tabnav :device_sites_tier3,
:generate_css => true do
Site.find(:all).each do |thesite|
add_tab do |t|
t.named thesite.name
t.links_to :controller => "device?site=#{thesite.id}&level3=device_sites_tier3"
end
end
end
%>

File app\views\layouts\tier2device.rhtml
<html>
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
<%= stylesheet_link_tag "/javascripts/jscalendar-1.0/calendar-win2k-cold-1.css" %>
<%= javascript_include_tag "jscalendar-1.0/calendar.js" %>
<%= javascript_include_tag "jscalendar-1.0/lang/calendar-en.js" %>
<%= javascript_include_tag "jscalendar-1.0/calendar-setup.js" %>
<head>
<title>AppName</title>
</head>

<body>
<br>

<%= tabnav :airstate %>
<%= tabnav :device_tier2 %>
<% if @level3 %>
<%= tabnav @level3 %>
<% end %>
<%= @content_for_layout %>
</body>
</html>

The controller, which is using activescaffold looks like this:
class DeviceController < ApplicationController
layout 'tier2device'


active_scaffold :device do |config|
config.actions = [:delete,:show, :list, :nested, :search]
config.list.columns = [:network, :name, :serialnum, :model, :macs, :purchase_date, :warranty_end]
config.columns[:macs].ui_type = :select
config.columns[:network].ui_type = :select
config.columns[:user].ui_type = :select
end

def conditions_for_collection

@level3 = nil
if params.include?("level3")
@level3 = params.delete("level3")
end
if params.include?("site")
mysite = params.delete("site")
mynets = Network.find(:all,:conditions => "site_id = #{mysite}")
mywhere = ['network_id IN (?)', mynets]
end

return mywhere
end


end



References - No .each in active record
http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord

Sunday, July 06, 2008

Reading the Service Tag or Serial Number in Ruby

I want to "do" a inventory of "all" my equipment. (Yes It will eventually be a Rails app), but the first issue is gettig all the "service" tags, and updating them on the fly. If you search, you'll find plenty of examples in vb or python, but not very many. (Read none) in ruby. So I decided to see if I could do it.

First I liked the ruby-wmi package, that gives a activerecord flavor to wmi. WMI is windows standard "Instrumentation" library, where you can find out all too many facts about a windows system.

Next a little "code" of my own to show "how" to do it. Implemented as a class on top of ruby-wmi, with some basic "caching" to make the overhead smaller.

require 'ruby-wmi'
require 'pp'

# Reference URL's
# http://www.vbforums.com/showthread.php?t=326425
# http://ruby-wmi.rubyforge.org/doc/classes/WMI/Base.html
# http://mentalpagingspace.blogspot.com/2008/01/ruby-class-tutorial-using-unify-dbi.html

class ManagePC

def initialize(ipaddress)

@myip = ipaddress
@biosv = WMI::Win32_BIOS.find(:all,:host=>@myip)
@csysv = WMI::Win32_ComputerSystem.find(:all,:host=>@myip)
@netv = WMI::Win32_NetworkAdapterConfiguration.find(:all,
:conditions => 'IPEnabled = True')
return

end #initialize

def prtnetvalues()
@netv.each do |netx|
netx.properties_.each do |p|
value = netx[p.name]
if value
if value.class == Fixnum
value = value.to_s
end
if value.class == Array
value = value.to_s
end
if value.class == TrueClass
if value
value = "True"
else
value = "False"
end
end
theprop = p.name + "="
theprop << value
puts theprop
end
end
end
end # prtnetvalues()

def prtcsysvalues()
@csysv.each do |csys|
csys.properties_.each do |p|
printf "#{p.name} = #{csys[p.name]}\n"
end
end
end # prtcsysvalues()


def netvalue(name)
@netv.each do |netx|
netx.properties_.each do |p|
if p.name == name
return netx[name]
end
end
end
return nil
end

def csysvalue(name)
@csysv.each do |csys|
csys.properties_.each do |p|
if p.name == name
return csys[name]
end
end
end
return nil
end

def macs()
mymacs = Array.new
current_mac = nil
@netv.each do |netx|
netx.properties_.each do |p|
if p.name == "IPAddress"
current_mac << netx[p.name].to_s
end
if p.name == "MACAddress"
current_mac << netx[p.name]
end
if p.name == "Caption" # A new network interface
if current_mac
mymacs << current_mac
end
current_mac = Array.new
end
end
end
mymacs << current_mac
return(mymacs)
end


def domain()
return csysvalue("Domain")
end

def model()
return csysvalue("Model")
end

def name()
return csysvalue("Name")
end

def domain?()
return csysvalue("PartOfDomain")
end

def username()
return csysvalue("UserName")
end

def memory()
return csysvalue("TotalPhysicalMemory")
end

def servicetag()
@biosv.each do |bios|
bios.properties_.each do |p|
if p.name == "SerialNumber"
return(bios[p.name])
end
end
end
return(nill)
end #GetServiceTag

end #ManagePC


mypc = ManagePC.new("127.0.0.1")
puts mypc.servicetag
puts mypc.domain
puts mypc.model
puts mypc.name
puts mypc.username
puts mypc.memory
pp mypc.macs

Tuesday, July 01, 2008

Annoucing PDFTORUBY Support Forum

PDFtoRuby now has a support "forum" hosted via Google Groups.
If your having issues or problems with PDFtoRuby, or its "just" working
please feel free to drop a message on the board.

I'll be glad to help "resolve" any issues you have

http://groups.google.com/group/pdftoruby?hl=en