Wednesday, January 6, 2010

Print the XML contents from an ADBBean

I wanted to print the xml contents of a custom object created by Axis2's wsdl2java. The object inherits from ADBBean, so you could use the following function to pull a reasonable approximation of the soap message out --


public static String debugAxisObject(org.apache.axis2.databinding.ADBBean b){
try {
org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder omwriter=
new org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder();

b.serialize(
new javax.xml.namespace.QName("http://localhost/",
b.getClass().getSimpleName(), "ns1"),
org.apache.axiom.om.OMAbstractFactory.getOMFactory(),
omwriter);

return omwriter.getOMElement().toStringWithConsume();
} catch (Exception e) {
return "error writing adbbean "+b.getClass().toString();
}
}


-- The QName is completely made up, so it will not match the 'real' soap message, but it will at least give you a decent idea of how your message is laid out. also, I have know idea how this behave if you use an actual MTOM attachment.

Thursday, August 20, 2009

Supercharge Google Reader with Send To Links [Feeds]

So google reader now has 'Send To' feature described below (from lifehacker). my friend sami shared it with me in google reader... and its pretty sweet!

Out of the box, Send To features post to Blogger and to del.icio.us which is cool.

so consider this a test post.



Supercharge Google Reader with Send To Links [Feeds]: "

Google Reader recently added custom 'Send To' controls to its feature list, and we've been looking for the most useful links to feed it. Here are 11 excellent send-to tools you can add to Reader, with more on the way.

'More on the way' because, despite trying to keep our eyes and feed readers in as many places as possible, we're guessing there are a lot of other great URL-friendly webapps that can be hooked into Reader, as these crowd-sourced examples have already proven.

To install one of these Send To items in your own Reader, head to your Settings link from Reader's main page, click the 'Send to' tab, then hit the 'Create a custom link' button at the bottom. You'll be prompted for a Name, URL, and Icon URL, which you can simply copy and paste from these entries.

Know of a web service, a bookmarklet, or any other webapp that can accept text or items through its URL? You can easily set up a Send To item to feed items from Reader to that webapp. Reader lets you automatically include URL-friendly variables from feed items:

LifehackerThe source of the item
Supercharge Google Reader with Send To Links [Feeds]The title of the item
http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-linksThe URL of the item
A shortened URL that redirects to the item

So if you knew, for example, that MyAwesomeLolcatApp can re-write the text on any web page with deliberate-but-cute misspellings, you could create a Send To item that has http://myawesomelolcatapp.com/url=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links, and it'd work just gangbusters.

