Sunday, February 17, 2008

Seam Carving

Isn't it annoying when you re-size a web page with an image in it and it doesn't re-sizes with the page. Or when you need an image to just shrink and look good without contorting or looking squeezed and you have to whip out the old Photoshop to fix it. Well your wishes have been granted. You can thank Shai Avidan and Ariel Shamir for creating a new image resizing algorithm that fixes all that and a bag chips, its called Seam Carving. The algorithm is amazing. Its almost spooky just looking at it work. You can squeeze an image down to half the width and it still looks good and preserves all the detail. You can even stretch a landscape image and give it a panoramic look.

You just won't believe it until you see it in action.
Check it....


I can see every browser, photo-editing and even video editing software using this technology. By the looks of it I think it might be open source.

Here are some libraries and applications so that you can start using it with your projects.

Seam Libraries & applications

  • C Library

  • .NET Library

  • C++ Library

  • Resizor

  • Saturday, January 26, 2008

    Does Windows=Evolution?












    Windows gets a lot of flack for being this monstrous OS that is just constantly being patched and updated with security fixs and feature updates. But maybe this is the natural way of building a rebust and agile system. I come across this reliazation after reading this very good article over at SEED called Algorithmic Inelegance.


    In flies, those paradigmatic models of genetics and development, that process of elaboration has been carried to an extreme. Any algorithmic elegance in the ancestral arthropod has been lost in favor of detailed, segment-by-segment hardwiring of the specification of the body plan. If a fly were software, it's software that has been patched and patched, and patches have been put on patches, until almost all vestiges of the original code have been obscured in the tweaks. It's the antithesis of planning and design—it's ad hoc co-option and opportunistic incorporation of chance enhancements. It's evolution.

    Does this sound a little familar?

    Now I'm not saying that Windows is totally devoid of direction.
    Of course some would disagree with that. But the symalarties with evolution is scary.

    Thursday, December 20, 2007

    IE8 Passes the ACID2 Test!


    Well the word is out. The IE8 Team has just officially announced that they have rendered the "ACID 2 Face" in I8 Standards mode. This is HUGE!! Finally no more workarounds or hacks on your CSS. Passing the ACID 2 test basically means that the browser follows the W3C HTML and CSS 2.0 specifications. The announcement also talked about supporting the many different types of users and older web pages. I think the IE8 Team has another trick up its sleeve and will later reveal a backward compatibility mode for older sites so that standards and nonstandard sites will work in IE8.

    Good job IE8 Team!

    Tuesday, December 11, 2007

    SharpDevelop IDE

    About 2 years ago I went on a search for a zip library because the .NET Framework at the time did not have one. I found this really nice zip library that came from the SharpDevelop IDE project. At the time the SharpDevelop project was pretty basic and they were at version 1.1. Well things have really changed since then. They have added some really cool features such as multiple framework support, refactoring, Subversion integration and Mono support.

    Here's a list of some of the features...

    • Open source, LGPL licensed

    • Write C#, ASP.NET, ADO.NET, XML, HTML code

    • Forms designer for C#, VB.NET and Boo

    • Code completion for C#, VB.NET and Boo (including Ctrl+Space support)

    • Integrated NUnit support plus code coverage (NCover)

    • Multi-framework support (.NET 1.1 and 2.0, Mono, Compact Framework)

    • XML Editing (source and tree view) with XPath search

    • Subversion integration

    • Code template support

    • Easily extensible with external tools

    • Re-host SharpDevelop with SDA

    • Easily extensible with Plug-Ins





    If your looking for a Free alternative to Visual Studio or even a Windows Mono IDE this is a very good alternative.

    Friday, November 30, 2007

    Silverlight 1.1 upgraded to Silverlight 2.0


    Microsofts Silverlight is a cross platform and cross browser version of the .NET Framework. That's right folks it runs on Windows,Mac & Linux.

    First quarter of 2008 they will be releasing Silverlight 2.0. This release has so many new features that they decided to up the number from 1.1 to 2.0.

    Here is a break down of the new features...

    WPF UI Framework: The current Silverlight Alpha release only includes basic controls support and a managed API for UI drawing. The next public Silverlight preview will add support for the higher level features of the WPF UI framework. These include: the extensible control framework model, layout manager support, two-way data-binding support, and control template and skinning support. The WPF UI Framework features in Silverlight will be a compatible subset of the WPF UI Framework features in last week's .NET Framework 3.5 release.

    Rich Controls: Silverlight will deliver a rich set of controls that make building Rich Internet Applications much easier. The next Silverlight preview release will add support for core form controls (textbox, checkbox, radiobutton, etc), built-in layout management controls (StackPanel, Grid, etc), common functionality controls (TabControl, Slider, ScrollViewer, ProgressBar, etc) and data manipulation controls (DataGrid, etc).

    Rich Networking Support: Silverlight will deliver rich networking support. The next Silverlight preview release will add support for REST, POX, RSS, and WS* communication. It will also add support for cross domain network access (so that Silverlight clients can access resources and data from any trusted source on the web).

    Rich Base Class Library Support: Silverlight will include a rich .NET base class library of functionality (collections, IO, generics, threading, globalization, XML, local storage, etc). The next Silverlight preview release will also add built-in support for LINQ to XML and richer HTML DOM API integration.

    This should spur a major migration from applications that would have been built on the desktop to be moved to the web. I'm really interested in what kind of performance this new framework will have and how far you can push it in terms of size. I wonder if there is a built in asynchronous framework to handle calls to different web services.

    The blurry line between desktop application and web app has gotten a lot bigger.

    Sunday, November 4, 2007

    Single & Multiline TextBox with MaxLength Validation

    After doing a bit of searching online I couldn't find an easy way to control the character length in a text box and a multi line text box. Plus the limit is defined by the schema of the table in a database. So I did what any developer would do with this problem. I used it as an excuse to write some code!

    Here is one example of limiting characters in a text box or a multi line text box in a asp.net form. This example will also show how to add a dynamic warning message once the limit has been reached.

    This example has 3 parts.

    • A Stored Procedure

    • Some C# code

    • A Javascript function



    Lets get into the code!

    Create the stored procedure

    CREATE PROCEDURE [dbo].[GetFieldWidths]
    (
    @TableName nvarchar(40)
    )
    AS
    BEGIN
    SELECT COLUMN_NAME,
    CHARACTER_MAXIMUM_LENGTH,
    DATA_TYPE
    FROM
    INFORMATION_SCHEMA.COLUMNS
    WHERE
    TABLE_NAME = @TableName
    END
    RETURN

    Create a C# function to read all valid fields widths into a Generic Dictionary Collection.



    // helper function
    public static Dictionary FieldWidths
    {
    get
    {
    System.Web.HttpApplicationState ApplicationState = HttpContext.Current.Application;
    if (ApplicationState["cDatabase.Tables.tblUsers.FieldWidths"] == null)
    {
    ApplicationState["cDatabase.Tables.tblUsers.FieldWidths"] = cDbaseFunc.FieldWidths(tblUsers.TableName);
    }

    return ApplicationState["cDatabase.Tables.tblUsers.FieldWidths"] as Dictionary;
    }
    }

    // main function
    public static Dictionary FieldWidths(string Table)
    {
    //Load field types
    string[] aryStringTypes = new string[6] { "char", "nchar", "ntext", "nvarchar", "text", "varchar" };
    List StringTypes = new List(aryStringTypes);

    Database db = DatabaseFactory.CreateDatabase();
    DbCommand dbCommand = db.GetStoredProcCommand(cDatabase.StoredProcedure.GetFieldWidths);
    db.AddInParameter(dbCommand, "@TableName", DbType.String, Table);
    IDataReader dr = db.ExecuteReader(dbCommand);

    string FieldName = string.Empty;
    int FieldLength;
    string FieldType = string.Empty;

    Dictionary FW = new Dictionary();
    while (dr.Read())
    {
    FieldType = dr.GetString(2).ToLower();
    if (StringTypes.Contains(FieldType))
    {
    FieldName = dr.GetString(0);
    FieldLength = dr.GetInt32(1);
    FW.Add(FieldName, FieldLength);
    }
    }
    dr.Close();

    return FW;
    }

    Create the Javascript function that limits the characters and creates the dynamic message.



    function CheckCharMaxLenLimit(control,maxlength)
    {
    var ErrorMsgID = control.id + "_$MAXLENGTH_ERROR_MSG$";
    var ErrorMsg = document.getElementById(ErrorMsgID);

    var MaxLength;
    if(maxlength != null)
    {
    MaxLength = maxlength;
    }
    else
    MaxLength = control.maxLength - 1;

    var TextLength = control.value.length;
    if(TextLength > MaxLength)
    {
    control.value = control.value.substring(0,MaxLength);

    if(ErrorMsg == null)
    {
    control.outerHTML = control.outerHTML + MaxLength + " character limit!";
    }
    }
    else
    {
    if(ErrorMsg != null)
    ErrorMsg.parentNode.removeChild(ErrorMsg);
    }
    }

    The final step is too attach the javascript function to your text box control "onkeyup" event.
    You can do this in the code behind like so....
    this.txtUserName.Attributes["onkeyup"] = "CheckCharMaxLenLimit(this," + this.FieldWidths["Username"] + ");";

    Summary


    The nice thing about the C# function is that it caches the returning list of fields and widths into an Application State variable. If your tables schema changes allot you could always cache it in a session state variable. This reduces the hits to SQL server which improves performance.

    The character limiting and checking is handled on the client side using the javascript function. This function also supports the "maxLength" attribute of the text box control. The dynamic message is also created on the client side by using the DOM to attach a child element to the text box. This creates a very quick UI response. Lastly the dynamic message can be formatted using standard CSS.

    Like so...
    .MAXLENGTH_ERROR_MSG
    {
    color:red;
    }

    This method uses SQL2005 but I'm sure it could easily be used with any database platform. I hope this helps someone out there with the same problem.

    Monday, September 24, 2007

    Top 10 IIS 7 changes

    If you don't already know Microsoft uses there own applications while still in beta on there production servers. Right now www.microsoft.com is running on the beta 3 Windows Server 2008 and the beta 3 of IIS 7. The 2 products are very stable and are in a functional release.

    Here are the top 10 major changes in IIS 7...


    • Simple, Configurable Command Line Setup

    • Great Compatibility with older asp apps

    • No More Metabase!

    • Centralized Configuration

    • Delegated Configuration

    • AppCmd and Other New Management Options

    • Failed Request Tracing

    • Request Filtering

    • UNC Content

    • Output Caching of Dynamic Content




    IIS 7 Totally modular


    Get more details here..