Friday, November 1, 2013

Deleted stored procedure from MS SQL!

Do not panic, as there are 2 ways to retrieve your precious stored procedure:


1) Recover them from the dblog table

SELECT
[cp].[refcounts],
[cp].[usecounts],
[cp].[objtype],
[st].[dbid],
[st].[objectid],
[st].[text],
[qp].[query_plan]
FROM
sys.dm_exec_cached_plans cp
CROSS
APPLY sys.dm_exec_sql_text ( cp.plan_handle ) st
CROSS
APPLY sys.dm_exec_query_plan ( cp.plan_handle ) qp 
where [st].[text] like '%__AUDIT%'

Select Convert(varchar(Max),Substring([RowLog Contents 0]
,33
,LEN([RowLog Contents 0]))) as [Script]
from fn_dblog(NULL,NULL)
Where [Operation]='LOP_DELETE_ROWS' And [Context]='LCX_MARK_AS_GHOST'
And [AllocUnitName]='sys.sysobjvalues.clst'

2) Recover them from cached database plan

SELECT
[cp].[refcounts],
[cp].[usecounts],
[cp].[objtype],
[st].[dbid],
[st].[objectid],
[st].[text],
[qp].[query_plan]
FROM
sys.dm_exec_cached_plans cp
CROSS
APPLY sys.dm_exec_sql_text ( cp.plan_handle ) st
CROSS
APPLY sys.dm_exec_query_plan ( cp.plan_handle ) qp ;


Tuesday, June 18, 2013

Unofficial pulse app finally arrives on Windows Phone

After many sleepless nights, i've finally completed the app and got approved by Microsoft. It was a pain to be rejected twice, first due to my negligence (i forgot to assign the app icon), second time was due to copyright issues (i've used the windows logo in the icon).

But nonetheless, it's approved and finally live in the app store now. You can download it here



Several roadblocks hit me, due to some Windows Phone Toolkit updates, LongListSelector are now officially part of Phone.Controls, microsoft had finally made it part of the official controls.

I was using the old toolkit and had several problems in maintaining the memory foot print low. My device was a Lumia 620 and was capped with a 180mb memory limit. After days of OutOfMemory exceptions, i've customised HubTiles so much that it no longer look and behaves like the original. I had to reduce the number of controls within HubTiles, take out different animations such as flip and rotate.

I was able to support both wp7 and wp8, until the new control came out with so much feature that i didn't have to code manually is luring me to ditch wp7. And so i did, i decided to support wp8 only and have the new LayoutMode="Grid" and virtualizing capabilities built-in. Now the app is able to load hundreds of hubtiles in a panoraitem without any hiccups.

The old version can only load like 50 tiles at max, before crashing due to the memory pressure. I've incoporated a feedback channel within the app and hope that with user's feedback, i can improve the app further and let the Windows Phone community have what they deserve (A rich appstore)

Monday, May 20, 2013

My first windows phone 8 app - SG News Cloud services Part 2

I've managed to garner good feedbacks and input from many helpful people and i'm preparing for a version 2.1 release, i'm still tinkering with the nitty gritty, but you can have a preview over here

A lot of brain cracking went into making all these happen. My first challenge was to work with the XAML mark up.


  1. Somehow my sampledatamodel couldn't display everything during design-time, so i had to debug, tweak, debug, tweak over and over again. 
  2. Fonts installation was quirky as well, but luckily i've managed to get the custom fonts working by using Expression Blend. 
  3. But i've used a converter, but visual studio kept prompting an error: Invalid XAML, after lots of frustration, i found someone saying that it's due to the space that i've put in my project name. No big deal for now, since visual studio designer wasn't helping me much, luckily it works on the devices & emulators
Comment below if you would like to know more about my app

My first windows phone 8 app - SG News Cloud services Part 2

I've

Tuesday, May 14, 2013

Yahoo Weather on iOS is beautiful

So i decided to try and make 1 using HTML & JS, take a look here: http://murugaratham.appspot.com/

Not much time for details, but if you are interested in getting involved, do drop me a comment/mail.

Thursday, May 9, 2013

My first windows phone 8 app - SG News Cloud services

I had a small window of time while waiting for my new job and managed to squeeze an application for windows phone 8. I would like to share my experience and decisions along the way.