If you make your own Send To discoveries, by all means, drop them in the comments, or send them to tips at lifehacker.com with 'Google Reader' and 'Send To' somewhere in the text or subject. Now, onto the neat hacks to make all your RSS items easier to print, save, share, calendar, and even translate:

  • Name: Printer Friendly
  • URL: http://www.printfriendly.com/print?url=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links
  • Icon URL: http://cdn.printfriendly.com/pf-icon.gif
  • What it does: Formats web pages for printing through PrintFriendly, with an eye for less ink usage. (via Zsolt)

  • Name: Save as PDF
  • URL: http://savepageaspdf.pdfonline.com/pdfonline/pdfonline.asp?cURL=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links
  • Icon URL: http://www.adobe.com/lib/com.adobe/template/icon/pdf.gif
  • What it does: Sends the article to PDF Online, which preps it as a PDF for saving or printing. (via Digital Inspiration)

  • Name: Evernote
  • URL: http://s.evernote.com/grclip?url=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links&title=Supercharge Google Reader with Send To Links [Feeds]
  • Icon URL: http://www.evernote.com/favicon.ico
  • What it does: Adds the URL and page text as an Evernote item, similar to Evernote's 'Web clipping' Firefox add-on or bookmarklet. (via Evernote Blog)

  • Name: Read It Later
  • URL: https://readitlaterlist.com/save?url=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links&title=Supercharge Google Reader with Send To Links [Feeds]
  • Icon URL: http://readitlaterlist.com/favicon.ico
  • What it does: Moves feed items into your Read It Later list, viewable through the web, Firefox extensions, and iPhone apps. (via Read It Later and zmnatz)

  • Name: Email
  • URL: mailto:?subject=Supercharge Google Reader with Send To Links [Feeds]&body=%0A<http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links>
  • What it does: Activates whatever default mail client you have installed on your system, and auto-fills the subject with the title and the body with a link. (via Google Operating System and AmaraMetellus)

  • Name: Full Gmail
  • URL: http://mail.google.com/mail/?fs=1&tf=1&view=cm&su=Supercharge Google Reader with Send To Links [Feeds]&body=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links%0A%0AShort link%3A
  • Icon URL: http://mail.google.com/favicon.ico
  • What it does: Emails a link using Gmail—but the full composition window, not Reader's stubbed email tool. Using Google Apps with your own domain name? As Dustin points out, you can replace mail.google.com with the address for your hosted Google apps, and the rest of the code should work. (via Google Operating System)

  • Name: Google Calendar
  • URL: http://www.google.com/calendar/event?action=TEMPLATE&text=Supercharge Google Reader with Send To Links [Feeds]&details=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links
  • Icon URL: http://calendar.google.com/googlecalendar/images/favicon.ico
  • What it does: Primarily useful for feeds that deliver dates and times without a lot of added text. For those items, Google Calendar can pick up the information and create new events from them. (via Google Operating System)

  • Name: Add This
  • URL: http://addthis.com/bookmark.php?v=250&url=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links&title=Supercharge Google Reader with Send To Links [Feeds]
  • Icon URL: http://addthis.com/favicon.ico
  • What it does: Pushes an item link to AddThis' site, where you can more easily share it across a bevy of social networks. (via Digital Inspiration)

  • Name: HootSuite
  • URL: http://hootsuite.com/twitter/bookmark-tool-v2?address=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links&title=Supercharge Google Reader with Send To Links [Feeds]
  • Icon URL: http://static.hootsuite.com/5-49/images/favicon.ico
  • What it does: Pushes items over to the advanced Twitter client HootSuite for editing. (via Dustin)

  • Name: Identica
  • URL: http://identi.ca/?action=newnotice&status_textarea=%E2%80%9CSupercharge Google Reader with Send To Links [Feeds]%E2%80%9d%3a%20
  • Icon URL: http://identi.ca/favicon.ico
  • What it does: Shares links through open source Twitter alternative Identi.ca (via Remko Tronçon)

  • Name: Google Translate
  • URL: http://translate.google.com/translate?u=http://feeds.gawker.com/~r/lifehacker/full/~3/ISY-As4gu-E/supercharge-google-reader-with-send-to-links
  • Icon URL: http://translate.google.com/favicon.ico
  • What it does: Sends blog articles and feed items to Google Translate for, well, translation. Reader can already translate entire feeds to another language automatically, but this allows for passing along the occasional item. (via Matt Cutts)








"

Sunday, March 9, 2008

Getting voicemail delivered to your email account

I used to rarely check my voicemail. I'd wait until a convenient time on the weekend and then delete 4 or 5 voicemails I'd accumulated during the week, mostly from my girlfriend or my mom. Usually if I see a missed call and a voicemail, I'll just call that missed caller right back because its easier than checking voicemail and calling them anyways. If someone wanted to just leave me a message I didn't have to respond to, I'd expect it to come as a text message. And of course if I saw a missed call & voicemail that was work related, I'd listen to it, but I don't get those particularly often.

But I am very religous with checking emails... so I thought it would be great to get my voicemails as email messages that I could listen to in my browser (ff of course...).

