August 6, 2008

OpenID, myOpenID Rocks!

Filed under: announcements,open id Himanshu @ 6:37 am

I have been using openID from last 5-6 months as and when I got chance to use it. It’s getting popular more and more now a days. I see more and more sites supporting it. When first time I learned about it, first thing that came to my mind was to support openID login for my site. And second thing that came to my mind was, MS passport got competition ;).  I haven’t seen passport authentication much popular apart from Microsoft sites.

As I didn’t had anything to secure on my site. So far I haven’t actively started working on to support openID login. It also make sense to have user ids for features like customization, but my site is not supporting that either. I would like to support openID authentication as soon as I finish coding with site-spaces that supports customization and security. Mainly when I need user authentication.

On root (http://root.objectpattern.com) page, that is like dashboard, I’m planning to have UI that supports customization/personalization. And once I finish coding Media Gallery, I will need authorization their for different spaces/albums of it, yeah some media will be private to my family and friends. I have done some initial tests using DotNetOpenID (http://code.google.com/p/dotnetopenid/). But that library didn’t worked well on GoDaddy hosting, because of trust level that GoDaddy Deluxe hosting gets. Haven’t done much research on that to fix it some how.

Also did some initial tests with myOpenId (http://myopenid.com) to setup such that I/someone can have openId as http://openid.objectpattern.com/. Actually, it wasn’t that difficult to do. I have my id ready, as http://openid.objectpattern.com/himanshu I liked myOpenID, it allows to have certificate sign on.

Anyway, I’m posting this to let you know a) openID Rocks 🙂 b) I’m planning to be openID consumer, c) setup with help of myOpenId is ready to have openID as openid.objectpattern.com/*.

By the way, did I told you what is openID? Oh, never mind just take a look at it’s official site (http://www.openid.net) if you don’t know what is openID and after that if you have any further queries about it, send me email or comment your query against this post, and I will try answering them.

August 5, 2008

Paging of SQL Server records

Filed under: .net,sql server Himanshu @ 6:29 am

In one of my ASP.NET, SQL Server project, we were expected to provide paging in the ASP.NET GridView. Microsoft’s very common sample will do this using Dataset filled with all records. If someone is doing GridView paging, s/he is doing it not waste server’s or client’s precious resources, Isn’t it?

To me, it make more sense to do paging of records being fetched in server memory along with view paging. What if table in question has more then 100,000 (1 lack) records?

Digging a bit further, I found a resource which explains how to do paging of records being sent from stored procedure. But it was expecting to have auto identity as primary key in the table. And we were so fortunate that we couldn’t have db design such that we can afford to have auto identity primary key, and so that solution to the paging problem. On doing some more finding, we all agreed to a solution that is described below. It’s not fully optimized, as it do not have any optimization for SQL Server to prepare result sets. But worked for our need in specific project as even in 100,000 records it was working very fast.

In our solution, stored procedure that will fetch records from table and return to caller will needs to have two addition parameters, @RowIndexFrom and @RowIndexTo

Getting customers by page will look like following,

CREATE PROCEDURE [dbo].[GetCustomersPage]
(
    @RowIndexFrom int,
    @RowIndexTo int
)
AS
BEGIN
    SET NOCOUNT ON;

    WITH IndexedCustomers AS
    (
        SELECT
            ROW_NUMBER() OVER (ORDER BY Id) AS rowIndex,
            Customers.*
        FROM
            Customers
    )
    SELECT * FROM IndexedCustomers WHERE rowIndex BETWEEN @RowIndexFrom AND @RowIndexTo

    SELECT COUNT(*)
    FROM
        Customers
END
GO

 

The stored procedure returns two result set, first will be records for given page (defined by different between @RowIndexFrom and @RowIndexTo parameters). And the second result set will give total number of records for give query. Second result set will help preparing pages list. So, if first page needs to be retrieved of page size 10, parameter values should be 1 and 10 respectively.

July 23, 2008

Creating a windows shortcut using AutoIt

Filed under: autoIt,robo coding Himanshu @ 6:07 am

AutoIt library do have function to create windows shortcut, FileCreateShortcut. AutoIt script to create new shortcut of specified target in specified file/folder. Once compiled and created executable, use it in following way.

Usage:

shortCut.exe  []

First parameter is required and should be path of file/folder for which to create shortcut

Second parameter is optional and if specified, should be full existing path including shortcut file name. If not specified shortcut will be created in the folder from where executable is run.

If ($CmdLine[0] < 1) Then
    MsgBox(16, "Error", "Insufficent parameters. In first parameter, specify for which file, shortcut should be created.") 
    Return 
EndIf 
$shortcutOf = $CmdLine[1] 
If (Not FileExists($shortcutOf)) Then 
    MsgBox(16, "Error", "File/directory """ & $shortcutOf & """ do not exists") 
    Return 
EndIf 
$shortcutPath = @WorkingDir & "\" & "Shortcut of " & 
$shortcutOf & ".lnk" 
If ($CmdLine[0] = 2) Then 
    $shortcutPath = $CmdLine[2] 
    If (StringLower( StringRight($shortcutPath , 4)) <> ".lnk" ) Then 
        $shortcutPath = $shortcutPath & ".lnk" 
    EndIf 
EndIf 
$objShell = ObjCreate("Wscript.Shell") 
$shortcut = $objShell.CreateShortcut($shortcutPath) 
$shortcut.TargetPath = $shortcutOf 
$shortcut.WindowStyle = 1 
$shortcut.Save()

If you want to download script file click here

Let me know if you need any further help in it.

June 12, 2008

Cannot connect to server

Filed under: networking Himanshu @ 7:21 pm

Many times, we face this statement. And almost all time we forget simple tool like ping, telnet and tracert. When I get into the situation where we couldn’t connect client to server, the first thing that I do is can I ping server? If ping is failing at what level of network route it is failing- tracert? Can I open the port (using telnet) that client software is trying to connect to the server.

Many of the time this becomes question when we do have network (can ping, and hence can also tracert). But cannot open port. And usually it is because of firewall.

More to come…

March 27, 2008

Sending keystrokes (Key press) from .Net to active application

Filed under: .net,programming,robo coding Himanshu @ 5:32 pm

Many of the part of windows works on messages – windows messages. One code can send different kind of messages to another application using Windows API. Keyboard messages and mouse messages are one of them.

.NET is one more layer above OS, e.g. Windows. If someone needs to emulate keyboard strokes to another application from .NET there is a choice of using .NET class library. To emulate keyboard events from .NET it’s easier to use

  • System.Windows.Forms.SendKeys.Send(string) and
  • System.Windows.Forms.SendKeys.SendWait(string)

Recently, I used this to auto log into a application that I’m developing if it’s debug build. Just to get a change from AutoHotKey.

The problem of this is it sends keystrokes to only active application.

March 17, 2008

VS.NET, macro creating string const, and macro creating string resource entry

Filed under: .net,programming,robo coding,vs.net Himanshu @ 2:08 pm

Per me, macro is one of the most important feature for any text editor or software IDE. And hence, it is very import for VS.NET user to understand and then use macros available in VS.NET. VS.NET macros are very powerfully tool and they help in lot more different ways.

I have created two macros that are very common in their need. While programming, we need to create string const on regular bases. It becomes inconvenient to go to top of the class while writing a method body for same class and create constant. Macro in library attached with this post becomes handy at that time.

Same use case hold very much true for creating string resources while writing method body. And it becomes really very easy if string resource can be created while writing method body.

For those who thinks like me (or want to 🙂 ), I have attached two macros with this post. Macro works for VS.NET 2005, haven't tested in any other version. But should work fine in VS.NET 2003 or VS.NET 2008

March 11, 2008

Create shortcuts by scripting (AutoIt, AutoHotKey)

Filed under: autoIt,robo coding Himanshu @ 12:01 pm

In windows, one can create shortcuts; Windows shortcuts can point to may resources like URL, an executable file, document files or folder in file system, disk, and network shares. But not all are same in their behavior. For example: If I create shortcut of an executable and put that shortcut in one of the directory which is included in PATH (Environment variable), I can invoke executable by just typing in shortcut name in Start->Run (Windows + R Key). But I could not do same with http URL. I also wanted to parameterize some of them. For example if I type in “jira ata-586”, it should open jira item “ata-586”.

I use AutoIt for quite some time. There are many good things about AutoIt, easy to learn it’s language (almost like VB), can create executable from script, comes with SciTE Script Editor along with plug-in for language and libraries of AutoIt. Because of plug-in SciTE can give nice code complete feature. I have also been using AutoHotKey a bit. One of the nice features of AutoHotKey is you can program it to wait until specific keys are pressed to perform certain operations, recording keyboard keystrokes and mouse gestures. And also supports to create executable from script.

It’s good to create this kind of scripts that will minimize effort to locate specific place that once can access on regular basis. I have created windows shortcuts or script shortcuts for following specific tasks that I perform regularly

  • Open folder of my projects in windows explorer. (“cd ata” or “cd pub”)
  • JIRA home page
  • JIRA space of specific project
  • Specific JIRA issues
  • Confluence Dashboard
  • Specific confluence space.
  • http://dictionary.reference.com with specific word
  • Google with specific search result.
  • Cisco vpn connection
  • Mapping network share to a drive letter
  • Starting tools that I regularly use, like specific version of visual studio, reflector, vmplayer, nunit…
  • Logging in to application that I’m working/testing
  • Fill-in form that I’m working
  • ….

Big list, I also recommend all to do same for the tasks that you regularly perform, and make you life easier.

March 10, 2008

Automation, Software Engineering, Productivity

Filed under: programming,robo coding,vs.net Himanshu @ 12:22 pm

It’s good to use computer as far as it is possible to do. Around the world, many computer engineers work for others to generate code-base that instructs computers to act as it’s user would like it to. Computers gives more accessibility to the information, knowledge, gives more processing power, help to be more managed and allow us to utilize much more clock cycle of our main thread – a human main thread, which can really do the thinking. Ultimately that what the difference is between human and machines in today edge. That is why we have many software built today. Operating systems, financial applications, engineering application and many others, including the RAD (Rapid application development) tools. RAD in compare to the edge where programmers need to punch the cards makes developer very efficient in generating computer instructions. And of-course even computers are also much more efficient now a days.

Anyway, many of us knows most of above that I have written. The point here is use computers, as much as you can to increase productivity. And it applies to software engineers as well. To support that, I’m planning to take several efforts that will include blog-posts, posting some tools, VS.NET macros, snippets and something else that will help.

Although this wouldn’t be the only goal of this blog-post repository (making it explicit as this is first blog-post in this repository), I’m starting with posting first version of first macro that creates resource entry of a selected string in the code. The macro is posted separately to make both more manageable. I’m linking my first macro with this blog post here, but will not do same for other automation posts that I will post later. To find them you should see posts tagged under RoboCoding. Please mind that the macro is in version-1, I will fix and enhance it as time ticks and the need. As well as more of such will come in future.

« Newer Posts

Powered by WordPress