Why are you creating applications for windows phone 8 when the smartphone OS is low?
 Well, i am not an expert in iOS/android development, although i have led a full team in delivering mobile solutions, but i didn't had opportunity to write full native applications. With less than 1 week of time, i've decided to leverage on my .NET experience to write an application

What advice do you have for me to be an indie developer hoping to get some passive income?
First of all, if you are an indie developer, plan out your budget & time. Even if you have the best application idea, but if it would requires $500,000 of upfront investment (which you find out in the midst of developing), then you are just wasting your own time. Software licenses, equipment, etc were all consider before i started.

When i decided to make a windows phone app, i've read up on what are the software prerequisites. So for windows phone 8, obviously you would need the Windows Phone 8 SDK, and here are the requirements as well as the link. I would also need a cheap windows phone 8 device (i bought a Lumia 620 for SG$350), as well as the developer account (SG$135).

Can you just tell me how much you spent in total before getting everything up?
SG$135 + SG$350 = SG$485

But that's not all, put into consideration the Windows 8 OS that you need in order to use the SDK. Luckily i gotten my windows 8 key from MSDN subscription.

So you mean i have to subscribe for MSDN in order to get everything running? You know how much it costs?

Frankly, i don't know how much it costs, but i managed to get an MSDN account from BizSpark, a short overview, it's a Microsoft initiative to help 'start-ups'. They provide free Azure & MSDN accounts to kick start your 'business'.

Enough of Q&A, if you have more, do comment on this post. Let me give a short breakdown of the architecture.

Even though i was given a free azure account, after some evaluation, i went ahead with Google App Engine (GAE). Reasons?

  1. Azure was too much fluff and complicated for me to get a simple thing done. Here's a quick wiki look up of what they are offering.
  2. .NET framework is powerful, but too bloated in my case, which might incur high utility costs.

So after deciding on GAE, i was at crossroads once again, Python, Java or Go? I've avoid Azure due to bloat, so no Java. Go is young for my liking, so i went with Python. 

Was it a challenge? 

To my surprise, No. I have zero knowledge on Python but it only took 2 days for everything to start working. Google did a great job in providing python toolkit which offers very useful features, e.g. authentication, authorization, api to Memcached, NoSQL, and many more.

So i hacked up a REST webservice and simple Content Management System (CMS) using GAE, webapp2 and JINJA templates. Tested everything a few rounds and didn't had to bother much about the cloud server anymore. Oh and not to mention GAE gives 1gb of bandwidth daily as opposed to Azure's complicated free tier

I will update with the windows phone 8 application development in my next post :) in the meantime, if you have a windows phone, do take a look SG News

Thursday, November 1, 2012

iOS safari choppy scrolling

Try adding this to your container:

-webkit-overflow-scrolling: touch;

Now enjoy smooth scrolling :)

Friday, June 8, 2012

nodejs

I've given myself too much excuses, but this time round, i've finally did something using node.js

nodejs express quickstart

I'm still pretty new to this, but i took a couple of days to set up amazon ec2 micro instance (free), mess around with unix, install nodejs, dynamic dns (dyndns.org) and now i have a running instance in the cloud!

Check it out from time to time http://ec2.dyndns.biz (i've lost the dns after letting the ec2 instance dead for too long, i've registered a new ec2 instance at http://murugaratham.dyndns.biz), i'll update the site as i improve the starter :)

Wednesday, January 18, 2012

Microsoft technologist's view on nodejs

Most of my enterprise experience is bound to the Microsoft stack (.Net, SharePoint 2007 & 2010, SQL Server, IIS, Windows 2003, 2008, 2008 R2, the list goes on and on)

Pretty much of this change ever since i took my part time degree and i was brought back to hardcore software development, design and documentation. C++, C, php, rdms, 3NF, data structures & abstraction, algorithms, big O notation, etc.

I sat down and gave it a thought, the very existence of IT in most businesses are mostly for complimenting a business. We can leave Facebook, twitter, google and yahoo out of the picture, as they had caught on a market niche while their respective industry are in their infancy.

In the last project that i was involved in, i've opened up my mindset, i told myself, not to listen to microsoft all the time. I said no to ajaxcontrol toolkit, i said no to grid view binding to datasets. This time i wan to go hardcore and be able to know exactly what i am doing and how is it being done.

Enter: jQuery. There is no need for me to introduce this excellent javascript framework, but what it did for me was more than being a javascript framework. It allow me to be exposed to the open source communities on IRC, mailing lists and several forums. Underscore.js, less.js and Zurb foundation soon found their way into my IDE.