So after an afternoon of wrestling with the pieces, heres how you do that:


  1. Sign up for grandcentral @ www.grandcentral.com. It was recently bought out by google, but it does not integrate with your existing google account. Try to get a number in your area code or one close by. I did this a couple of months before setting up my voicemail system, and was able to get a number.

  2. Use *71 to set up 'No Answer/Busy Transfer' on your current cellphone to forward to your grandcentral number. My cell is verizon, so this works very easily for me, and I'm sure other carriers provide something similar. This service is free (it is on my plan and as far as I know I never opted in) and it will try to ring your cellphone 3-6 times, and if you don't pick up will forward your call (regular call forwarding will forward your call without trying to ring you). After you don't pick up, the call is transfered to grandcentral were it will use your grandcentral rules to decide how to route the call.

  3. In my case, I turn 'quickrules' off so that grandcentral does not try to route my calls. In that case, it will go straight to grandcentral voicemail.

  4. Set your grandcentral notifications to email you at your primary email address, and you can optionally choose to be alerted by text message. I like to turn on the latter because it tells you detailed info about your voicemail (who, when, how long the message was).

  5. Profit?

  6. You should probably customize your grandcentral voicemail greeting too so people know to leave you a message. Or you can totally mess with them because you can have different greetings that get played to different people, but all strangers will still get your professional greeting.



I like this system because I check my voicemails much more frequently now (its fun). The messages go to your email with a play button that links to grandcentral (with a url you can access w/o being logged into so you can forward to your heart's content).

GrandCentral has a lot of other cool features too that you can exploit now that you have an easy way to make use of it. Enjoy!

- Dave

Friday, February 1, 2008

Carl from ATHF loves the GIANTS

This video accurately sums up my opinion on the Giants.

Thursday, January 31, 2008

VB6 -> VB.NET Upgrade Wizard, Fixed Width Structures

I used the upgrade wizard included in Visual Studio.NET and found it overall pretty good. My biggest issue with it was the way it handled structures with fixed width fields. In VB you'd define a structure like this:

Type example
field1 As String * 10
field2 As String * 10
End Type


In VB.NET it would get converted as:

Structure example
<VBFixedString(10), _
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=10)> _
Public field1 As String
<VBFixedString(10), _
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=10)> _
Public field2 As String
End Structure


So it looks like the wizard did the trick by adding all those attributes. I thought that this was adequate until we realized during testing that we weren't getting properly padded fields out of the structure like we had been in VB6. So if we set field1 to "hello" in VB6, then retrieved the value, we'd get "hello     " (thats 5 trailing spaces). In VB.NET, the same value in field1 would be retrieved as "hello" with no spaces. I'd bet that that fancy pants attributes actually does its job when used as a library from another COM app. But in just a normal capacity it did not behave expected.

No problem, we'll just have to try and fix it! So my first thought is that maybe there is some sort of .NET library to redirect all member access to a function. Sort of like __getattr__ in python. We could conceivably just change the Structure to a Class, and inherit it from a class that implements __getattr__ and we wouldn't have to change any code.

No dice, as far as I can tell there is nothing in .NET to bounce member access to a function. It would have been nice to have some sort of class that would provide the bounce for us, then we just override the member resolution function or something.

So what I did instead was turn those Structures to Classes anyways, and had them all inherit from a class implementing this property and method:

Default Public ReadOnly Property GetField(ByVal retrievethisfield As String) As String
Get
Return _GetField(retrievethisfield)
End Get
End Property

Public Function _GetField(ByVal fieldname As String) As String
Dim field As Reflection.FieldInfo = Me.GetType().GetField(fieldname)
Dim val As Object = field.GetValue(Me)
Dim fixedlength As Integer
For Each attr As Attribute In field.GetCustomAttributes(True)
If TypeOf attr Is VBFixedStringAttribute Then
fixedlength = CType(attr, VBFixedStringAttribute).Length
Return Left(CStr(val).PadRight(fixedlength, " "), fixedlength)
End If
Next
Return val
End Function


So the dirty part is that to set you use normal member lookup via obj.field1 etc, but to do a get you do obj("field1") and it will do the padding for you (Note the use of the default property...). You can get rid of some of those wizard attributes, as long as you use VBFixed. Ugly huh! What would be nice is to be able to then tag the member variables in the structure/class as writeonly so I could find (as errors in the task list) all the gets and replace them with my lookup. This is possible for properties, but not for member variables because they must be second class citizens.

