Shlrm.org Blag

Archive for July, 2008

HOWTO: rewrite an email address on send in outlook

by David Kowis on Jul.30, 2008, under Coding!

I’m not terribly big on microsoft products, but I have to use them at work. I was emailing someone whos reply-to address was incorrect, so I needed to rewrite it on send. It was terribly annoying to have to remember to replace it everytime I hit “reply.”

Here’s some code that does it.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    'Trying to rewrite an email address on send
    Dim item2 As MailItem
    If TypeOf Item Is MailItem Then
        Set item2 = Item
        Dim str As String
        Dim r As Recipient
        For Each r In item2.Recipients
        If r.Address = "old.address@someplace.net" Then
            r.Delete
            Dim newRecipient As Recipient
            Set newRecipient = item2.Recipients.Add("new.address@something.more.useful.com")
            newRecipient.Type = olTo
            newRecipient.Resolve
        End If
        Next
    End If
End Sub
Leave a Comment : more...

My First Ruby Proggie

by David Kowis on Jul.29, 2008, under Ruby

I wrote this to provide me a simple wget type program.

require 'net/http'
require 'uri'

proxy_addr = 'localhost'
proxy_port = 8118

url = URI.parse('http://shlrm.org/baconflowchartvj8.jpg')

Net::HTTP::Proxy(proxy_addr, proxy_port).start(url.host)   do |request|
  puts "Connected to teh proxy"
  # connected to mah proxy
  to_save = url.path.split(/\//)[-1]
  File.open("c:\\" + to_save, 'wb') do |f|
    puts "opened file"
    request.request_get(url.path) do |response|
      content_length = Integer(response['content-length'])
      total_count = 0
      response.read_body do |str|
        if str.length > 0 then
          total_count += str.length
          print "Complete: #{total_count} of #{content_length}:  "
          puts "%4f" % (1.0*total_count/content_length*100)
        end
        f.write str
      end
    end
    puts "Written file"
  end
  puts "done connecting"
end
puts "all done"

So that’s it.

Leave a Comment : more...

Ruby: Unit Tests and Debugging

by David Kowis on Jul.29, 2008, under Ruby

Well, this is all that’s left for learning the core of the language. How to use ruby’s built in Unit Testing framework and how to fiddle with the debugger. This post will be very short, because there’s not a whole lot to unit testing. Going over the debugger is kinda silly too, since it’s mostly just a command reference. Also, I found an interesting gotcha in the examples listed that I’ll share with you. There’s a benchmarking and profiling module worth saying a few words about. (continue reading…)

Leave a Comment : more...

Ruby: Fibrous Content Ahead

by David Kowis on Jul.28, 2008, under Ruby

Fibers, threads, and processes! Oh, my! Fibers are probably the most interesting part of this, and ruby’s slightly broken threading model. Processes are interesting from the aspect of being able to communicate with external programs. (continue reading…)

Leave a Comment :, more...

Ruby Input and Output

by David Kowis on Jul.27, 2008, under Ruby

The next chapter is one on basic input and output. This one is also kinda short. Or maybe it feels short, as there’s not a whole lot of new stuff to digest… EDIT: heh, well I started out saying it was short, but turns out I had more to say about it than I thought. Maybe I’m getting better at this blagging stuff. (continue reading…)

Leave a Comment : more...

Archives

Hacker’s Diet

The Hacker's Diet Online