Soon enough, i've heard and tried a few node.js one page applications. The concept was clear and easy. The one language that most, if not all web developers are familiar with: Javascript. Using it for your user interface, server application and even database, one language to rule them all.

Author Ryan Dahl initially insisted that node be a 1 process thingy, lately, i believed due to many feedback and Joyent's direction, now they provide process forking.

My main roadblock for implementation in production is the stability, better debugging capabilities & easier fail-over. There are ways to implement fail over, but due to the fact that it is still under very rapid development, breaking API changes & deprecation caused a few sample apps that i created having problems.

I will look forward to v1.0 and implement it on our production servers.

Thursday, December 8, 2011

IE7 & IE8 calibri font blurry Sharepoint jQuery

Using jQuery in Sharepoint became a second nature to me. I was using a div with fadeIn(), nothing special and everything went well on our development environment and integration environment. Until we went to UAT and received lots of complains from users saying that the fonts look pixelated and blurry. I went down on site and saw that the fonts was indeed very blurry (especially true on their screens).

Bad news for me as I had a 7 level depth of div and span tags, not to mentioned it was in a webpart and Sharepoint corev4.css had this div.ms-WPBody that likes to screw my styles up.

After deep investigation, since safari, chrome and IE9 didn't had any blurry fonts, I downgraded my IE9 to IE8 and managed to replicate the issue. Hours past and I did a side-by-side comparison between chrome and IE8. Then I saw something within the top level div which I used the fadeIn() effect. div id="divContainer" style="filter: alpha bla bla bla,....."

It caught my attention and I used IE developer tools and went straight to the CSS tab and looked for the "filter". I turned it off by clicking on the checkbox. The fonts immediately sharpened. Hmm, http://blogs.msdn.com/b/e7/archive/2009/06/23/engineering-changes-to-cleartype-in-windows-7.aspx


So I've read up a lot and found out that jQuery might actually add in the filter somehow. I managed to solve it by putting:

document.getElementById('divContiner').style.removeAttribute('filter');

But I later found out that it only work for IE8. After some more frustrating hours, I discarded the fadeIn() effect and the fonts were sharp and crisp :)

Thursday, October 13, 2011

Facebook detect movement before loading new feeds

If you are eagle-eyed enough, you would have noticed that facebook actually doesn't poll unnecessarily from the server. Somehow it knows that you are away for sometime and when you are active and start to move your mouse, newer feeds starts loading.


<script type="text/javascript">
  document.onmousemove = (function() {
    var onmousestop = function() {
      $('h1').css("color", "white");
    }, thread;
    return function() {
      $('h1').css("color", "red") clearTimeout(thread);
      thread = setTimeout(onmousestop, 200);
    };
  })();


Read more on this: Closures
I've embedded this scrip into the blog -> Blue H1, so don't panic if you see the h1 starts turning blue :)


Thursday, September 29, 2011

Mimic wikipedia for SharePoint 2010 search



Recently, there was a user requirement for customizing SharePoint 2010 Enterprise wiki search control. 


Objective: Mimicking Wikipedia search box functionality, whereby when a user enters a wiki page title, if there is an exact hit, we should redirect the user to the page, instead of displaying SharePoint's default result page. (Less the autocomplete)


Using jQuery & a bit of digging into SP.js, i found that internally, SharePoint actually uses a javascript function called "SubmitSearchRedirect", which actually redirects the user to "/_layouts/searchresults.aspx" and appending the search keyword as the querystring. 

So a seemingly difficult request was actually completed in less than 10 mins.



