2009-06-02

Copy of nice Date Time Format in Ruby

I got this from here http://snippets.dzone.com/posts/show/2255

------------------------------------------------------------------- Time#strftime
time.strftime( string ) => string
---------------------------------------------------------------------------------
Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.

"
Format meaning:

%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"
"

2009-06-01

Getting Excel addins to work with Ruby

I was having difficulty with this until I came across this post by bbiker.  The problem is that when you open Excel with a program OLE link it has a different environment to that when you open manually.  Specifically addins might not work and need to be kicked.

I put it to work with the following function in the test code (this is non working code as it requires your own addin name) :

require 'win32ole'

class UpdateAddInFile

  def addin_installed?(ai)
    begin
      puts "Addins: #{ai}? =  #{@xl.AddIns(ai).Installed}"
      @xl.AddIns(ai).Installed=0
      @xl.AddIns(ai).Installed=1
    rescue
      puts "<><>Testing for adding #{ai} caused an exception."
    end
  end

  def initialize(thisFile)
    @xl = WIN32OLE.new('Excel.Application')
    @xl.Visible = true
    addin_installed?("Your Add-In")
    #Satisfying wait as Excel addins get installed
    dummy = @xl.workbooks.Add # Add a new work book
    dummy.Cells(1,1).value = "add in functions will now work"
  end

end

UpdateAddInFile.new('c:\\test.xls')

puts "Waiting for readline"
readline

2009-05-28

Ruby log file management

I have been looking for a ruby log file management.  I looked at log4r but not sure it does what I want.  I am assuming a program that is run regularly to carry out a job. I would like the following:

1) for log files to be created for each run.  These to be stored in a log file directory

2) For the log files to be managed eg stored in log\2009\2009-04 and then a log file per day and a method of multiple log files per day.

3) The log files to have a format so that they are quite happy to crash in the middle, computer turned off and still be well formed and to have written everything that has been done out safely.  IE they can’t use regular XML format as can’t rely on closing brackets

4) Ideally have a graphical hierarchical tool to show you what happened.  Eg how long does something take over time, how often has it gone wrong.  A task would log start and end events. How many have happened per month etc  Looking at graphical environements this seems more suited to a rubyfx than shoes as rubyfx has support for a tree list.  Ideally the top levels of the tree would be the file directory structure.

5) The structure to cope with hierarchical logging eg

Start A
  Start B
  End B
  Start B
End A

Shows two B inside an A, on of the B’s was unsuccessful

6) Automatic log control eg ability to have only n Months of logs, to keep only say end of month logs after 1 year and even log thinnning where old logs are first thinned by getting rid of sub levels to take up less space.  Fixed space could also be used.

I think this is as far as I have got so far now back to some real work.

Later:  I have looked at YAML and think it is going to be helpful.

List of UK pottery suppliers

I have been trying to find a source of pottery supplies in the UK and wanted to list the main suppliers and some information about price.  I want to get some colour for the children to use, some clay, some slip for making bone china mugs in a mould and perhaps some plates.

I used ctm and they worked well.  Just need to get the kiln running now.

So in no particular order here they are:

Name Website Comments Price of colours Supplies clay,slip
http://www.ctmpotterssupplies.co.uk/ Complete supplier – good for larger quantities, based in Exeter. Delivery £10 per 25kg
Bit basic but functional web site
Scarva Erthenware glaze £5-£13 per kg powder, £6-£10 per 230ml/325g pot mixed.
Underglaze colour £2 to £4 per 100g pot. Pencils £3.20 each
porcelain 14.70 a gallon 8.64 for 12.5kg white earthenware
http://www.potterycrafts.co.uk/ Good website, Staffordshire
Duncan Covercoat
  Bone china and porcelain 5lt £21 £10 for 10KG for white earthenware
http://www.claymansupplies.co.uk/ Chichester    
http://www.dornhillpotterysupplies.co.uk/ Gloucestershire    
http://www.hobbyceramicraft.co.uk/ Focused on Ceramic cafe.    

2009-05-23

Playing with Ruby on rails on Windows

I have been playing with Rubymine which is a lovely development environment for Ruby.  I have a new web site development project so decided to learn Ruby on rails.

I have been reading Simply Rails 2 by Patrick Lenz and have now decided to actually try it out.  However the installation on Windows didn’t seem as straightforward as I thought it was going to be.  firstly the Instant rails seemed the wrong way to go as I already had ruby. So I did it by hand.

So I did gem install rails which worked fine.  Then downloaded rubymine and a 30 day free evaluation.  This then created my project for me.  So far so good.  I downloaded SQLite3 and put the .exe,.dll and .def in the Windows/ system32 directory, or rather I thought I did.   When I looked later Vista had prevented them.  So then I put them in c:\ruby\bin.

Had a bit of a problem with the SQL lite and I haven't been alone in this.  I created a data base with the SQL addin manager for Firefox.  Apart from using a .sqlite rather .sqlite3 that seemed ok. 

I had problems with installing the gem sqlite3-ruby and then I found this great post http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/

and it worked with gem install gem install sqlite3-ruby --version=1.2.3  and that seemed to work.

However ruby script/server still wouldn’t start up rails.  Time for supper.  The problem was I had corrupted the database.yaml file by adding a single character.  Once that was sorted it worked fine.

2009-04-30

Excel 2007 slow to open

Just a quick note I have both Excel 2003 and Excel 2007 and Excel 2007 was very slow to open.  A search of the web came up with the invaluable and crazy suggestion to create a blank .XLAM and add it.  Hey presto Excel 2007 responds as quickly as 2003.  Weird.

Starting a TortoiseSVN project

SVN is a great version control system and TortoiseSVN a great tool to access it.  I currently run the SVN server on a Windows desktop running as a serivce and each night back taking a rolling backup of it.

However I find one thing slightly confusing and that is how to move an existing project into SVN.  Typically you start something off and then decide it is worth a little more effort so add it to version control.  However the Tortoise SVN import tool is annoying in that when you import a folder it does not become the working copy.  So the help manual recommends you use Section 4.2.2, “Import in Place”.  This is then copied from the manual with some extra graphics:

  1. Use the repository browser to create a new project folder directly in the repository. (right click in File Explorer to get pp up menu then choose TortoiseSVN->Repo-Browserimage

  2. Checkout the new folder over the top of the folder you want to import. You will get a warning that the local folder is not empty. Now you have a versioned top level folder with unversioned content. (Make sure the URL of the repository contains the sub directory you have just added):image

  3. Use TortoiseSVN → Add... on this versioned folder to add some or all of the content. You can add and remove files, set svn:ignore properties on folders and make any other changes you need to.

  4. Commit the top level folder, and you have a new versioned tree, and a local working copy, created from your existing folder.

This is actually very easy but I remember getting confused before.