Copyrights @ Journal 2014 - Designed By Templateism - SEO Plugin by MyBloggerLab

Thursday, August 24, 2006

Python on the .NET Framework

One of the least talked language on web is IronPython when it became available in Microsoft CLR.
Dynamic runtime languages were previously thought to run very poorly on the .NET Framework, but IronPython dismisses that idea. Microsoft is backing IronPython because it exemplifies just how well the .NET Framework can handle dynamic runtime languages. Supposedly, IronPython runs as fast as the C-based implementation of Python-2.4, if not faster. The company claims that IronPython can run 1.8x faster than Python-2.4 right now. Besides being speedy, it also allows developers to access all of the standard C Python libraries, not to mention and create their own subclasses deriving from the .NET framework.
IronPython is the codename for a new implementation of the Python programming language on the .NET Framework. It is fast - up to 1.8x faster than Python-2.4 on the standard pystone benchmark. It supports an interactive interpreter with fully dynamic compilation as well as static compilation to produce pre-compiled executables. It's well integrated with the rest of the Framework and makes all of the .NET libraries easily available to Python programmers. In this episode Jim Hugunin introduces IronPython with demos showing interactive exploration and GUI building from a command prompt as well as simple embedding as a scripting language in an existing Windows Presentation Foundation application. Via Overview at Microsft's Download website
Still, when I read this old news, I was surprised to see Microsoft's backing on Python where they will not be investing that much of money to see a dynamic language work. Anyways, as part of research found a very interesting comparision of Ruby, Java and C++ with Python by dmh2000. This comparision is just awesome.
conclusion
Java is more productive than C/C++. Use C/C++ only when speed or bare metal access is called for. Python/Ruby is more productive than Java and more pleasant to code in. There is a big question on static vs. dynamic typing. I contend that static typing has to be better for the purposes of program correctness, but the required cruft reduces productivity. If actual practice in large systems shows that in fact runtime typing errors don't occur often and are worth the productivity tradeoff, then I will bow to dynamic typing. I can't come up with a definitive answer to Python vs. Ruby. They seem very equivalent. Would choose based on practicality in a given situation. My general feeling was that Python annoyed me in ways that Ruby didn't, but I think those annoyances would disappear if I was using Python all the time.

Wednesday, August 23, 2006

log_reuse_wait_desc column in sys.databases

Having these words in your SQL Server error in SQL Server 2005 seems a little unbearable.
The transaction log for database '%.*ls' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
SQL Server 2005 Database Properties Window There are various reason to get the error. Transaction log expansion may occur because of the following reasons or scenarios: The linked MS Technet article does not help but confuses you.
• Uncommitted Transactions
• Extremely Large Transactions
• Operations: DBCC DBREINDEX and CREATE INDEX
• While Restoring from Transaction Log Backups
• Client Applications Do Not Process All Results
• Queries Time Out Before a Transaction Log Completes the Expansion and You Receive False 'Log Full' Error Messages
• Unreplicated Transactions
Check this FORUM POST out, excellent suggestion, set transaction recovery mode to "Simple". Try that once through database properties panel, it does not work for first time. few times it definitley works. Try changing the "Auto Shrink" and "Auto Close" properties to "True"

Tuesday, August 22, 2006

Create a Thumbnail Image of web page

How do I create cached image of a webpage. I just wanted to create a thumbnail of a webpage based on URL. There is no way, you would find the right stuff to do so. I found Alan Dean's page on Generate an image of a web page. He has explained the technique very well. Described his search for such code. He wrote on his own. There are a very few people got it working. So here is the code, took me a lot of time to get it working. Read through the sample I added here very carefully before you copy the code as is. I tried my best to write all comments to make it easy readable.
Tried it in all possible ways to make it successful the way I wanted. This code works awesome but I wanted to use System.drawing very well to make it work. There is no way I could find to do this without using Win32 Api. Apart from that, I need to add the axWebBrowser control and it needs to be visible on form in order to find the image of the web page. Then how do I do it on the fly on my website. There must be a way to create a thumbnail from webpage with out adding ActiveX controls....
Good Luck!! Let me know if this works for you.
'*************************************************************************
'This is main form Class where you will add the basic functions.
'*************************************************************************


Imports
SHDocVw ' Import the shdocvw.dll from Widnows\System32 folder.
Imports mshtml  ' Import the mshtml.dll from Widnows\System32 folder.
Imports System.Runtime.InteropServices ' Need this as we added above two as Interop

Imports
System.Windows.Forms