function applyCustomSearch() {
            $("#onetIDGoSearch").attr("onclick", ""); //user click on search img
            $("#idSearchString").attr("onkeydown", ""); //user keystroke

            $("#onetIDGoSearch").click(function() {
                <Your AJAX function to check if the page exists>($("#idSearchString").val(), function(exactHit){
                    if(exactHit== true) { //simulate got exact hit
                        window.location = "http://"+ document.domain +"/<Your Enterprise Wiki Homepage>/" + $("#idSearchString").val() + ".aspx?ContextId=" + $.queryString("ContextId");
                    } else { 
                        SubmitSearchRedirect("http://"+ document.domain +"/_layouts/searchresults.aspx");
                    }           
                });
            });

            $("#idSearchString").keydown(function (event) {                
                if (event.keyCode == '13') {
                    event.preventDefault();
                    <Your AJAX function to check if the page exists>($("#idSearchString").val(), function(exactHit){
                    if(exactHit== true) { //simulate got exact hit
                        window.location = "http://"+ document.domain +"/<Your Enterprise Wiki Homepage>/" + $("#idSearchString").val() + ".aspx?ContextId=" + $.queryString("ContextId");
                    } else { 
                        SubmitSearchRedirect("http://"+ document.domain +"/_layouts/searchresults.aspx");
                    }           
                });
}); }

The logic is dead simple. 

For my project, i used an event receiver to track all the articles by saving them into a database and creating a tag cloud. So i had the benefit of knowing exactly how many article pages and how they are being named. So all i did was a simple $.getJSON() to my custom RESTful WCF service, which returns a boolean, and the rest is straightforward.

For simpler projects, you can either use http://spservices.codeplex.com/ to query the wiki pages library for the article existence.

I shall do a blogpost on how to embed jQuery library into SharePoint 2010 in the subsequent posts.


Wednesday, September 21, 2011

GSPMigrator source code release

After leaving the source codes for this tool, i've decided to put it on CodePlex with the GNU v2 licence, hoping that it will support and help any one that needs to migrate files into SharePoint 2007 (and in the future 2010).

GSPMigrator is basically a migration tool that allows anyone within the network to connect to a network drive and view it with a tree view.



There are several problems (although there are still some minor ones) that i went through before coming out with this version:

  • Lazy-loading vs eager-loading on generating tree views
Lazy-loading will give better user experience.

Tuesday, September 20, 2011

Customising SharePoint 2010 enterprise wiki

Requirements:

There are 3 different business context:

  1. Work
  2. Personal
  3. Entertainment
When a user comes into the wiki site, there will be a visual webpart embedded in the form to scope this document to 1 of the above 3 context. So if the user would like to post a Work-related wiki article, he can select an option (dropdown list or radio button etc, but on my POC it's only a textbox :P) and when he click on the sharepoint save & close button



the permission of the article will be restricted based on predefined rules.

Solution (after some thoughts):

  1. Event receiver to set permissions
  2. Using HttpContext in EventReceiver synchronous events (itemAdding & itemUpdating) to get the value to b
  3. Customising the master page to include a VWP (visual webpart) to allow user select "context"


Thursday, July 21, 2011

.Net technical test drawing mountains

Recently, my friend was given a technical test during an interview, i realized that it's a rather common "test" given to interviewees. I took up the challenge and squeeze out some time to do it.

The interviewer asked my friend to write a console application that reads from user's keyboard input, when the user enters a number, draw a mountain with the user input as the number of back and forward slashes. (of course, with bigger numbers, the subsequent layers need more padding between the slashes).

I wasn't exactly sure how the question was structured, but based on my understanding, i scribbled typed the expected end results on a text editor.


/\         gap=0, space=0, input=1

 /\        gap=1, space=0, input=2 (print new line)
/  \       gap=0, space=2

  /\       gap=2, space=0, input=3 (print new line)
 /  \      gap=1, space=2 (print new line)
/    \     gap=0, space=4 (print new line)

   /\      gap=3, space=0, input=4
  /  \     gap=2, space=2 (print new line)
 /    \    gap=1, space=4 (print new line)
/      \   gap=0, space=6 (print new line)

So, with my iPad showing me the expected results and my primary monitor with visual studio 2010... i started writing some loops:



using System;


namespace DrawMountains
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputNum; 
            if (int.TryParse(Console.ReadLine(), out inputNum))
            {
                for (int i = 0; i < inputNum; i++)//print tip of mountain & padding (if any) 
                {
                    int temp = inputNum-i; //amount of padding to print
                    while (temp > 1) //amount of space before left slope
                    {
                        PrintSpace();
                        temp--;
                    }
                    PrintLeftSlope();
                    //----------------prints all left slope correctly (up to n num)
                    int temp2 = i*2;
                    for (int j = 0; j<temp2; j++) //padding between the slashes
                    {
                        PrintSpace();
                    }
                    PrintRightSlope(); //self-explanatory
                }
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Invalid input");
                Console.ReadKey();
            }
        }


        static void PrintLeftSlope()
        {
            Console.Write("/");
        }


        static void PrintRightSlope()
        {
            Console.WriteLine(@"\");
        }


        static void PrintSpace()
        {
            Console.Write(" ");
        }
    }
}