Sometimes I feel like VB.NET has some python like things I like (specifically invoking unknown methods on an 'object' object). Other times I realize its a totally different animal and I can find comparable things between any language if I wanted to.

Tuesday, January 29, 2008

Superbowl Box Pool Odds on Point Change

my dad sent me this link today:

http://www.j-e-f-f.com/sb-o-m.htm


it details the percentage payout per quarter that each superbowl pool box has earned in all superbowls. since we play a pool on point change, this link doesn't actually tell us much.

so i went to superbowl.com for stats and made a quick program to come up with this chart that gives us the percentage of hits on each box. here it is:


0 1 2 3 4 5 6 7 8 9
0 10.69 2.24 1.21 8.79 5 1.72 7.59 8.45 1.21 2.76
1
0.17 0.34 0.86 0.86 0.34 1.03 1.38 0.17 0.52
2

0 1.21 0.34 0 1.03 1.38 0.17 0.52
3


3.62 2.76 0.17 4.83 5.52 0.17 1.55
4



0.69 0.52 1.55 3.1 0 1.9
5




0 0.17 0.52 0 0.17
6





1.21 3.45 0.34 0.86
7






2.93 0.86 1.9
8







0.17 0.69
9








0.34


When taking AFC & NFC into consideration, this is the chart. NFC is the columns going across, AFC is the rows going down.



0 1 2 3 4 5 6 7 8 9
0 10.69 1.55 0.69 4.66 2.93 1.21 3.97 4.48 1.03 1.55
1 0.69 0.17 0.34 0.69 0.69 0.17 0.69 0.86 0.17 0.34
2 0.52 0 0 0.52 0.34 0 0.52 0.69 0 0.34
3 4.14 0.17 0.69 3.62 1.03 0 2.59 2.76 0.17 1.38
4 2.07 0.17 0 1.72 0.69 0 1.03 2.07 0 1.03
5 0.52 0.17 0 0.17 0.52 0 0.17 0.34 0 0.17
6 3.62 0.34 0.52 2.24 0.52 0 1.21 1.72 0.34 0.34
7 3.97 0.52 0.69 2.76 1.03 0.17 1.72 2.93 0.34 0.86
8 0.17 0 0.17 0 0 0 0 0.52 0.17 0.52
9 1.21 0.17 0.17 0.17 0.86 0 0.52 1.03 0.17 0.34


and likewise, here are the expected final scores when afc/nfc is not taken into account:


0 1 2 3 4 5 6 7 8 9
0 0 2.44 2.44 2.44 0 4.88 4.88 7.32 0 4.88
1
0 0 0 4.88 4.88 2.44 2.44 2.44 2.44
2

0 0 2.44 0 0 2.44 0 2.44
3


0 4.88 0 4.88 2.44 0 0
4



0 0 0 9.76 0 2.44
5




0 0 0 0 0
6





2.44 2.44 2.44 2.44
7






4.88 0 2.44
8







0 2.44
9








0

and when afc & nfc are taken into account (afc is rows again)


0 1 2 3 4 5 6 7 8 9
0 0 0 2.44 0 0 4.88 2.44 4.88 0 2.44
1 2.44 0 0 0 2.44 2.44 2.44 2.44 2.44 2.44
2 0 0 0 0 2.44 0 0 0 0 2.44
3 2.44 0 0 0 2.44 0 0 2.44 0 0
4 0 2.44 0 2.44 0 0 0 9.76 0 2.44
5 0 2.44 0 0 0 0 0 0 0 0
6 2.44 0 0 4.88 0 0 2.44 2.44 2.44 2.44
7 2.44 0 2.44 0 0 0 0 4.88 0 0
8 0 0 0 0 0 0 0 0 0 2.44
9 2.44 0 0 0 0 0 0 2.44 0 0

First Post!

yes, i've created a blog using the power of the internet.