Public
Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Add the axWebBrowser control from SHDocVw library to your form name it as axWebBrowser
        'Add the Event Handler as DocumentComplete, because we need to capture screen image when document is completely loaded.
        AddHandler axWebBrowser.DocumentComplete, AddressOf Me.OnDocumentComplete
        End Sub
      Private Sub OnDocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent)
 
        Dim document As IHTMLDocument2 = CType(Me.axWebBrowser.Document, IHTMLDocument2)
        If Not (document Is Nothing) Then
            Dim element As IHTMLElement = CType(document.body, IHTMLElement)
            If Not (element Is Nothing) Then
                Dim render As IHTMLElementRender = CType(element, IHTMLElementRender)
                If Not (render Is Nothing) Then
                    ' Using
                    Dim graphics As Graphics = Me.pictureBox.CreateGraphics
                    Try
                        Dim hdcDestination As IntPtr = graphics.GetHdc
                        render.DrawToDC(hdcDestination)
                        Dim hdcMemory As IntPtr = gdi32.CreateCompatibleDC(hdcDestination)
                        Dim bitmap As IntPtr = gdi32.CreateCompatibleBitmap(hdcDestination, Me.axWebBrowser.ClientRectangle.Width, Me.axWebBrowser.ClientRectangle.Height)
                        If Not (bitmap = IntPtr.Zero) Then
                            Dim hOld As IntPtr = CType(gdi32.SelectObject(hdcMemory, bitmap), IntPtr)
                            gdi32.BitBlt(hdcMemory, 0, 0, Me.axWebBrowser.ClientRectangle.Width, Me.axWebBrowser.ClientRectangle.Height, hdcDestination, 0, 0, CType(gdi32.TernaryRasterOperations.SRCCOPY, Integer))
                            gdi32.SelectObject(hdcMemory, hOld)
                            gdi32.DeleteDC(hdcMemory)
                            graphics.ReleaseHdc(hdcDestination)

                            'Add a PictureBox control to your form, named pictureBox. This way you can
                            'see the image immediately after it is generated. You can save to FS using Bitmap.Save method.
                            Me.pictureBox.Image = Image.FromHbitmap(bitmap)

                        End If

                    Finally

                        'You must dispose Graphics Object for better use.
                        CType(graphics, IDisposable).Dispose()
                    End Try
                End If
            End If
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Add a button to you form named Button1.
        ' This way we can control when we want to start Browsing.
        ' Select the URI to be browsed here.
        Me.axWebBrowser.Navigate(New Uri("http://www.google.com"))
 
    End Sub
End Class
'*************************************************************************
'This class for dummy for calling GDI Functions from Win32 Api.
'So that you can encapsulate whole GDI work outside.
'*************************************************************************
Public Class gdi32

    ' I copied all the signatures in this class from http://www.pinvoke.net 
 
    Public Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Boolean
    Public Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal hgdiobj As IntPtr) As IntPtr
    Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As IntPtr) As IntPtr
    Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr
    Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
    Enum TernaryRasterOperations As Integer
 
        SRCCOPY = 13369376      'dest = source
        SRCPAINT = 15597702     'dest = source OR dest
        SRCAND = 8913094        'dest = source AND dest
        SRCINVERT = 6684742     'dest = source XOR dest
        SRCERASE = 4457256      'dest = source AND (NOT dest )
        NOTSRCCOPY = 3342344    'dest = (NOT source)
        NOTSRCERASE = 1114278   'dest = (NOT src) AND (NOT dest)
        MERGECOPY = 12583114    'dest = (source AND pattern)
        MERGEPAINT = 12255782   'dest = (NOT source) OR dest
        PATCOPY = 15728673      'dest = pattern
        PATPAINT = 16452105     'dest = DPSnoo
        PATINVERT = 5898313     'dest = pattern XOR dest
        DSTINVERT = 5570569     'dest = (NOT dest)
        BLACKNESS = 66          'dest = BLACK
        WHITENESS = 16711778    'dest = WHITE
    End Enum
End Class

'Check out Alan Dean's explaination, because I don;t get it. He is smarter than me, so I just believed that it works.
<Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"), System.Runtime.InteropServices.InterfaceTypeAttribute(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown), System.Runtime.InteropServices.ComVisible(True), System.Runtime.InteropServices.ComImport()> _
Interface IHTMLElementRender
    Sub DrawToDC(<System.Runtime.InteropServices.In()> ByVal hDC As IntPtr)
    Sub SetDocumentPrinter(<System.Runtime.InteropServices.In(), System.Runtime.InteropServices.MarshalAs(UnmanagedType.BStr)> ByVal bstrPrinterName As String, <System.Runtime.InteropServices.In()> ByVal hDC As IntPtr)
End Interface
 
 
 

Saturday, August 05, 2006

Shri Satyanarayan Pooja Katha and Photograph

Every year, in the month of Shravan as per India calendar, me and my wife decided to arrange Satyanarayan Pooja. Last year was the most pleasure, this year we are doing with same spirit and devotion on August 12, 2006.
I had been searching for Katha in Marathi, expectation was atleast told and made as I heard since my childhood.

Everywhere I could see Maharashtrians posting requests to send one or where do you get it. It is really difficult in US to have that fantacy unless there is somebody who is scanning and emailing that. This year decided to spread the pleasure by providing a copy to all. Check this page for Satyanarayan Pooja. Completely in Marathi.
There is also a photograph for your use.
Let me know what you think, post a comment here if you need anything else. Allow me sometime before I can make it available, but your comments are more valuable.