This post is purely for educational purposes, no point for memorizing this sample and contrived effort. I believe the interviewer's purpose is to see how strong are you in the way you design your algorithms, handling exception (which i didn't do) and perhaps your naming convention and formatting. 

Monday, May 23, 2011

SharePoint 2010 and .Net 4 Part 2

A continuation from this post.

I have achieved a managed software development cycle for complex SharePoint 2010 systems, a brief overview (albeit poorly drawn sample)

I have had several problems before finalizing the solution & project files:

  1. SharePoint 2010 application pool can only support .Net 3.5 and below (our latest proprietary framework is done with .Net 4.0)
  2. Cross-Origin Request Sharing 
  3. SharePoint 2010 requires signed assemblies for Visual Webpart projects in order to do debugging

For the first problem, we have worked around by wrapping the Business Interface with a WCF project that acts as a proxy. We had a lot of internal arguments, discussions and some conflict on this approach. One of the team member is uncomfortable with the additional overhead, however after doing several tests with Apache Bench, we are satisfied with the performance and delays. Another colleague actually done a similar implementation and mentioned that in the long-run when user base increases, we can actually scale out by letting the WCF services run on a dedicated box, sounds nice. Thus, we went ahead with the WCF as a proxy pattern. 

For the second problem, we spent many man hours figuring out why we can't do an AJAX call to our custom WCF services via jQuery 1.6. After narrowing down the issues to the Cross-Origin Request Sharing, we have tried to use JSONP without success, setting jQuery options of $.support.cors = true without success, jQuery options of CrossDomain = true without success. I spent few hours trying to make the jQuery call the WCF, something which appears so simple and straight forward, i decided to use google chrome and see what the console says..

"XMLHttpRequest cannot load <url>. Origin <url> is not allowed by Access-Control-Allow-Origin." We fixed the issue by adding a global.asax into the WCF project and adding a method in the Application_BeginRequest.

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",  "GET, POST");

        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");

        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }
}

For the third problem, it wasn't so bad, we just had to get the framework team to sign all their libraries before we add into SharePoint bin. This is actually for non Visual Webpart solutions, namely sharepoint application pages. We would have to use our Business Objects and Interfaces on the codebehind, so that pretty much explains it.

Have fun developing in SharePoint 2010 :)

Thursday, May 12, 2011

SharePoint 2010 and .Net 4

There are many people that tried and failed (including myself), my company have a proprietary framework written in .Net 4.0 (latest release), after 3 frustrating days and nights, i've given up and made several work-arounds and exceptions.

The only way that allow you to use .Net 4 projects is, to wrap it around a WCF 3.5 project. My solution for the current project involves jQuery and WCF heavily in order to give the end users a highly interactive interface. Hope to be able to extract non-sensitive snippets and post it here.

Wednesday, May 11, 2011

Fix iPhone vibration problems

My iPhone 3GS vibration motor just went dead on me for no reason, luckily I have an app called iBrate, after double tapping on the screen which supposedly made the phone vibrate non stop, it's still not budging, in a fit of anger I hit it on my table and the thing went bzzzzzzzzzzzz. Caught me by surprise, after googling for similar cases, I found that using iBrate with slapping the phone's back on the palm is a solution for many. Guess it's time to get iPhone 5 as soon as it launches :)

Thursday, May 5, 2011

SharePoint 2010 custom error off

Back in MOSS 2007, when i need to debug, all i have to do is to change the web.config file:

<customErrors mode="Off"/>

However, in SharePoint 2010, there is another web.config in the Hive folder, under LAYOUTS. To disable customError, remember to give hive folder a visit and change the values there :)

Wednesday, March 2, 2011

Sharepoint 2010 custom wiki page layout

While doing some exploratory work, i tried to clone the default Enterprise Wiki pagelayout and added some of my own controls, everything went smooth until when i try to save & close the page and i was thrown the following error:
"failed to get value of the wiki categories column from the managed metadata field type control invalid field name"


Googling didn't help much as most of them prompted me to activate the taxonomy site feature (which after verifying, it was already active), after some head scratching, i realized that when i duplicate the layout page, i've used the default Associated Content Type as "Article Page" instead of "Enterprise Wiki Page", after editing the associated content type, all went well :)